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
@@ -1,6 +1,7 @@
|
||||
use std::fmt;
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use crate::config;
|
||||
use chrono::{DateTime, Utc};
|
||||
use rspotify::model::album::FullAlbum;
|
||||
use rspotify::model::track::{FullTrack, SavedTrack, SimplifiedTrack};
|
||||
@@ -181,33 +182,61 @@ impl ListItem for Track {
|
||||
current.map(|t| t.id() == self.id).unwrap_or(false)
|
||||
}
|
||||
|
||||
fn as_listitem(&self) -> Box<dyn ListItem> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
|
||||
fn display_left(&self) -> String {
|
||||
format!("{}", self)
|
||||
fn display_left(&self, library: Arc<Library>) -> String {
|
||||
let formatting = library
|
||||
.cfg
|
||||
.values()
|
||||
.track_format
|
||||
.clone()
|
||||
.unwrap_or_default();
|
||||
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)
|
||||
} else {
|
||||
format!("{}", self)
|
||||
}
|
||||
}
|
||||
|
||||
fn display_center(&self, library: Arc<Library>) -> String {
|
||||
if library.cfg.values().album_column.unwrap_or(true) {
|
||||
self.album.clone().unwrap_or_default()
|
||||
let formatting = library
|
||||
.cfg
|
||||
.values()
|
||||
.track_format
|
||||
.clone()
|
||||
.unwrap_or_default();
|
||||
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)
|
||||
} else {
|
||||
"".to_string()
|
||||
self.album.clone().unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
fn display_right(&self, library: Arc<Library>) -> String {
|
||||
let saved = if library.is_saved_track(&Playable::Track(self.clone())) {
|
||||
if library.cfg.values().use_nerdfont.unwrap_or(false) {
|
||||
"\u{f62b} "
|
||||
} else {
|
||||
"✓ "
|
||||
}
|
||||
let formatting = library
|
||||
.cfg
|
||||
.values()
|
||||
.track_format
|
||||
.clone()
|
||||
.unwrap_or_default();
|
||||
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)
|
||||
} else {
|
||||
""
|
||||
};
|
||||
format!("{}{}", saved, self.duration_str())
|
||||
let saved = if library.is_saved_track(&Playable::Track(self.clone())) {
|
||||
if library.cfg.values().use_nerdfont.unwrap_or(false) {
|
||||
"\u{f62b}"
|
||||
} else {
|
||||
"✓"
|
||||
}
|
||||
} else {
|
||||
""
|
||||
};
|
||||
format!("{} {}", saved, self.duration_str())
|
||||
}
|
||||
}
|
||||
|
||||
fn play(&mut self, queue: Arc<Queue>) {
|
||||
@@ -223,14 +252,6 @@ impl ListItem for Track {
|
||||
queue.append(Playable::Track(self.clone()));
|
||||
}
|
||||
|
||||
fn save(&mut self, library: Arc<Library>) {
|
||||
library.save_tracks(vec![self], true);
|
||||
}
|
||||
|
||||
fn unsave(&mut self, library: Arc<Library>) {
|
||||
library.unsave_tracks(vec![self], true);
|
||||
}
|
||||
|
||||
fn toggle_saved(&mut self, library: Arc<Library>) {
|
||||
if library.is_saved_track(&Playable::Track(self.clone())) {
|
||||
library.unsave_tracks(vec![self], true);
|
||||
@@ -239,6 +260,14 @@ impl ListItem for Track {
|
||||
}
|
||||
}
|
||||
|
||||
fn save(&mut self, library: Arc<Library>) {
|
||||
library.save_tracks(vec![self], true);
|
||||
}
|
||||
|
||||
fn unsave(&mut self, library: Arc<Library>) {
|
||||
library.unsave_tracks(vec![self], true);
|
||||
}
|
||||
|
||||
fn open(&self, _queue: Arc<Queue>, _library: Arc<Library>) -> Option<Box<dyn ViewExt>> {
|
||||
None
|
||||
}
|
||||
@@ -303,4 +332,8 @@ impl ListItem for Track {
|
||||
fn track(&self) -> Option<Track> {
|
||||
Some(self.clone())
|
||||
}
|
||||
|
||||
fn as_listitem(&self) -> Box<dyn ListItem> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user