mirror of
https://github.com/house-of-vanity/tmux-helper.git
synced 2026-02-04 09:47:59 +00:00
Merge colorize with player status
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -17,6 +17,7 @@ struct TrackInfo {
|
||||
artist: String,
|
||||
position: String,
|
||||
duration: String,
|
||||
status: String,
|
||||
}
|
||||
|
||||
fn read_file(file_path: &str) -> String {
|
||||
@@ -84,6 +85,7 @@ fn player_info(player: &str) -> Result<TrackInfo, Box<dyn std::error::Error>> {
|
||||
title: "".to_string(),
|
||||
position: "".to_string(),
|
||||
duration: "".to_string(),
|
||||
status: "".to_string(),
|
||||
};
|
||||
while let Some(key) = iter.next() {
|
||||
if key.as_str() == Some("xesam:title") {
|
||||
@@ -108,6 +110,14 @@ fn player_info(player: &str) -> Result<TrackInfo, Box<dyn std::error::Error>> {
|
||||
}
|
||||
let position: Box<dyn arg::RefArg> = proxy.get("org.mpris.MediaPlayer2.Player", "Position")?;
|
||||
track_info.position = format_time(position.as_i64().unwrap() / 1000000);
|
||||
// ugly
|
||||
let _status_text_box: Box<dyn arg::RefArg> = proxy.get("org.mpris.MediaPlayer2.Player", "PlaybackStatus")?;
|
||||
let _status_text = _status_text_box.as_str().unwrap();
|
||||
match _status_text.as_ref() {
|
||||
"Playing" => track_info.status = "▶".to_string(),
|
||||
"Paused" => track_info.status = "⏸".to_string(),
|
||||
_ => track_info.status = "⏹".to_string(),
|
||||
};
|
||||
Ok(track_info)
|
||||
}
|
||||
|
||||
@@ -141,7 +151,7 @@ fn main() {
|
||||
track_info.artist.push_str("..");
|
||||
}
|
||||
println!(
|
||||
"#[none]#[bold]{}{}{}#[none]{} - {}{} {}[{}/{}]{}",
|
||||
"#[none]#[bold]{}{}{}#[none]{} - {}{} {}[{}/{}] {} {}",
|
||||
TRACK_NAME,
|
||||
track_info.title,
|
||||
END,
|
||||
@@ -151,10 +161,11 @@ fn main() {
|
||||
TRACK_TIME,
|
||||
track_info.position,
|
||||
track_info.duration,
|
||||
track_info.status,
|
||||
END,
|
||||
);
|
||||
}
|
||||
Err(_e) => panic!("Can't get mediaplayer info."),
|
||||
Err(_e) => println!("No music playing"),
|
||||
},
|
||||
_ => panic!(help_text),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user