Add shuffle and repeat

This commit is contained in:
KoffeinFlummi
2019-03-25 18:31:39 +01:00
parent e6a7d8a693
commit 45062bd89e
7 changed files with 270 additions and 50 deletions

View File

@@ -8,21 +8,24 @@ use cursive::vec::Vec2;
use cursive::Printer;
use unicode_width::UnicodeWidthStr;
use queue::Queue;
use config::Config;
use queue::{Queue, RepeatSetting};
use spotify::{PlayerEvent, Spotify};
pub struct StatusBar {
queue: Arc<Queue>,
spotify: Arc<Spotify>,
last_size: Vec2,
use_nerdfont: bool,
}
impl StatusBar {
pub fn new(queue: Arc<Queue>, spotify: Arc<Spotify>) -> StatusBar {
pub fn new(queue: Arc<Queue>, spotify: Arc<Spotify>, cfg: &Config) -> StatusBar {
StatusBar {
queue: queue,
spotify: spotify,
last_size: Vec2::new(0, 0),
use_nerdfont: cfg.use_nerdfont.unwrap_or(false)
}
}
}
@@ -53,17 +56,45 @@ impl View for StatusBar {
);
});
let state_icon = match self.spotify.get_current_status() {
PlayerEvent::Playing => "",
PlayerEvent::Paused => "▮▮",
PlayerEvent::Stopped | PlayerEvent::FinishedTrack => " ",
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((0, 1), &state_icon);
printer.print((1, 1), &state_icon);
});
let repeat = if self.use_nerdfont {
match self.queue.get_repeat() {
RepeatSetting::None => "",
RepeatSetting::RepeatPlaylist => "\u{f955} ",
RepeatSetting::RepeatTrack => "\u{f957} ",
}
} else {
match self.queue.get_repeat() {
RepeatSetting::None => "",
RepeatSetting::RepeatPlaylist => "[R] ",
RepeatSetting::RepeatTrack => "[R1] ",
}
}.to_string();
let shuffle = if self.use_nerdfont {
if self.queue.get_shuffle() { "\u{f99c} " } else { "" }
} else {
if self.queue.get_shuffle() { "[Z] " } else { "" }
}.to_string();
if let Some(ref t) = self.queue.get_current() {
let elapsed = self.spotify.get_current_progress();
let elapsed_ms = elapsed.as_secs() as u32 * 1000 + elapsed.subsec_millis();
@@ -74,12 +105,12 @@ impl View for StatusBar {
elapsed.as_secs() % 60
);
let duration = format!("{} / {} ", formatted_elapsed, t.duration_str());
let offset = HAlign::Right.get_offset(duration.width(), printer.size.x);
let right = repeat + &shuffle + &format!("{} / {} ", formatted_elapsed, t.duration_str());
let offset = HAlign::Right.get_offset(right.width(), printer.size.x);
printer.with_color(style, |printer| {
printer.print((4, 1), &t.to_string());
printer.print((offset, 1), &duration);
printer.print((offset, 1), &right);
});
printer.with_color(style_bar, |printer| {
@@ -89,6 +120,13 @@ impl View for StatusBar {
printer.print((0, 0), &format!("{}{}", "=".repeat(duration_width), ">"));
});
} else {
let right = repeat + &shuffle;
let offset = HAlign::Right.get_offset(right.width(), printer.size.x);
printer.with_color(style, |printer| {
printer.print((offset, 1), &right);
});
printer.with_color(style_bar, |printer| {
printer.print((0, 0), &"".repeat(printer.size.x));
});