diff --git a/Cargo.lock b/Cargo.lock index 102fe09..95764c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -832,8 +832,7 @@ dependencies = [ [[package]] name = "libmacchina" version = "8.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80a723e0a76ac2da702ac67c4a3f26306ba9229d1dc2571266e781648c30528e" +source = "git+https://github.com/Macchina-CLI/libmacchina#a7d5001a65a98d5c9567958f3ab54f60e0b4d0ee" dependencies = [ "cfg-if 1.0.0", "core-foundation 0.9.4", diff --git a/Cargo.toml b/Cargo.toml index 8d21e8c..ba5e898 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" build = "build.rs" [dependencies] -libmacchina = { version = "8.0.0", features = ["version"] } +libmacchina = { git = "https://github.com/Macchina-CLI/libmacchina", features = ["version"] } bytesize = "1.3.0" shellexpand = "3.1.0" clap = { version = "4.4.6", features = ["derive"] } diff --git a/src/data/mod.rs b/src/data/mod.rs index bb858a4..05ae5d4 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -33,6 +33,7 @@ pub enum ReadoutKey { Processor, ProcessorLoad, Memory, + Swap, Battery, GPU, DiskSpace, @@ -58,6 +59,7 @@ impl Display for ReadoutKey { Self::Processor => write!(f, "Processor"), Self::ProcessorLoad => write!(f, "ProcessorLoad"), Self::Memory => write!(f, "Memory"), + Self::Swap => write!(f, "Swap"), Self::Battery => write!(f, "Battery"), Self::GPU => write!(f, "GPU"), Self::DiskSpace => write!(f, "DiskSpace"), @@ -188,6 +190,7 @@ pub fn get_all_readouts<'a>( handle_readout_processor_load(&mut readout_values, &general_readout, theme) } ReadoutKey::Memory => handle_readout_memory(&mut readout_values, theme, opt), + ReadoutKey::Swap => handle_readout_swap(&mut readout_values, theme, opt), ReadoutKey::Battery => handle_readout_battery(&mut readout_values, theme), ReadoutKey::DesktopEnvironment => { handle_readout_desktop_environment(&mut readout_values, &general_readout) @@ -426,6 +429,30 @@ fn handle_readout_memory(readout_values: &mut Vec, theme: &Theme, opt: } } +fn handle_readout_swap(readout_values: &mut Vec, theme: &Theme, opt: &Opt) { + use crate::format::memory as format_mem; + use libmacchina::traits::MemoryReadout as _; + + let memory_readout = MemoryReadout::new(); + let total = memory_readout.swap_total(); + let used = memory_readout.swap_used(); + + match (total, used) { + (Ok(total), Ok(used)) => { + if theme.get_bar().is_visible() { + let bar = create_bar(theme, crate::bars::usage(used, total)); + readout_values.push(Readout::new(ReadoutKey::Swap, bar)) + } else { + readout_values.push(Readout::new( + ReadoutKey::Swap, + format_mem(total, used, opt.memory_percentage), + )) + } + } + (Err(e), _) | (_, Err(e)) => readout_values.push(Readout::new_err(ReadoutKey::Swap, e)), + } +} + fn handle_readout_battery(readout_values: &mut Vec, theme: &Theme) { use crate::format::battery as format_bat; use libmacchina::traits::BatteryReadout as _; diff --git a/src/theme/base.rs b/src/theme/base.rs index d29246d..9c809ac 100644 --- a/src/theme/base.rs +++ b/src/theme/base.rs @@ -216,6 +216,7 @@ impl Theme { ReadoutKey::Backlight => self.keys.get_backlight(), ReadoutKey::Uptime => self.keys.get_uptime(), ReadoutKey::Memory => self.keys.get_memory(), + ReadoutKey::Swap => self.keys.get_swap(), ReadoutKey::GPU => self.keys.get_gpu(), ReadoutKey::DiskSpace => self.keys.get_disk_space(), } diff --git a/src/theme/components.rs b/src/theme/components.rs index d95a43a..e515a69 100644 --- a/src/theme/components.rs +++ b/src/theme/components.rs @@ -303,6 +303,7 @@ pub struct Keys { pub packages: Option, pub uptime: Option, pub memory: Option, + pub swap: Option, pub machine: Option, pub local_ip: Option, pub backlight: Option, @@ -328,6 +329,7 @@ impl Default for Keys { packages: Some(String::from("Packages")), uptime: Some(String::from("Uptime")), memory: Some(String::from("Memory")), + swap: Some(String::from("Swap")), machine: Some(String::from("Machine")), local_ip: Some(String::from("Local IP")), backlight: Some(String::from("Brightness")), @@ -437,6 +439,14 @@ impl Keys { "Memory" } + pub fn get_swap(&self) -> &str { + if let Some(m) = &self.swap { + return m; + } + + "Swap" + } + pub fn get_machine(&self) -> &str { if let Some(m) = &self.machine { return m;