From 0ed4c77dcd502f1475faf39bfe4c17da0b7daf02 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 22 Feb 2020 19:53:15 +0000 Subject: [PATCH] Show nice volume prompt --- src/main.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8f7cbbe..085f347 100644 --- a/src/main.rs +++ b/src/main.rs @@ -155,7 +155,7 @@ fn main() { if let Some(volume) = sub.value_of("VOLUME") { speaker.set_volume(volume.parse().unwrap()); } else { - info!("{}", speaker.volume().unwrap()); + info!("{}", Volume::new(speaker.volume().unwrap(), speaker.muted().unwrap())); } }, ("seek", Some(sub)) => { @@ -299,12 +299,14 @@ impl std::fmt::Display for Track { #[derive(Serialize, Deserialize, Debug)] struct Volume { volume: u8, + muted: bool, } impl Volume { - pub fn new(vol: u8) -> Volume { + pub fn new(vol: u8, muted: bool) -> Volume { Self { volume: vol, + muted, } } } @@ -314,9 +316,15 @@ impl std::fmt::Display for Volume { const MAX_VOLUME: usize = 100; const PROG_BAR_LEN: usize = 25; - write!(f, "\u{1F50A} {}/{}", self.volume, MAX_VOLUME)?; + let pictogram = if self.muted { + "\u{1F507}" + } else { + "\u{1F50A}" + }; - let percent = (self.volume as usize / MAX_VOLUME) * PROG_BAR_LEN; + write!(f, "{} {}/{}", pictogram, self.volume, MAX_VOLUME)?; + + let percent = (self.volume as usize * PROG_BAR_LEN) / MAX_VOLUME; write!(f, " [{}{}]", "\u{2587}".repeat(percent), "-".repeat(PROG_BAR_LEN - percent)) } -- libgit2 1.7.2