Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display album name for playable objects #268

Merged
merged 3 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/album.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ impl ListItem for Album {
format!("{}", self)
}

fn display_center(&self) -> String {
"".to_string()
}

fn display_right(&self, library: Arc<Library>) -> String {
let saved = if library.is_saved_album(self) {
if library.use_nerdfont {
Expand Down
4 changes: 4 additions & 0 deletions src/artist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl ListItem for Artist {
format!("{}", self)
}

fn display_center(&self) -> String {
"".to_string()
}

fn display_right(&self, library: Arc<Library>) -> String {
let followed = if library.is_followed_artist(self) {
if library.use_nerdfont {
Expand Down
3 changes: 2 additions & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl CommandManager {
kb.insert("<".into(), Command::Previous);
kb.insert(">".into(), Command::Next);
kb.insert("c".into(), Command::Clear);
kb.insert(" ".into(), Command::Queue);
kb.insert("Space".into(), Command::Queue);
kb.insert("Enter".into(), Command::Play);
kb.insert("s".into(), Command::Save);
kb.insert("Ctrl+s".into(), Command::SaveQueue);
Expand Down Expand Up @@ -375,6 +375,7 @@ impl CommandManager {
fn parse_key(key: &str) -> Event {
match key {
"Enter" => Event::Key(Key::Enter),
"Space" => Event::Char(" ".chars().next().unwrap()),
"Tab" => Event::Key(Key::Tab),
"Backspace" => Event::Key(Key::Backspace),
"Esc" => Event::Key(Key::Esc),
Expand Down
4 changes: 4 additions & 0 deletions src/episode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ impl ListItem for Episode {
self.name.clone()
}

fn display_center(&self) -> String {
"".to_string()
}

fn display_right(&self, _library: Arc<Library>) -> String {
format!("{} [{}]", self.duration_str(), self.release_date)
}
Expand Down
4 changes: 4 additions & 0 deletions src/playable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ impl ListItem for Playable {
self.as_listitem().display_left()
}

fn display_center(&self) -> String {
self.as_listitem().display_center()
}

fn display_right(&self, library: Arc<Library>) -> String {
self.as_listitem().display_right(library)
}
Expand Down
4 changes: 4 additions & 0 deletions src/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ impl ListItem for Playlist {
self.name.clone()
}

fn display_center(&self) -> String {
"".to_string()
}

fn display_right(&self, library: Arc<Library>) -> String {
let saved = if library.is_saved_playlist(self) {
if library.use_nerdfont {
Expand Down
4 changes: 4 additions & 0 deletions src/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ impl ListItem for Show {
format!("{}", self)
}

fn display_center(&self) -> String {
"".to_string()
}

fn display_right(&self, library: Arc<Library>) -> String {
let saved = if library.is_saved_show(self) {
if library.use_nerdfont {
Expand Down
4 changes: 4 additions & 0 deletions src/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ impl ListItem for Track {
format!("{}", self)
}

fn display_center(&self) -> String {
format!("{}", self.album)
}

fn display_right(&self, library: Arc<Library>) -> String {
let saved = if library.is_saved_track(&Playable::Track(self.clone())) {
if library.use_nerdfont {
Expand Down
1 change: 1 addition & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::track::Track;
pub trait ListItem: Sync + Send + 'static {
fn is_playing(&self, queue: Arc<Queue>) -> bool;
fn display_left(&self) -> String;
fn display_center(&self) -> String;
fn display_right(&self, library: Arc<Library>) -> String;
fn play(&mut self, queue: Arc<Queue>);
fn queue(&mut self, queue: Arc<Queue>);
Expand Down
20 changes: 18 additions & 2 deletions src/ui/listview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,23 +202,39 @@ impl<I: ListItem> View for ListView<I> {
};

let left = item.display_left();
let center = item.display_center();
let right = item.display_right(self.library.clone());

let center_offset = printer.size.x / 2;

// draw left string
printer.with_color(style, |printer| {
printer.print_hline((0, 0), printer.size.x, " ");
printer.print((0, 0), &left);
});

// draw ".." to indicate a cut off string
let max_length = printer.size.x.saturating_sub(right.width() + 1);
// left string cut off indicator
let max_length = center_offset.saturating_sub(1);
if max_length < left.width() {
let offset = max_length.saturating_sub(1);
printer.with_color(style, |printer| {
printer.print((offset, 0), "..");
});
}

printer.with_color(style, |printer| {
printer.print((center_offset, 0), &center);
});

// center string cut off indicator
let max_length = printer.size.x.saturating_sub(right.width() + 1);
if max_length < center_offset + center.width() {
let offset = max_length.saturating_sub(1);
printer.with_color(style, |printer| {
printer.print((offset, 0), "..");
});
}

// draw right string
let offset = HAlign::Right.get_offset(right.width(), printer.size.x);

Expand Down