From b2c225256ff48d5db67d32f86b6bca595074b710 Mon Sep 17 00:00:00 2001 From: Teemu Viikeri Date: Tue, 15 Oct 2024 14:36:45 +0300 Subject: [PATCH] feat: add dynamic handling of play/pause state in bottom controls bar (#31) --- src/player/ui.rs | 2 +- src/player/ui/components.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/player/ui.rs b/src/player/ui.rs index dc92af8..78d417c 100644 --- a/src/player/ui.rs +++ b/src/player/ui.rs @@ -131,7 +131,7 @@ async fn interface(player: Arc, minimalist: bool) -> eyre::Result<()> { VOLUME_TIMER.store(0, Ordering::Relaxed); } - let controls = components::controls(WIDTH); + let controls = components::controls(&player, WIDTH); let menu = if minimalist { vec![action, middle] diff --git a/src/player/ui/components.rs b/src/player/ui/components.rs index 10d7af8..736ea8a 100644 --- a/src/player/ui/components.rs +++ b/src/player/ui/components.rs @@ -103,8 +103,9 @@ pub fn action(player: &Player, width: usize) -> String { } /// Creates the bottom controls bar, and also spaces it properly. -pub fn controls(width: usize) -> String { - let controls = [["[s]", "kip"], ["[p]", "ause"], ["[q]", "uit"]]; +pub fn controls(player: &Player, width: usize) -> String { + let play_pause = if player.sink.is_paused() { ["[p]", "lay "] } else { ["[p]", "ause"] }; + let controls = [["[s]", "kip"], play_pause, ["[q]", "uit"]]; let len: usize = controls.concat().iter().map(|x| x.len()).sum(); let controls = controls.map(|x| format!("{}{}", x[0].bold(), x[1]));