Add track_format config option (#800)
* Added track_name_first config option to allow choosing if artists' names should be shown before or after the track name.
* Added active_fields config option, which allows configuration of which columns are visible in Queue/Library view.
This also removes the need for a separate track_name_first and album_column option.
* Fixed README
* Made custom tracklist formatting more flexible.
Updated readme with new instructions.
Reformatted impl member order to match the definitions in traits.rs.
* Added track_name_first config option to allow choosing if artists' names should be shown before or after the track name.
* Added active_fields config option, which allows configuration of which columns are visible in Queue/Library view.
This also removes the need for a separate track_name_first and album_column option.
* Fixed README
* Made custom tracklist formatting more flexible.
Updated readme with new instructions.
Reformatted impl member order to match the definitions in traits.rs.
* Fetch formatting config from library config
Instead of the lazy static mutex
* Moved custom format function to Playable impl as it's a better location to handle both Tracks and Episodes
* Rename from `tracklist_formatting` to `track_format`
Also shorten `format_{left|center|right}` to `{left|center|right}`
Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
This commit is contained in:
committed by
Henrik Friedrichsen
parent
0e50466a5e
commit
f7450321da
@@ -19,6 +19,55 @@ pub enum Playable {
|
||||
}
|
||||
|
||||
impl Playable {
|
||||
pub fn format(playable: Playable, formatting: String, library: Arc<Library>) -> String {
|
||||
formatting
|
||||
.replace(
|
||||
"%artists",
|
||||
if let Some(artists) = playable.artists() {
|
||||
artists
|
||||
.iter()
|
||||
.map(|artist| artist.clone().name)
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ")
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
.as_str(),
|
||||
)
|
||||
.replace(
|
||||
"%title",
|
||||
match playable.clone() {
|
||||
Playable::Episode(episode) => episode.name,
|
||||
Playable::Track(track) => track.title,
|
||||
}
|
||||
.as_str(),
|
||||
)
|
||||
.replace(
|
||||
"%album",
|
||||
match playable.clone() {
|
||||
Playable::Track(track) => track.album.unwrap_or_default(),
|
||||
_ => String::new(),
|
||||
}
|
||||
.as_str(),
|
||||
)
|
||||
.replace(
|
||||
"%saved",
|
||||
if library.is_saved_track(&match playable.clone() {
|
||||
Playable::Episode(episode) => Playable::Episode(episode),
|
||||
Playable::Track(track) => Playable::Track(track),
|
||||
}) {
|
||||
if library.cfg.values().use_nerdfont.unwrap_or_default() {
|
||||
"\u{f62b}"
|
||||
} else {
|
||||
"✓"
|
||||
}
|
||||
} else {
|
||||
""
|
||||
},
|
||||
)
|
||||
.replace("%duration", playable.duration_str().as_str())
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<String> {
|
||||
match self {
|
||||
Playable::Track(track) => track.id.clone(),
|
||||
@@ -106,8 +155,8 @@ impl ListItem for Playable {
|
||||
self.as_listitem().is_playing(queue)
|
||||
}
|
||||
|
||||
fn display_left(&self) -> String {
|
||||
self.as_listitem().display_left()
|
||||
fn display_left(&self, library: Arc<Library>) -> String {
|
||||
self.as_listitem().display_left(library)
|
||||
}
|
||||
|
||||
fn display_center(&self, library: Arc<Library>) -> String {
|
||||
|
||||
Reference in New Issue
Block a user