feat: add dynamic handling of play/pause state in bottom controls bar (#31)

This commit is contained in:
Teemu Viikeri 2024-10-15 14:36:45 +03:00 committed by GitHub
parent 8d9d003dc9
commit b2c225256f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View File

@ -131,7 +131,7 @@ async fn interface(player: Arc<Player>, minimalist: bool) -> eyre::Result<()> {
VOLUME_TIMER.store(0, Ordering::Relaxed); VOLUME_TIMER.store(0, Ordering::Relaxed);
} }
let controls = components::controls(WIDTH); let controls = components::controls(&player, WIDTH);
let menu = if minimalist { let menu = if minimalist {
vec![action, middle] vec![action, middle]

View File

@ -103,8 +103,9 @@ pub fn action(player: &Player, width: usize) -> String {
} }
/// Creates the bottom controls bar, and also spaces it properly. /// Creates the bottom controls bar, and also spaces it properly.
pub fn controls(width: usize) -> String { pub fn controls(player: &Player, width: usize) -> String {
let controls = [["[s]", "kip"], ["[p]", "ause"], ["[q]", "uit"]]; 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 len: usize = controls.concat().iter().map(|x| x.len()).sum();
let controls = controls.map(|x| format!("{}{}", x[0].bold(), x[1])); let controls = controls.map(|x| format!("{}{}", x[0].bold(), x[1]));