From 573cb35b52118285bc6d79c813ac2b2de340dd8c Mon Sep 17 00:00:00 2001 From: AB Date: Tue, 7 Jul 2020 09:17:27 +0300 Subject: [PATCH] Linting and minor style changes --- .github/workflows/PKGBUILD | 2 +- Cargo.toml | 3 ++- src/config.rs | 46 +++++++++++++++++++------------------- src/utils.rs | 38 +++++++++++++++++-------------- 4 files changed, 47 insertions(+), 42 deletions(-) diff --git a/.github/workflows/PKGBUILD b/.github/workflows/PKGBUILD index 32c2af5..d6cd4b6 100644 --- a/.github/workflows/PKGBUILD +++ b/.github/workflows/PKGBUILD @@ -1,7 +1,7 @@ # Maintainer: Alexandr Bogomyakov (ultradesu) pkgname=tmux-helper -pkgver=0.2.1 +pkgver=0.3.3 pkgrel=1 pkgdesc="Tmux helper" url="https://github.com/house-of-vanity/tmux-helper.git" diff --git a/Cargo.toml b/Cargo.toml index e66fd76..b358712 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tmux-helper" -version = "0.3.2" +version = "0.3.3" description = "Utility for printing system info for tmux status line." authors = ["Ultra Desu "] edition = "2018" @@ -11,3 +11,4 @@ dbus = "*" chrono = "*" mpd = "*" clap = "*" +size_format = "1.0" diff --git a/src/config.rs b/src/config.rs index 524032d..920ca65 100644 --- a/src/config.rs +++ b/src/config.rs @@ -55,11 +55,11 @@ pub fn read() -> Config { .short("m") .long("mem") .help("Print mem usage bar.") -// .conflicts_with("cpu") -// .conflicts_with("mpris") -// .conflicts_with("mpd") -// .conflicts_with("localtime") -// .conflicts_with("utctime") + // .conflicts_with("cpu") + // .conflicts_with("mpris") + // .conflicts_with("mpd") + // .conflicts_with("localtime") + // .conflicts_with("utctime") .required(false), ) .arg( @@ -67,11 +67,11 @@ pub fn read() -> Config { .short("p") .long("mpris") .help("Show player info using MPRIS2 interface.") -// .conflicts_with("cpu") -// .conflicts_with("mem") -// .conflicts_with("localtime") -// .conflicts_with("mpd") -// .conflicts_with("utctime") + // .conflicts_with("cpu") + // .conflicts_with("mem") + // .conflicts_with("localtime") + // .conflicts_with("mpd") + // .conflicts_with("utctime") .required(false), ) .arg( @@ -79,11 +79,11 @@ pub fn read() -> Config { .short("d") .long("mpd") .help("Show mpd player using MPD native protocol.") -// .conflicts_with("cpu") -// .conflicts_with("mem") -// .conflicts_with("localtime") -// .conflicts_with("mpris") -// .conflicts_with("utctime") + // .conflicts_with("cpu") + // .conflicts_with("mem") + // .conflicts_with("localtime") + // .conflicts_with("mpris") + // .conflicts_with("utctime") .required(false), ) // Options @@ -92,7 +92,7 @@ pub fn read() -> Config { .short("l") .long("localtime") .help("Local time") -// .conflicts_with_all(&["mem", "mpris", "mpd", "cpu", "utctime"]) + // .conflicts_with_all(&["mem", "mpris", "mpd", "cpu", "utctime"]) .takes_value(true) .required(false), ) @@ -101,7 +101,7 @@ pub fn read() -> Config { .short("u") .long("utctime") .help("UTC time") -// .conflicts_with_all(&["mem", "mpris", "mpd", "cpu", "localtime"]) + // .conflicts_with_all(&["mem", "mpris", "mpd", "cpu", "localtime"]) .takes_value(true) .required(false), ) @@ -182,13 +182,13 @@ pub fn read() -> Config { // ut_format - utc time format let lt_format = Some(match cli_args.value_of("localtime") { - Some(format) => format.to_string(), - None => "%H:%M".to_string(), - }); + Some(format) => format.to_string(), + None => "%H:%M".to_string(), + }); let ut_format = Some(match cli_args.value_of("utctime") { - Some(format) => format.to_string(), - None => "%H:%M".to_string(), - }); + Some(format) => format.to_string(), + None => "%H:%M".to_string(), + }); let mut cfg = Config { action: Action::Cpu, diff --git a/src/utils.rs b/src/utils.rs index f17acde..f731aae 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,10 +2,11 @@ use crate::config; use crate::dbus::blocking::stdintf::org_freedesktop_dbus::Properties; use chrono::{DateTime, Local, Utc}; use dbus::{arg, blocking::Connection}; +use mpd::Client; +use size_format::SizeFormatterBinary; +use std::process; use std::time::Duration; use sys_info; -use mpd::Client; -use std::process; #[derive(Debug, Clone)] pub struct TrackInfo { @@ -47,7 +48,10 @@ pub fn mem_load_bar(bar_len: i32, config: &config::Config) { let len = ((memory.total - memory.avail) as f32 / (memory.total as f32) * bar_len as f32) as i32; to_bar(len, bar_len, 0.7, 0.9, config); - print!("{:.0} MiB#[default]", memory.avail / 1024); + print!( + "{}B #[default]", + SizeFormatterBinary::new((memory.avail * 1000) as u64) + ); } pub fn cpu_load_bar(bar_len: i32, config: &config::Config) { @@ -181,8 +185,7 @@ fn shorten(line: String, max_len: usize, max_shift: usize) -> String { new_line.push(ch); counter += 1; } - } - else { + } else { new_line = line; } new_line @@ -224,7 +227,10 @@ pub fn mpris(config: &config::Config) { pub fn mpd(config: &config::Config) { let mut conn = match Client::connect(&config.mpd_server) { Ok(conn) => conn, - Err(e) => {println!("Can't connect to MPD server. {}", e); process::exit(0x0001)} + Err(e) => { + println!("Can't connect to MPD server. {}", e); + process::exit(0x0001) + } }; let mut track_info = TrackInfo { title: String::new(), @@ -233,7 +239,7 @@ pub fn mpd(config: &config::Config) { duration: String::new(), status: String::new(), }; -// println!("{:?}", conn.currentsong()); + // println!("{:?}", conn.currentsong()); if let Some(song) = conn.currentsong().unwrap() { if let Some(title) = song.title { track_info.title = title @@ -249,18 +255,16 @@ pub fn mpd(config: &config::Config) { } } if let Some(time) = conn.status().unwrap().time { - track_info.position = format_time(time.0.num_seconds() as i64); - track_info.duration = format_time(time.1.num_seconds() as i64); + track_info.position = format_time(time.0.num_seconds() as i64); + track_info.duration = format_time(time.1.num_seconds() as i64); } let status = match conn.status() { - Ok(status) => { - match status.state { - mpd::State::Play => "▶".to_string(), - mpd::State::Pause => "⏸".to_string(), - mpd::State::Stop => "⏹".to_string(), - } - } - Err(_) => {"⏹".to_string()}, + Ok(status) => match status.state { + mpd::State::Play => "▶".to_string(), + mpd::State::Pause => "⏸".to_string(), + mpd::State::Stop => "⏹".to_string(), + }, + Err(_) => "⏹".to_string(), }; track_info.status = status; format_player(track_info, config)