mirror of
https://github.com/house-of-vanity/tmux-helper.git
synced 2026-02-04 17:57:58 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7ac12974f | ||
|
|
6e08864d99 | ||
|
|
6a9a871006 | ||
|
|
bab994fc41 | ||
|
|
fc1c2f539d |
BIN
.github/prev.png
vendored
BIN
.github/prev.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 25 KiB |
@@ -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"
|
||||||
|
|||||||
74
src/utils.rs
74
src/utils.rs
@@ -164,46 +164,39 @@ pub fn get_time(utc: bool, format: Option<String>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn shorten(line: String, max_len: usize, max_shift: usize) -> String {
|
||||||
|
let mut new_line = String::new();
|
||||||
|
let len = if max_len + max_shift >= line.chars().count() {
|
||||||
|
line.chars().count()
|
||||||
|
} else {
|
||||||
|
max_len
|
||||||
|
};
|
||||||
|
if line.len() > len {
|
||||||
|
let mut counter = 0;
|
||||||
|
for ch in line.chars() {
|
||||||
|
if counter == len {
|
||||||
|
new_line.push_str("..");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
new_line.push(ch);
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new_line = line;
|
||||||
|
}
|
||||||
|
new_line
|
||||||
|
}
|
||||||
|
|
||||||
fn format_player(track_info: TrackInfo, config: &config::Config) {
|
fn format_player(track_info: TrackInfo, config: &config::Config) {
|
||||||
let mut title_len = 30;
|
|
||||||
let mut artist_len = 30;
|
|
||||||
let mut artist_line: String = String::new();
|
|
||||||
let mut title_line: String = String::new();
|
|
||||||
let mut separator: String = " — ".to_string();
|
let mut separator: String = " — ".to_string();
|
||||||
let max_shift = 6;
|
let mut max_len = 30;
|
||||||
if track_info.artist.chars().count() == 0 {
|
if track_info.artist.chars().count() == 0 {
|
||||||
separator = "".to_string();
|
separator = "".to_string();
|
||||||
title_len += artist_len;
|
max_len = max_len * 2;
|
||||||
}
|
|
||||||
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;
|
|
||||||
for ch in track_info.artist.chars() {
|
|
||||||
if counter == artist_len {
|
|
||||||
artist_line.push_str("..");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
artist_line.push(ch);
|
|
||||||
counter += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if title_len + max_shift >= track_info.title.chars().count() {
|
|
||||||
title_len = track_info.title.chars().count()
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
let artist_line = shorten(track_info.artist, max_len, 6);
|
||||||
|
let title_line = shorten(track_info.title, max_len, 6);
|
||||||
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) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user