5 Commits

Author SHA1 Message Date
AB
e7ac12974f Fix player printing. 2020-05-15 13:07:49 +03:00
AB
6e08864d99 Fix duration format. 2020-05-14 23:39:40 +03:00
AB
6a9a871006 Fix duration format. 2020-05-14 23:32:05 +03:00
AB
bab994fc41 Fix duration format. 2020-05-14 22:13:22 +03:00
AB
fc1c2f539d Aupdate image 2020-05-14 22:00:02 +03:00
3 changed files with 38 additions and 38 deletions

BIN
.github/prev.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "tmux-helper" name = "tmux-helper"
version = "0.3.0" version = "0.3.2"
description = "Utility for printing system info for tmux status line." description = "Utility for printing system info for tmux status line."
authors = ["Ultra Desu <ultradesu@hexor.ru>"] authors = ["Ultra Desu <ultradesu@hexor.ru>"]
edition = "2018" edition = "2018"

View File

@@ -164,46 +164,39 @@ pub fn get_time(utc: bool, format: Option<String>) {
} }
} }
fn format_player(track_info: TrackInfo, config: &config::Config) { fn shorten(line: String, max_len: usize, max_shift: usize) -> String {
let mut title_len = 30; let mut new_line = String::new();
let mut artist_len = 30; let len = if max_len + max_shift >= line.chars().count() {
let mut artist_line: String = String::new(); line.chars().count()
let mut title_line: String = String::new(); } else {
let mut separator: String = "".to_string(); max_len
let max_shift = 6; };
if track_info.artist.chars().count() == 0 { if line.len() > len {
separator = "".to_string();
title_len += artist_len;
}
if artist_len + max_shift >= track_info.artist.chars().count() {
artist_len = track_info.artist.chars().count()
}
if track_info.artist.len() > artist_len {
let mut counter = 0; let mut counter = 0;
for ch in track_info.artist.chars() { for ch in line.chars() {
if counter == artist_len { if counter == len {
artist_line.push_str(".."); new_line.push_str("..");
break; break;
} }
artist_line.push(ch); new_line.push(ch);
counter += 1; counter += 1;
} }
}
else {
new_line = line;
}
new_line
}
fn format_player(track_info: TrackInfo, config: &config::Config) {
let mut separator: String = "".to_string();
let mut max_len = 30;
if track_info.artist.chars().count() == 0 {
separator = "".to_string();
max_len = max_len * 2;
} }
if title_len + max_shift >= track_info.title.chars().count() { let artist_line = shorten(track_info.artist, max_len, 6);
title_len = track_info.title.chars().count() let title_line = shorten(track_info.title, max_len, 6);
}
if track_info.title.len() > title_len {
let mut counter = 0;
for ch in track_info.title.chars() {
if counter == title_len {
title_line.push_str("..");
break;
}
title_line.push(ch);
counter += 1;
}
}
println!( println!(
"#[none]#[bold]{}{}{}#[none]{}{}{}{} {}[{}/{}] {} {}#[default]", "#[none]#[bold]{}{}{}#[none]{}{}{}{} {}[{}/{}] {} {}#[default]",
config.color_track_name, config.color_track_name,
@@ -240,6 +233,7 @@ pub fn mpd(config: &config::Config) {
duration: String::new(), duration: String::new(),
status: String::new(), status: String::new(),
}; };
// println!("{:?}", conn.currentsong());
if let Some(song) = conn.currentsong().unwrap() { if let Some(song) = conn.currentsong().unwrap() {
if let Some(title) = song.title { if let Some(title) = song.title {
track_info.title = title track_info.title = title
@@ -247,10 +241,16 @@ pub fn mpd(config: &config::Config) {
if let Some(artist) = song.tags.get("Artist") { if let Some(artist) = song.tags.get("Artist") {
track_info.artist = artist.to_string() track_info.artist = artist.to_string()
} }
// if there is no tags and title.
if track_info.artist == track_info.title {
if let Some(name) = song.name {
track_info.title = name
}
}
} }
if let Some(time) = conn.status().unwrap().time { if let Some(time) = conn.status().unwrap().time {
track_info.position = time.0.num_seconds().to_string(); track_info.position = format_time(time.0.num_seconds() as i64);
track_info.duration = time.1.num_seconds().to_string() track_info.duration = format_time(time.1.num_seconds() as i64);
} }
let status = match conn.status() { let status = match conn.status() {
Ok(status) => { Ok(status) => {