mirror of
https://github.com/house-of-vanity/tmux-helper.git
synced 2026-02-04 09:47:59 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f62bcf55e | ||
|
|
a420204e5d | ||
|
|
b5db03203c | ||
|
|
d9b5643ae5 |
@@ -6,7 +6,7 @@ authors = ["Ultra Desu <ultradesu@hexor.ru>"]
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
sys-info = "0.9"
|
||||
sysinfo = "0.36.0"
|
||||
dbus = "0.9"
|
||||
chrono = "0.4"
|
||||
mpd = "0.1"
|
||||
|
||||
70
README.md
70
README.md
@@ -1,7 +1,8 @@
|
||||
# Tmux helper
|
||||
Small app that perform system check and print TMUX friendly output.
|
||||
Small app that perform system check and print TMUX friendly output. Prebuilded for MacOS M chip and Linux AMD64
|
||||
|
||||
<img width="1495" height="1264" alt="image" src="https://github.com/user-attachments/assets/7b9ffc97-0b59-4028-9b5d-f29347d16000" />
|
||||
|
||||

|
||||
|
||||
### Building
|
||||
`cargo build --release`
|
||||
@@ -9,31 +10,50 @@ or get binary on release page
|
||||
|
||||
### Fetures
|
||||
```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]
|
||||
Usage: tmux-helper [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
|
||||
Options:
|
||||
-c, --cpu
|
||||
Print cpu load bar.
|
||||
-m, --mem
|
||||
Print mem usage bar.
|
||||
--low <low>
|
||||
Low threshold (0.0 - 1.0) [default: 0.7]
|
||||
--mid <mid>
|
||||
Mid threshold (0.0 - 1.0) [default: 0.9]
|
||||
-p, --mpris
|
||||
Show player info using MPRIS2 interface.
|
||||
-d, --mpd
|
||||
Show mpd player using MPD native protocol.
|
||||
-l, --localtime [<localtime>]
|
||||
Local time
|
||||
-u, --utctime [<utctime>]
|
||||
UTC time
|
||||
-s, --symbol [<bar_symbol>]
|
||||
Symbol to build bar [default: ▮]
|
||||
-e, --empty-symbol [<bar_empty_symbol>]
|
||||
Symbol to represent the empty part of the bar [default: ▯]
|
||||
-a, --mpd-address <mpd_address>
|
||||
<ADDR>:<PORT> of MPD server. [default: 127.0.0.1:6600]
|
||||
--COLOR_LOW <COLOR_LOW>
|
||||
CPU and MEM bar color while low usage. [default: 119]
|
||||
--COLOR_MID <COLOR_MID>
|
||||
CPU and MEM bar color while mid usage. [default: 220]
|
||||
--COLOR_HIGH <COLOR_HIGH>
|
||||
CPU and MEM bar color while high usage. [default: 197]
|
||||
--COLOR_TRACK_NAME <COLOR_TRACK_NAME>
|
||||
Color of track name filed. [default: 46]
|
||||
--COLOR_TRACK_ARTIST <COLOR_TRACK_ARTIST>
|
||||
Color of artist name filed. [default: 46]
|
||||
--COLOR_TRACK_TIME <COLOR_TRACK_TIME>
|
||||
Color of playing time field. [default: 153]
|
||||
--COLOR_END <COLOR_END>
|
||||
Default color using to terminate others. [default: 153]
|
||||
-h, --help
|
||||
Print help
|
||||
-V, --version
|
||||
Print version
|
||||
```
|
||||
|
||||
|
||||
53
src/utils.rs
53
src/utils.rs
@@ -6,8 +6,9 @@ use dbus::{arg, blocking::Connection};
|
||||
use mpd::Client;
|
||||
use size_format::SizeFormatterBinary;
|
||||
use std::process;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use sys_info;
|
||||
use sysinfo::System;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TrackInfo {
|
||||
@@ -39,9 +40,26 @@ pub fn to_bar(value: i32, max: i32, low: f32, mid: f32, config: &config::Config)
|
||||
}
|
||||
|
||||
pub fn mem_load_bar(bar_len: i32, config: &config::Config) {
|
||||
let memory = sys_info::mem_info().expect("Failed to get mem_info");
|
||||
let used_ratio = (memory.total - memory.avail) as f32 / memory.total as f32;
|
||||
let mut sys = System::new_all();
|
||||
sys.refresh_memory();
|
||||
|
||||
let total_memory = sys.total_memory();
|
||||
let used_memory = sys.used_memory();
|
||||
|
||||
// On macOS sysinfo.used_memory() includes caches and compressed memory
|
||||
// Try a more conservative estimate
|
||||
// Usually real used memory is about 30-50% of what sysinfo shows
|
||||
#[cfg(target_os = "macos")]
|
||||
let actual_used = used_memory * 40 / 100; // Approximately 40% of sysinfo.used_memory
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let actual_used = used_memory;
|
||||
|
||||
let actual_free = total_memory - actual_used;
|
||||
|
||||
let used_ratio = actual_used as f32 / total_memory as f32;
|
||||
let len = (used_ratio * bar_len as f32) as i32;
|
||||
|
||||
to_bar(
|
||||
len,
|
||||
bar_len,
|
||||
@@ -49,16 +67,33 @@ pub fn mem_load_bar(bar_len: i32, config: &config::Config) {
|
||||
config.mid_threshold,
|
||||
config,
|
||||
);
|
||||
|
||||
// Show: used/free
|
||||
print!(
|
||||
"{}B #[default]",
|
||||
SizeFormatterBinary::new((memory.avail * 1024) as u64)
|
||||
"{}/{} #[default]",
|
||||
SizeFormatterBinary::new(actual_used),
|
||||
SizeFormatterBinary::new(actual_free)
|
||||
);
|
||||
}
|
||||
|
||||
pub fn cpu_load_bar(bar_len: i32, config: &config::Config) {
|
||||
let cpu_count = sys_info::cpu_num().expect("Failed to get cpu_num");
|
||||
let la_one = sys_info::loadavg().expect("Failed to get loadavg").one;
|
||||
let len = (la_one / cpu_count as f64 * bar_len as f64).round() as i32;
|
||||
let mut sys = System::new_all();
|
||||
|
||||
// Update CPU information
|
||||
sys.refresh_cpu_all();
|
||||
|
||||
// Wait a bit to get accurate CPU usage data
|
||||
thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);
|
||||
sys.refresh_cpu_all();
|
||||
|
||||
let cpu_count = sys.cpus().len();
|
||||
|
||||
// Get average CPU usage
|
||||
let cpu_usage: f32 = sys.cpus().iter().map(|cpu| cpu.cpu_usage()).sum::<f32>() / cpu_count as f32;
|
||||
let cpu_load_ratio = cpu_usage / 100.0; // sysinfo returns percentages
|
||||
|
||||
let len = (cpu_load_ratio * bar_len as f32).round() as i32;
|
||||
|
||||
to_bar(
|
||||
len,
|
||||
bar_len,
|
||||
@@ -67,7 +102,7 @@ pub fn cpu_load_bar(bar_len: i32, config: &config::Config) {
|
||||
config,
|
||||
);
|
||||
|
||||
print!("{:.2} LA1#[default]", la_one);
|
||||
print!("{:.1}%#[default]", cpu_usage);
|
||||
}
|
||||
|
||||
pub fn get_player() -> Result<Vec<String>, Box<dyn std::error::Error>> {
|
||||
|
||||
Reference in New Issue
Block a user