From 08f8a0a134e373a93a47362671bea33302f36c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Thu, 25 May 2023 21:54:51 +0300 Subject: [PATCH] workaround for ampersand --- nowplaying.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/nowplaying.rs b/nowplaying.rs index 5c435bc..c885bdf 100644 --- a/nowplaying.rs +++ b/nowplaying.rs @@ -1,26 +1,35 @@ +/* + * Ferit Yiğit BALABAN, + * nowplaying.rs 2023 + */ + use std::process::Command; fn main() { - let output0 = Command::new("/usr/bin/playerctl") + let output0 = Command::new("playerctl") .arg("status") .output() .expect("err: call playerctl status"); - let status = String::from_utf8_lossy(&output0.stdout); - if status == "Playing\n" { - let output1 = Command::new("/usr/bin/playerctl") + match status.trim() { + "Playing" => { + let output1 = Command::new("playerctl") .arg("-f") - .arg("'{{trunc(xesam:artist, 15)}} - {{trunc(xesam:title, 30)}}'") + .arg("{{trunc(xesam:artist, 15)}} - {{trunc(xesam:title, 30)}}") .arg("metadata") .output() .expect("err: call playerctl metadata"); - let music = &String::from_utf8(output1.stdout).unwrap(); - println!("{}", &music[1..music.len() - 2]); - } else if status == "Paused\n" { - println!("Paused\n"); - } else { - println!(""); + let music = String::from_utf8(output1.stdout).unwrap(); + let music = music.replace("&", "&"); + println!("{}", music); + } + "Paused" => { + println!("Paused"); + } + _ => { + println!(""); + } } }