diff --git a/README.md b/README.md index ada64f3..c229187 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,9 @@ configuration during runtime use the `reload` statement in the command prompt Possible configuration values are: * `use_nerdfont`: Turn nerdfont glyphs on/off +* `flip_status_indicators`: By default the statusbar will show a play icon when + a track is playing and a pause icon when playback is stopped. If this setting + is enabled, the behavior is reversed. * `theme`: Set a custom color palette (see below) * `backend`: Audio backend to use, run `ncspot -h` for a list of devices * `backend_device`: Audio device string to configure the backend diff --git a/src/config.rs b/src/config.rs index a56cef8..23696f4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,6 +20,7 @@ pub struct ConfigValues { pub keybindings: Option>, pub theme: Option, pub use_nerdfont: Option, + pub flip_status_indicators: Option, pub audio_cache: Option, pub audio_cache_size: Option, pub backend: Option, diff --git a/src/main.rs b/src/main.rs index b637a6e..8824f8f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -185,7 +185,7 @@ async fn main() { spotify.clone(), queue.clone(), library.clone(), - cfg.clone(), + cfg, event_manager.clone(), ); @@ -204,11 +204,7 @@ async fn main() { #[cfg(feature = "cover")] let coverview = ui::cover::CoverView::new(queue.clone(), library.clone(), &cfg); - let status = ui::statusbar::StatusBar::new( - queue.clone(), - library, - cfg.values().use_nerdfont.unwrap_or(false), - ); + let status = ui::statusbar::StatusBar::new(queue.clone(), library); let mut layout = ui::layout::Layout::new(status, &event_manager, theme) .screen("search", search.with_name("search")) diff --git a/src/ui/statusbar.rs b/src/ui/statusbar.rs index 75e3f98..bd554c7 100644 --- a/src/ui/statusbar.rs +++ b/src/ui/statusbar.rs @@ -17,11 +17,10 @@ pub struct StatusBar { spotify: Spotify, library: Arc, last_size: Vec2, - use_nerdfont: bool, } impl StatusBar { - pub fn new(queue: Arc, library: Arc, use_nerdfont: bool) -> StatusBar { + pub fn new(queue: Arc, library: Arc) -> StatusBar { let spotify = queue.get_spotify(); StatusBar { @@ -29,7 +28,37 @@ impl StatusBar { spotify, library, last_size: Vec2::new(0, 0), - use_nerdfont, + } + } + + fn use_nerdfont(&self) -> bool { + self.library.cfg.values().use_nerdfont.unwrap_or(false) + } + + fn playback_indicator(&self) -> &str { + let status = self.spotify.get_current_status(); + let nerdfont = self.use_nerdfont(); + let flipped = self + .library + .cfg + .values() + .flip_status_indicators + .unwrap_or(false); + + const NF_PLAY: &str = "\u{f909} "; + const NF_PAUSE: &str = "\u{f909} "; + const NF_STOP: &str = "\u{f909} "; + let indicators = match (nerdfont, flipped) { + (false, false) => ("▶ ", "▮▮", "◼ "), + (false, true) => ("▮▮", "▶ ", "▶ "), + (true, false) => (NF_PLAY, NF_PAUSE, NF_STOP), + (true, true) => (NF_PAUSE, NF_PLAY, NF_PLAY), + }; + + match status { + PlayerEvent::Playing(_) => indicators.0, + PlayerEvent::Paused(_) => indicators.1, + PlayerEvent::Stopped | PlayerEvent::FinishedTrack => indicators.2, } } } @@ -70,27 +99,12 @@ impl View for StatusBar { ); }); - let state_icon = if self.use_nerdfont { - match self.spotify.get_current_status() { - PlayerEvent::Playing(_) => "\u{f909} ", - PlayerEvent::Paused(_) => "\u{f8e3} ", - PlayerEvent::Stopped | PlayerEvent::FinishedTrack => "\u{f9da} ", - } - } else { - match self.spotify.get_current_status() { - PlayerEvent::Playing(_) => "▶ ", - PlayerEvent::Paused(_) => "▮▮", - PlayerEvent::Stopped | PlayerEvent::FinishedTrack => "◼ ", - } - } - .to_string(); - printer.with_color(style, |printer| { - printer.print((1, 1), &state_icon); + printer.print((1, 1), self.playback_indicator()); }); let updating = if !*self.library.is_done.read().unwrap() { - if self.use_nerdfont { + if self.use_nerdfont() { "\u{f9e5} " } else { "[U] " @@ -99,7 +113,7 @@ impl View for StatusBar { "" }; - let repeat = if self.use_nerdfont { + let repeat = if self.use_nerdfont() { match self.queue.get_repeat() { RepeatSetting::None => "", RepeatSetting::RepeatPlaylist => "\u{f955} ", @@ -114,7 +128,7 @@ impl View for StatusBar { }; let shuffle = if self.queue.get_shuffle() { - if self.use_nerdfont { + if self.use_nerdfont() { "\u{f99c} " } else { "[Z] " @@ -168,18 +182,6 @@ impl View for StatusBar { printer.print((0, 0), &"━".repeat(duration_width + 1)); }); } - - // if let Some(Playable::Track(ref t)) = self.queue.get_current() { - // let saved = if self.library.is_saved_track(&Playable::Track(t.clone())) { - // if self.use_nerdfont { - // "\u{f62b} " - // } else { - // "✓ " - // } - // } else { - // "" - // }; - // } } fn layout(&mut self, size: Vec2) {