mirror of
https://github.com/house-of-vanity/tmux-helper.git
synced 2026-02-04 09:47:59 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1e418a633 | ||
|
|
8e569078de |
43
src/main.rs
43
src/main.rs
@@ -2,18 +2,18 @@ extern crate chrono;
|
||||
extern crate dbus;
|
||||
|
||||
use crate::dbus::blocking::stdintf::org_freedesktop_dbus::Properties;
|
||||
use chrono::{DateTime, FixedOffset, Local, Utc};
|
||||
use chrono::{DateTime, Local, Utc};
|
||||
use dbus::{arg, blocking::Connection};
|
||||
use std::{env, fs, time::Duration};
|
||||
use std::{env, time::Duration};
|
||||
use sys_info;
|
||||
|
||||
const LOW: &str = "#[fg=colour2]";
|
||||
const MID: &str = "#[fg=colour3]";
|
||||
const HIGH: &str = "#[fg=colour1]";
|
||||
const END: &str = "#[fg=colour7]";
|
||||
const TRACK_NAME: &str = "#[fg=colour3]";
|
||||
const TRACK_ARTIST: &str = "#[fg=colour3]";
|
||||
const TRACK_TIME: &str = "#[bg=colour252 fg=colour235 bold]";
|
||||
const LOW: &str = "#[fg=colour119]";
|
||||
const MID: &str = "#[fg=colour220]";
|
||||
const HIGH: &str = "#[fg=colour197]";
|
||||
const END: &str = "#[fg=colour153]";
|
||||
const TRACK_NAME: &str = "#[fg=colour46]";
|
||||
const TRACK_ARTIST: &str = "#[fg=colour46]";
|
||||
const TRACK_TIME: &str = "#[fg=colour153]";
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct TrackInfo {
|
||||
@@ -24,10 +24,6 @@ struct TrackInfo {
|
||||
status: String,
|
||||
}
|
||||
|
||||
fn read_file(file_path: &str) -> String {
|
||||
fs::read_to_string(file_path).expect("Cant read file.")
|
||||
}
|
||||
|
||||
fn to_bar(value: i32, max: i32, low: f32, mid: f32) {
|
||||
let mut bar = "".to_string();
|
||||
let bar_sym = "▮".to_string();
|
||||
@@ -59,18 +55,21 @@ fn mem_load_bar(bar_len: i32) {
|
||||
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);
|
||||
print!("{:.0} MiB", memory.avail / 1024);
|
||||
print!("{:.0} MiB#[default]", memory.avail / 1024);
|
||||
}
|
||||
|
||||
fn cpu_load_bar(bar_len: i32) {
|
||||
let load = read_file("/proc/loadavg");
|
||||
let load_data = load.split_whitespace().collect::<Vec<&str>>();
|
||||
let _cpu_count = read_file("/proc/cpuinfo");
|
||||
let cpu_count = _cpu_count.matches("model name").count();
|
||||
let one: f32 = load_data[0].parse().unwrap();
|
||||
let len: f32 = one as f32 / cpu_count as f32 * bar_len as f32;
|
||||
let cpu_count = match sys_info::cpu_num() {
|
||||
Ok(c) => c,
|
||||
Err(e) => panic!("{:?}", e),
|
||||
};
|
||||
let la_one: f32 = match sys_info::loadavg() {
|
||||
Ok(l) => l.one as f32,
|
||||
Err(e) => panic!("{:?}", e),
|
||||
};
|
||||
let len: f32 = la_one as f32 / cpu_count as f32 * bar_len as f32;
|
||||
to_bar(len as i32, bar_len, 0.3, 0.7);
|
||||
print!("{:.2} LA1", one);
|
||||
print!("{:.2} LA1#[default]", la_one);
|
||||
}
|
||||
|
||||
fn get_player() -> Result<Vec<String>, Box<dyn std::error::Error>> {
|
||||
@@ -226,7 +225,7 @@ fn main() {
|
||||
track_info.title = title;
|
||||
}
|
||||
println!(
|
||||
"#[none]#[bold]{}{}{}#[none]{}{}{}{} {}[{}/{}] {} {}",
|
||||
"#[none]#[bold]{}{}{}#[none]{}{}{}{} {}[{}/{}] {} {}#[default]",
|
||||
TRACK_NAME,
|
||||
track_info.title,
|
||||
END,
|
||||
|
||||
Reference in New Issue
Block a user