Skip to content

Commit

Permalink
Merge pull request #344 from hasezoey/hideCoverArtConfig
Browse files Browse the repository at this point in the history
feat: allow configuring coverart hidden via config
  • Loading branch information
tramhao committed Jul 9, 2024
2 parents 59c118d + 684831a commit b28e69d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Feat: Add new V2 Config Layout, old v1 config is automatically migrated to v2.
- Feat(tui): allow Sixel to be used for covers.
- Feat(tui): allow all cover providers to not be compiled in.
- Feat(tui): allow disabling the coverart display in config (previously the only options were to not compile it in or disable via cli).
- Fix: update the build scripts to check that the repository is actually the `termusic` repository before using the git version.
- Fix: allow backends to be compiled in for `termusic-playback` but not in `termusic-server`.
- Fix: on backend mpv, clear media-title on EndOfFile.
Expand Down
17 changes: 16 additions & 1 deletion lib/src/config/tui_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ pub struct TuiOverlay {

/// Disable TUI images (like cover-art) from being displayed in the terminal
///
/// This option will not be saved to the config and prevent saving to the config value
///
/// (disables ueberzug, sixel, iterm, kitty image displaying)
pub disable_tui_images: bool,
pub coverart_hidden_overwrite: Option<bool>,
}

impl TuiOverlay {
/// Get whether the coverart should be hidden or not, either the overwrite if present, otherwise the config itself
///
/// true => hidden
pub fn get_coverart_hidden(&self) -> bool {
if let Some(overwrite) = self.coverart_hidden_overwrite {
overwrite
} else {
self.settings.coverart.hidden
}
}
}
6 changes: 5 additions & 1 deletion lib/src/config/v2/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ pub struct CoverArtPosition {
pub align: Alignment,
/// Scale of the image
pub size_scale: i8,
/// Whether to show or hide the coverart if it is compiled in
pub hidden: bool,
}

#[derive(Debug, Clone, Copy, Deserialize, Serialize, Default, PartialEq, Eq)]
Expand Down Expand Up @@ -133,6 +135,7 @@ mod v1_interop {
align: value.align.into(),
// the value is named "width", but more use like a scale on both axis
size_scale: value.width_between_1_100.clamp(0, i8::MAX as u32) as i8,
hidden: Self::default().hidden,
}
}
}
Expand Down Expand Up @@ -176,7 +179,8 @@ mod v1_interop {
converted.coverart,
CoverArtPosition {
align: Alignment::BottomRight,
size_scale: 20
size_scale: 20,
hidden: false
}
);

Expand Down
4 changes: 3 additions & 1 deletion tui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,11 @@ fn get_config(args: &cli::Args) -> Result<CombinedSettings> {

let config_tui = TuiConfigVersionedDefaulted::from_config_path()?.into_settings();

let coverart_hidden_overwrite = if args.disable_cover { Some(true) } else { None };

let overlay_tui = TuiOverlay {
settings: config_tui,
disable_tui_images: args.disable_cover,
coverart_hidden_overwrite,
};

Ok(CombinedSettings {
Expand Down
12 changes: 10 additions & 2 deletions tui/src/ui/components/xywh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ impl Model {
pub fn xywh_toggle_hide(&mut self) {
self.clear_photo().ok();
let mut config_tui = self.config_tui.write();
config_tui.disable_tui_images = !config_tui.disable_tui_images;

// dont save value if cli has overwritten it, but still allow runtime changing
if let Some(current) = config_tui.coverart_hidden_overwrite {
config_tui.coverart_hidden_overwrite = Some(!current);
info!("Not saving coverart.hidden as it is overwritten by cli!");
} else {
config_tui.settings.coverart.hidden = !config_tui.settings.coverart.hidden;
}

drop(config_tui);
self.update_photo().ok();
}
Expand Down Expand Up @@ -108,7 +116,7 @@ impl Model {
/// Requires that the current thread has a entered runtime
#[allow(clippy::cast_possible_truncation)]
pub fn update_photo(&mut self) -> Result<()> {
if self.config_tui.read().disable_tui_images {
if self.config_tui.read().get_coverart_hidden() {
return Ok(());
}
self.clear_photo()?;
Expand Down

0 comments on commit b28e69d

Please sign in to comment.