4 Commits
0.1.8 ... 0.2.0

Author SHA1 Message Date
Alexandr Bogomyakov
5d23b7da2d Bump version 2019-12-24 13:17:20 +03:00
Alexandr Bogomyakov
5cf2ab0e40 Add time feature with custom format. 2019-12-24 13:16:23 +03:00
AB
7c7d9070a4 Update separator. 2019-12-19 01:39:22 +03:00
AB
456d423f47 Improve player metadata displaying. 2019-12-19 01:36:57 +03:00
2 changed files with 50 additions and 21 deletions

View File

@@ -1,9 +1,10 @@
[package] [package]
name = "tmux-helper" name = "tmux-helper"
version = "0.1.0" version = "0.2.0"
authors = ["Ultra Desu <ultradesu@hexor.ru>"] authors = ["Ultra Desu <ultradesu@hexor.ru>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
sys-info = "*" sys-info = "*"
dbus = "*" dbus = "*"
chrono = "*"

View File

@@ -1,5 +1,8 @@
extern crate chrono;
extern crate dbus; extern crate dbus;
use crate::dbus::blocking::stdintf::org_freedesktop_dbus::Properties; use crate::dbus::blocking::stdintf::org_freedesktop_dbus::Properties;
use chrono::{DateTime, FixedOffset, Local, Utc};
use dbus::{arg, blocking::Connection}; use dbus::{arg, blocking::Connection};
use std::{env, fs, time::Duration}; use std::{env, fs, time::Duration};
use sys_info; use sys_info;
@@ -153,9 +156,24 @@ fn format_time(sec: i64) -> String {
result.to_string() result.to_string()
} }
fn get_time(utc: bool, mut format: &str) {
// Format reference: https://docs.rs/chrono/0.4.10/chrono/format/strftime/index.html
if format.len() == 0 {
format = "%H:%M";
}
if utc {
let local_time = Local::now();
let utc_time = DateTime::<Utc>::from_utc(local_time.naive_utc(), Utc);
println!("{}", utc_time.format(format));
} else {
let local_time = Local::now();
println!("{}", local_time.format(format));
}
}
fn main() { fn main() {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
let help_text: &str = "Available commands -mb, -cb"; let help_text: &str = "Available commands -mb, -cb, -tl <TIME FORMAT>, -tu <TIME FORMAT>, -p";
match args.len() { match args.len() {
1 => { 1 => {
panic!(help_text); panic!(help_text);
@@ -163,12 +181,34 @@ fn main() {
2 => match args[1].as_ref() { 2 => match args[1].as_ref() {
"-cb" => cpu_load_bar(15), "-cb" => cpu_load_bar(15),
"-mb" => mem_load_bar(15), "-mb" => mem_load_bar(15),
"-tl" => get_time(false, ""),
"-tu" => get_time(true, ""),
"-p" => match player_info(get_player().unwrap()) { "-p" => match player_info(get_player().unwrap()) {
Ok(mut track_info) => { Ok(mut track_info) => {
let mut title_len = 30; let mut title_len = 30;
let mut artist_len = 30; let mut artist_len = 30;
let mut separator: String = " - ".to_string(); let mut separator: String = " ".to_string();
let max_shift = 6; let max_shift = 6;
if track_info.artist.chars().count() == 0 {
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 artist: String = String::new();
let mut counter = 0;
for ch in track_info.artist.chars() {
if counter == artist_len {
artist.push_str("..");
break;
}
artist.push(ch);
counter += 1;
}
track_info.artist = artist;
}
if title_len + max_shift >= track_info.title.chars().count() { if title_len + max_shift >= track_info.title.chars().count() {
title_len = track_info.title.chars().count() title_len = track_info.title.chars().count()
} }
@@ -177,31 +217,14 @@ fn main() {
let mut counter = 0; let mut counter = 0;
for ch in track_info.title.chars() { for ch in track_info.title.chars() {
if counter == title_len { if counter == title_len {
title.push_str("..");
break; break;
} }
title.push(ch); title.push(ch);
counter += 1; counter += 1;
} }
title.push_str("..");
track_info.title = title; track_info.title = title;
} }
if artist_len + max_shift >= track_info.artist.chars().count() {
artist_len = track_info.artist.chars().count()
}
if track_info.artist.chars().count() == 0 {separator = "".to_string()}
if track_info.artist.len() > artist_len {
let mut artist: String = String::new();
let mut counter = 0;
for ch in track_info.artist.chars() {
if counter == artist_len {
break;
}
artist.push(ch);
counter += 1;
}
artist.push_str("..");
track_info.artist = artist;
}
println!( println!(
"#[none]#[bold]{}{}{}#[none]{}{}{}{} {}[{}/{}] {} {}", "#[none]#[bold]{}{}{}#[none]{}{}{}{} {}[{}/{}] {} {}",
TRACK_NAME, TRACK_NAME,
@@ -222,6 +245,11 @@ fn main() {
}, },
_ => panic!(help_text), _ => panic!(help_text),
}, },
3 => match args[1].as_ref() {
"-tl" => get_time(false, args[2].as_ref()),
"-tu" => get_time(true, args[2].as_ref()),
_ => panic!(help_text),
},
_ => { _ => {
panic!(help_text); panic!(help_text);
} }