mirror of
https://github.com/house-of-vanity/tmux-helper.git
synced 2026-02-04 17:57:58 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9c59a6733 | ||
|
|
5d37a86d09 | ||
|
|
573cb35b52 | ||
|
|
b1015ada2f |
2
.github/workflows/PKGBUILD
vendored
2
.github/workflows/PKGBUILD
vendored
@@ -1,7 +1,7 @@
|
|||||||
# Maintainer: Alexandr Bogomyakov (ultradesu) <ab@hexor.ru>
|
# Maintainer: Alexandr Bogomyakov (ultradesu) <ab@hexor.ru>
|
||||||
|
|
||||||
pkgname=tmux-helper
|
pkgname=tmux-helper
|
||||||
pkgver=0.2.1
|
pkgver=0.3.4
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="Tmux helper"
|
pkgdesc="Tmux helper"
|
||||||
url="https://github.com/house-of-vanity/tmux-helper.git"
|
url="https://github.com/house-of-vanity/tmux-helper.git"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tmux-helper"
|
name = "tmux-helper"
|
||||||
version = "0.3.2"
|
version = "0.3.4"
|
||||||
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"
|
||||||
@@ -11,3 +11,4 @@ dbus = "*"
|
|||||||
chrono = "*"
|
chrono = "*"
|
||||||
mpd = "*"
|
mpd = "*"
|
||||||
clap = "*"
|
clap = "*"
|
||||||
|
size_format = "1.0"
|
||||||
|
|||||||
37
README.md
37
README.md
@@ -3,14 +3,37 @@ Small app that perform system check and print TMUX friendly output.
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
### Features:
|
|
||||||
1. `tmux-helper -cb` print cpu load with bar.
|
|
||||||
2. `tmux-helper -mb` print memory usage with bar.
|
|
||||||
3. `tmux-helper -p` show current player status using d-bus.
|
|
||||||
|
|
||||||
### Building
|
### Building
|
||||||
`cargo build --release`
|
`cargo build --release`
|
||||||
or get binary on release page
|
or get binary on release page
|
||||||
|
|
||||||
### Customization
|
### Fetures
|
||||||
Colours are hardcoded but it's easy to change it. It defined as CONST in very beginning of main.rs file.
|
```shell
|
||||||
|
tmux-helper 0.3.2
|
||||||
|
Ultra Desu <ultradesu@hexor.ru>
|
||||||
|
Utility for printing system info for tmux status line.
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
tmux-helper [FLAGS] [OPTIONS]
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
-c, --cpu Print cpu load bar.
|
||||||
|
-h, --help Prints help information
|
||||||
|
-m, --mem Print mem usage bar.
|
||||||
|
-d, --mpd Show mpd player using MPD native protocol.
|
||||||
|
-p, --mpris Show player info using MPRIS2 interface.
|
||||||
|
-V, --version Prints version information
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
--COLOR_END <COLOR_END> Default color using to terminate others.
|
||||||
|
--COLOR_HIGH <COLOR_HIGH> CPU and MEM bar color while high usage.
|
||||||
|
--COLOR_LOW <COLOR_LOW> CPU and MEM bar color while low usage.
|
||||||
|
--COLOR_MID <COLOR_MID> CPU and MEM bar color while mid usage.
|
||||||
|
--COLOR_TRACK_ARTIST <COLOR_TRACK_ARTIST> Color of artist name filed.
|
||||||
|
--COLOR_TRACK_NAME <COLOR_TRACK_NAME> Color of track name filed.
|
||||||
|
--COLOR_TRACK_TIME <COLOR_TRACK_TIME> Color of playing time field.
|
||||||
|
-l, --localtime <localtime> Local time
|
||||||
|
-a, --mpd-address <mpd_address> <ADDR>:<PORT> of MPD server.
|
||||||
|
-u, --utctime <utctime> UTC time
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -55,11 +55,11 @@ pub fn read() -> Config {
|
|||||||
.short("m")
|
.short("m")
|
||||||
.long("mem")
|
.long("mem")
|
||||||
.help("Print mem usage bar.")
|
.help("Print mem usage bar.")
|
||||||
// .conflicts_with("cpu")
|
// .conflicts_with("cpu")
|
||||||
// .conflicts_with("mpris")
|
// .conflicts_with("mpris")
|
||||||
// .conflicts_with("mpd")
|
// .conflicts_with("mpd")
|
||||||
// .conflicts_with("localtime")
|
// .conflicts_with("localtime")
|
||||||
// .conflicts_with("utctime")
|
// .conflicts_with("utctime")
|
||||||
.required(false),
|
.required(false),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
@@ -67,11 +67,11 @@ pub fn read() -> Config {
|
|||||||
.short("p")
|
.short("p")
|
||||||
.long("mpris")
|
.long("mpris")
|
||||||
.help("Show player info using MPRIS2 interface.")
|
.help("Show player info using MPRIS2 interface.")
|
||||||
// .conflicts_with("cpu")
|
// .conflicts_with("cpu")
|
||||||
// .conflicts_with("mem")
|
// .conflicts_with("mem")
|
||||||
// .conflicts_with("localtime")
|
// .conflicts_with("localtime")
|
||||||
// .conflicts_with("mpd")
|
// .conflicts_with("mpd")
|
||||||
// .conflicts_with("utctime")
|
// .conflicts_with("utctime")
|
||||||
.required(false),
|
.required(false),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
@@ -79,11 +79,11 @@ pub fn read() -> Config {
|
|||||||
.short("d")
|
.short("d")
|
||||||
.long("mpd")
|
.long("mpd")
|
||||||
.help("Show mpd player using MPD native protocol.")
|
.help("Show mpd player using MPD native protocol.")
|
||||||
// .conflicts_with("cpu")
|
// .conflicts_with("cpu")
|
||||||
// .conflicts_with("mem")
|
// .conflicts_with("mem")
|
||||||
// .conflicts_with("localtime")
|
// .conflicts_with("localtime")
|
||||||
// .conflicts_with("mpris")
|
// .conflicts_with("mpris")
|
||||||
// .conflicts_with("utctime")
|
// .conflicts_with("utctime")
|
||||||
.required(false),
|
.required(false),
|
||||||
)
|
)
|
||||||
// Options
|
// Options
|
||||||
@@ -92,7 +92,7 @@ pub fn read() -> Config {
|
|||||||
.short("l")
|
.short("l")
|
||||||
.long("localtime")
|
.long("localtime")
|
||||||
.help("Local time")
|
.help("Local time")
|
||||||
// .conflicts_with_all(&["mem", "mpris", "mpd", "cpu", "utctime"])
|
// .conflicts_with_all(&["mem", "mpris", "mpd", "cpu", "utctime"])
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.required(false),
|
.required(false),
|
||||||
)
|
)
|
||||||
@@ -101,7 +101,7 @@ pub fn read() -> Config {
|
|||||||
.short("u")
|
.short("u")
|
||||||
.long("utctime")
|
.long("utctime")
|
||||||
.help("UTC time")
|
.help("UTC time")
|
||||||
// .conflicts_with_all(&["mem", "mpris", "mpd", "cpu", "localtime"])
|
// .conflicts_with_all(&["mem", "mpris", "mpd", "cpu", "localtime"])
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.required(false),
|
.required(false),
|
||||||
)
|
)
|
||||||
@@ -182,13 +182,13 @@ pub fn read() -> Config {
|
|||||||
// ut_format - utc time format
|
// ut_format - utc time format
|
||||||
|
|
||||||
let lt_format = Some(match cli_args.value_of("localtime") {
|
let lt_format = Some(match cli_args.value_of("localtime") {
|
||||||
Some(format) => format.to_string(),
|
Some(format) => format.to_string(),
|
||||||
None => "%H:%M".to_string(),
|
None => "%H:%M".to_string(),
|
||||||
});
|
});
|
||||||
let ut_format = Some(match cli_args.value_of("utctime") {
|
let ut_format = Some(match cli_args.value_of("utctime") {
|
||||||
Some(format) => format.to_string(),
|
Some(format) => format.to_string(),
|
||||||
None => "%H:%M".to_string(),
|
None => "%H:%M".to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut cfg = Config {
|
let mut cfg = Config {
|
||||||
action: Action::Cpu,
|
action: Action::Cpu,
|
||||||
|
|||||||
84
src/utils.rs
84
src/utils.rs
@@ -2,10 +2,11 @@ use crate::config;
|
|||||||
use crate::dbus::blocking::stdintf::org_freedesktop_dbus::Properties;
|
use crate::dbus::blocking::stdintf::org_freedesktop_dbus::Properties;
|
||||||
use chrono::{DateTime, Local, Utc};
|
use chrono::{DateTime, Local, Utc};
|
||||||
use dbus::{arg, blocking::Connection};
|
use dbus::{arg, blocking::Connection};
|
||||||
|
use mpd::Client;
|
||||||
|
use size_format::SizeFormatterBinary;
|
||||||
|
use std::process;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use sys_info;
|
use sys_info;
|
||||||
use mpd::Client;
|
|
||||||
use std::process;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TrackInfo {
|
pub struct TrackInfo {
|
||||||
@@ -47,7 +48,10 @@ pub fn mem_load_bar(bar_len: i32, config: &config::Config) {
|
|||||||
let len =
|
let len =
|
||||||
((memory.total - memory.avail) as f32 / (memory.total as f32) * bar_len as f32) as i32;
|
((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);
|
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) {
|
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);
|
new_line.push(ch);
|
||||||
counter += 1;
|
counter += 1;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
new_line = line;
|
new_line = line;
|
||||||
}
|
}
|
||||||
new_line
|
new_line
|
||||||
@@ -197,21 +200,37 @@ fn format_player(track_info: TrackInfo, config: &config::Config) {
|
|||||||
}
|
}
|
||||||
let artist_line = shorten(track_info.artist, max_len, 6);
|
let artist_line = shorten(track_info.artist, max_len, 6);
|
||||||
let title_line = shorten(track_info.title, max_len, 6);
|
let title_line = shorten(track_info.title, max_len, 6);
|
||||||
println!(
|
if track_info.position == "00:00" || track_info.duration == "" {
|
||||||
"#[none]#[bold]{}{}{}#[none]{}{}{}{} {}[{}/{}] {} {}#[default]",
|
println!(
|
||||||
config.color_track_name,
|
"#[none]#[bold]{}{}{}#[none]{}{}{}{} {}{} {}#[default]",
|
||||||
title_line,
|
config.color_track_name,
|
||||||
config.color_end,
|
title_line,
|
||||||
separator,
|
config.color_end,
|
||||||
config.color_track_artist,
|
separator,
|
||||||
artist_line,
|
config.color_track_artist,
|
||||||
config.color_end,
|
artist_line,
|
||||||
config.color_track_time,
|
config.color_end,
|
||||||
track_info.position,
|
config.color_track_time,
|
||||||
track_info.duration,
|
track_info.status,
|
||||||
track_info.status,
|
config.color_end,
|
||||||
config.color_end,
|
);
|
||||||
);
|
} else {
|
||||||
|
println!(
|
||||||
|
"#[none]#[bold]{}{}{}#[none]{}{}{}{} {}[{}/{}] {} {}#[default]",
|
||||||
|
config.color_track_name,
|
||||||
|
title_line,
|
||||||
|
config.color_end,
|
||||||
|
separator,
|
||||||
|
config.color_track_artist,
|
||||||
|
artist_line,
|
||||||
|
config.color_end,
|
||||||
|
config.color_track_time,
|
||||||
|
track_info.position,
|
||||||
|
track_info.duration,
|
||||||
|
track_info.status,
|
||||||
|
config.color_end,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mpris(config: &config::Config) {
|
pub fn mpris(config: &config::Config) {
|
||||||
@@ -224,7 +243,10 @@ pub fn mpris(config: &config::Config) {
|
|||||||
pub fn mpd(config: &config::Config) {
|
pub fn mpd(config: &config::Config) {
|
||||||
let mut conn = match Client::connect(&config.mpd_server) {
|
let mut conn = match Client::connect(&config.mpd_server) {
|
||||||
Ok(conn) => conn,
|
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 {
|
let mut track_info = TrackInfo {
|
||||||
title: String::new(),
|
title: String::new(),
|
||||||
@@ -233,7 +255,7 @@ pub fn mpd(config: &config::Config) {
|
|||||||
duration: String::new(),
|
duration: String::new(),
|
||||||
status: String::new(),
|
status: String::new(),
|
||||||
};
|
};
|
||||||
// println!("{:?}", conn.currentsong());
|
// 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
|
||||||
@@ -249,18 +271,16 @@ pub fn mpd(config: &config::Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(time) = conn.status().unwrap().time {
|
if let Some(time) = conn.status().unwrap().time {
|
||||||
track_info.position = format_time(time.0.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);
|
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) => match status.state {
|
||||||
match status.state {
|
mpd::State::Play => "▶".to_string(),
|
||||||
mpd::State::Play => "▶".to_string(),
|
mpd::State::Pause => "⏸".to_string(),
|
||||||
mpd::State::Pause => "⏸".to_string(),
|
mpd::State::Stop => "⏹".to_string(),
|
||||||
mpd::State::Stop => "⏹".to_string(),
|
},
|
||||||
}
|
Err(_) => "⏹".to_string(),
|
||||||
}
|
|
||||||
Err(_) => {"⏹".to_string()},
|
|
||||||
};
|
};
|
||||||
track_info.status = status;
|
track_info.status = status;
|
||||||
format_player(track_info, config)
|
format_player(track_info, config)
|
||||||
|
|||||||
Reference in New Issue
Block a user