From 249a4ef5a7e223bce8165ff4ea7321c5746d3d8e Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Sun, 31 Jul 2022 11:24:22 +0200 Subject: [PATCH] Add `statusbar_format` configuration option Fixes #877 --- README.md | 63 +++++++++++++++++++++++-------------------- src/config.rs | 1 + src/model/playable.rs | 2 +- src/model/track.rs | 6 ++--- src/ui/statusbar.rs | 14 +++++++++- 5 files changed, 52 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 0c5f52e..b47f5bb 100644 --- a/README.md +++ b/README.md @@ -325,34 +325,35 @@ runtime use the `reload` command. Possible configuration values are: -| Name | Description | Possible values | Default | -|---------------------------------|----------------------------------------------------------------|---------------------------------------------------------------------------|-------------| -| `command_key` | Key to open command line | Single character | `:` | -| `initial_screen` | Screen to show after startup | `"library"`, `"search"`, `"queue"`, `"cover"`[1] | `"library"` | -| `use_nerdfont` | Turn nerdfont glyphs on/off | `true`, `false` | `false` | -| `flip_status_indicators` | Reverse play/pause icon meaning[2] | `true`, `false` | `false` | -| `backend` | Audio backend to use | String[3] | | -| `backend_device` | Audio device to configure the backend | String | | -| `audio_cache` | Enable caching of audio files | `true`, `false` | `true` | -| `audio_cache_size` | Maximum size of audio cache in MiB | Number | | -| `volnorm` | Enable volume normalization | `true`, `false` | `false` | -| `volnorm_pregain` | Normalization pregain to apply in dB (if enabled) | Number | `0.0` | -| `default_keybindings` | Enable default keybindings | `true`, `false` | `false` | -| `notify`[4] | Enable desktop notifications | `true`, `false` | `false` | -| `bitrate` | Audio bitrate to use for streaming | `96`, `160`, `320` | `320` | -| `gapless` | Enable gapless playback | `true`, `false` | `true` | -| `shuffle` | Set default shuffle state | `true`, `false` | `false` | -| `repeat` | Set default repeat mode | `off`, `track`, `playlist` | `off` | -| `playback_state` | Set default playback state | `"Stopped"`, `"Paused"`, `"Playing"`, `"Default"` | `"Paused"` | -| `library_tabs` | Tabs to show in library screen | Array of `"tracks"`, `"albums"`, `"artists"`, `"Playlists"`, `"podcasts"` | All tabs | -| `cover_max_scale`[1] | Set maximum scaling ratio for cover art | Number | `1.0` | -| `hide_display_names` | Hides spotify usernames in the library header and on playlists | `true`, `false` | `false` | -| `[track_format]` | Set active fields shown in Library/Queue views | See [track formatting](#track-formatting) | | -| `[theme]` | Custom theme | See [custom theme](#theming) | | -| `[keybindings]` | Custom keybindings | See [custom keybindings](#custom-keybindings) | | +| Name | Description | Possible values | Default | +|---------------------------------|----------------------------------------------------------------|---------------------------------------------------------------------------|---------------------| +| `command_key` | Key to open command line | Single character | `:` | +| `initial_screen` | Screen to show after startup | `"library"`, `"search"`, `"queue"`, `"cover"`[1] | `"library"` | +| `use_nerdfont` | Turn nerdfont glyphs on/off | `true`, `false` | `false` | +| `flip_status_indicators` | Reverse play/pause icon meaning[2] | `true`, `false` | `false` | +| `backend` | Audio backend to use | String[3] | | +| `backend_device` | Audio device to configure the backend | String | | +| `audio_cache` | Enable caching of audio files | `true`, `false` | `true` | +| `audio_cache_size` | Maximum size of audio cache in MiB | Number | | +| `volnorm` | Enable volume normalization | `true`, `false` | `false` | +| `volnorm_pregain` | Normalization pregain to apply in dB (if enabled) | Number | `0.0` | +| `default_keybindings` | Enable default keybindings | `true`, `false` | `false` | +| `notify`[4] | Enable desktop notifications | `true`, `false` | `false` | +| `bitrate` | Audio bitrate to use for streaming | `96`, `160`, `320` | `320` | +| `gapless` | Enable gapless playback | `true`, `false` | `true` | +| `shuffle` | Set default shuffle state | `true`, `false` | `false` | +| `repeat` | Set default repeat mode | `off`, `track`, `playlist` | `off` | +| `playback_state` | Set default playback state | `"Stopped"`, `"Paused"`, `"Playing"`, `"Default"` | `"Paused"` | +| `library_tabs` | Tabs to show in library screen | Array of `"tracks"`, `"albums"`, `"artists"`, `"Playlists"`, `"podcasts"` | All tabs | +| `cover_max_scale`[1] | Set maximum scaling ratio for cover art | Number | `1.0` | +| `hide_display_names` | Hides spotify usernames in the library header and on playlists | `true`, `false` | `false` | +| `statusbar_format` | Formatting for tracks in the statusbar | See [track_formatting](#track-formatting) | `%artists - %track` | +| `[track_format]` | Set active fields shown in Library/Queue views | See [track formatting](#track-formatting) | | +| `[theme]` | Custom theme | See [custom theme](#theming) | | +| `[keybindings]` | Custom keybindings | See [custom keybindings](#custom-keybindings) | | 1. If built with the `cover` feature. -2. By default the statusbar will show a play icon when a track is playing and +2. 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. 3. Run `ncspot -h` for a list of devices. @@ -442,14 +443,18 @@ search_match = "light red" More examples can be found in [this pull request](https://github.com/hrkfdn/ncspot/pull/40). ### Track Formatting -It's possible to customize which fields are shown in Queue/Library views. +It's possible to customize how tracks are shown in Queue/Library views and the +statusbar, whereas `statusbar_format` will hold the statusbar formatting and +`[track_format]` the formatting for tracks in list views. If you don't define `center` for example, the default value will be used. -Available options for tracks: -`%artists`, `%title`, `%album`, `%saved`, `%duration` +Available options for tracks: `%artists`, `%title`, `%album`, `%saved`, +`%duration` Default configuration: ```toml +statusbar_format = "%artists - %title" + [track_format] left = "%artists - %title" center = "%album" diff --git a/src/config.rs b/src/config.rs index 2a05153..6ad2925 100644 --- a/src/config.rs +++ b/src/config.rs @@ -73,6 +73,7 @@ pub struct ConfigValues { pub cover_max_scale: Option, pub playback_state: Option, pub track_format: Option, + pub statusbar_format: Option, pub library_tabs: Option>, pub hide_display_names: Option, } diff --git a/src/model/playable.rs b/src/model/playable.rs index 1977cff..36c5e98 100644 --- a/src/model/playable.rs +++ b/src/model/playable.rs @@ -19,7 +19,7 @@ pub enum Playable { } impl Playable { - pub fn format(playable: Playable, formatting: String, library: Arc) -> String { + pub fn format(playable: &Playable, formatting: &str, library: Arc) -> String { formatting .replace( "%artists", diff --git a/src/model/track.rs b/src/model/track.rs index 13ba762..c646c70 100644 --- a/src/model/track.rs +++ b/src/model/track.rs @@ -192,7 +192,7 @@ impl ListItem for Track { let default = config::TrackFormat::default().left.unwrap(); let left = formatting.left.unwrap_or_else(|| default.clone()); if left != default { - Playable::format(Playable::Track(self.clone()), left, library) + Playable::format(&Playable::Track(self.clone()), &left, library) } else { format!("{}", self) } @@ -208,7 +208,7 @@ impl ListItem for Track { let default = config::TrackFormat::default().center.unwrap(); let center = formatting.center.unwrap_or_else(|| default.clone()); if center != default { - Playable::format(Playable::Track(self.clone()), center, library) + Playable::format(&Playable::Track(self.clone()), ¢er, library) } else { self.album.clone().unwrap_or_default() } @@ -224,7 +224,7 @@ impl ListItem for Track { let default = config::TrackFormat::default().right.unwrap(); let right = formatting.right.unwrap_or_else(|| default.clone()); if right != default { - Playable::format(Playable::Track(self.clone()), right, library) + Playable::format(&Playable::Track(self.clone()), &right, library) } else { let saved = if library.is_saved_track(&Playable::Track(self.clone())) { if library.cfg.values().use_nerdfont.unwrap_or(false) { diff --git a/src/ui/statusbar.rs b/src/ui/statusbar.rs index c2aa6a6..3d715f1 100644 --- a/src/ui/statusbar.rs +++ b/src/ui/statusbar.rs @@ -9,6 +9,7 @@ use cursive::Printer; use unicode_width::UnicodeWidthStr; use crate::library::Library; +use crate::model::playable::Playable; use crate::queue::{Queue, RepeatSetting}; use crate::spotify::{PlayerEvent, Spotify}; @@ -68,6 +69,17 @@ impl StatusBar { (self.spotify.volume() as f64 / 65535_f64 * 100.0).round() as u16 ) } + + fn format_track(&self, t: &Playable) -> String { + let format = self + .library + .cfg + .values() + .statusbar_format + .clone() + .unwrap_or_else(|| "%artists - %title".to_string()); + Playable::format(t, &format, self.library.clone()) + } } impl View for StatusBar { @@ -174,7 +186,7 @@ impl View for StatusBar { printer.with_color(style, |printer| { if let Some(ref t) = self.queue.get_current() { - printer.print((4, 1), &t.to_string()); + printer.print((4, 1), &self.format_track(t)); } printer.print((offset, 1), &right); });