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 | |
|---|---|---|---|
|
|
7f62bcf55e | ||
|
|
a420204e5d | ||
|
|
b5db03203c | ||
|
|
d9b5643ae5 |
@@ -6,7 +6,7 @@ authors = ["Ultra Desu <ultradesu@hexor.ru>"]
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sys-info = "0.9"
|
sysinfo = "0.36.0"
|
||||||
dbus = "0.9"
|
dbus = "0.9"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
mpd = "0.1"
|
mpd = "0.1"
|
||||||
|
|||||||
70
README.md
70
README.md
@@ -1,7 +1,8 @@
|
|||||||
# Tmux helper
|
# 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
|
### Building
|
||||||
`cargo build --release`
|
`cargo build --release`
|
||||||
@@ -9,31 +10,50 @@ or get binary on release page
|
|||||||
|
|
||||||
### Fetures
|
### Fetures
|
||||||
```shell
|
```shell
|
||||||
tmux-helper 0.3.2
|
|
||||||
Ultra Desu <ultradesu@hexor.ru>
|
|
||||||
Utility for printing system info for tmux status line.
|
Utility for printing system info for tmux status line.
|
||||||
|
|
||||||
USAGE:
|
Usage: tmux-helper [OPTIONS]
|
||||||
tmux-helper [FLAGS] [OPTIONS]
|
|
||||||
|
|
||||||
FLAGS:
|
Options:
|
||||||
-c, --cpu Print cpu load bar.
|
-c, --cpu
|
||||||
-h, --help Prints help information
|
Print cpu load bar.
|
||||||
-m, --mem Print mem usage bar.
|
-m, --mem
|
||||||
-d, --mpd Show mpd player using MPD native protocol.
|
Print mem usage bar.
|
||||||
-p, --mpris Show player info using MPRIS2 interface.
|
--low <low>
|
||||||
-V, --version Prints version information
|
Low threshold (0.0 - 1.0) [default: 0.7]
|
||||||
|
--mid <mid>
|
||||||
OPTIONS:
|
Mid threshold (0.0 - 1.0) [default: 0.9]
|
||||||
--COLOR_END <COLOR_END> Default color using to terminate others.
|
-p, --mpris
|
||||||
--COLOR_HIGH <COLOR_HIGH> CPU and MEM bar color while high usage.
|
Show player info using MPRIS2 interface.
|
||||||
--COLOR_LOW <COLOR_LOW> CPU and MEM bar color while low usage.
|
-d, --mpd
|
||||||
--COLOR_MID <COLOR_MID> CPU and MEM bar color while mid usage.
|
Show mpd player using MPD native protocol.
|
||||||
--COLOR_TRACK_ARTIST <COLOR_TRACK_ARTIST> Color of artist name filed.
|
-l, --localtime [<localtime>]
|
||||||
--COLOR_TRACK_NAME <COLOR_TRACK_NAME> Color of track name filed.
|
Local time
|
||||||
--COLOR_TRACK_TIME <COLOR_TRACK_TIME> Color of playing time field.
|
-u, --utctime [<utctime>]
|
||||||
-l, --localtime <localtime> Local time
|
UTC time
|
||||||
-a, --mpd-address <mpd_address> <ADDR>:<PORT> of MPD server.
|
-s, --symbol [<bar_symbol>]
|
||||||
-u, --utctime <utctime> UTC time
|
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 mpd::Client;
|
||||||
use size_format::SizeFormatterBinary;
|
use size_format::SizeFormatterBinary;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use sys_info;
|
use sysinfo::System;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TrackInfo {
|
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) {
|
pub fn mem_load_bar(bar_len: i32, config: &config::Config) {
|
||||||
let memory = sys_info::mem_info().expect("Failed to get mem_info");
|
let mut sys = System::new_all();
|
||||||
let used_ratio = (memory.total - memory.avail) as f32 / memory.total as f32;
|
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;
|
let len = (used_ratio * bar_len as f32) as i32;
|
||||||
|
|
||||||
to_bar(
|
to_bar(
|
||||||
len,
|
len,
|
||||||
bar_len,
|
bar_len,
|
||||||
@@ -49,16 +67,33 @@ pub fn mem_load_bar(bar_len: i32, config: &config::Config) {
|
|||||||
config.mid_threshold,
|
config.mid_threshold,
|
||||||
config,
|
config,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Show: used/free
|
||||||
print!(
|
print!(
|
||||||
"{}B #[default]",
|
"{}/{} #[default]",
|
||||||
SizeFormatterBinary::new((memory.avail * 1024) as u64)
|
SizeFormatterBinary::new(actual_used),
|
||||||
|
SizeFormatterBinary::new(actual_free)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cpu_load_bar(bar_len: i32, config: &config::Config) {
|
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 mut sys = System::new_all();
|
||||||
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;
|
// 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(
|
to_bar(
|
||||||
len,
|
len,
|
||||||
bar_len,
|
bar_len,
|
||||||
@@ -67,7 +102,7 @@ pub fn cpu_load_bar(bar_len: i32, config: &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>> {
|
pub fn get_player() -> Result<Vec<String>, Box<dyn std::error::Error>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user