From 8234145bf250f7bfb4dd06ef1c9f5543c4bace8e Mon Sep 17 00:00:00 2001 From: druskus20 Date: Sat, 21 Aug 2021 18:30:06 +0200 Subject: [PATCH 1/9] Renamed system stat functions --- crates/eww/src/config/inbuilt.rs | 8 ++++---- crates/eww/src/config/system_stats.rs | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/eww/src/config/inbuilt.rs b/crates/eww/src/config/inbuilt.rs index c2c4b50..343ac1f 100644 --- a/crates/eww/src/config/inbuilt.rs +++ b/crates/eww/src/config/inbuilt.rs @@ -23,13 +23,13 @@ macro_rules! builtin_vars { pub fn get_inbuilt_vars() -> HashMap { builtin_vars! {Duration::new(2, 0), // @desc EWW_TEMPS - Heat of the components in Celcius\nExample: `{(CPU_TEMPS.core_1 + CPU_TEMPS.core_2) / 2}` - "EWW_TEMPS" => || Ok(DynVal::from(cores())), + "EWW_TEMPS" => || Ok(DynVal::from(get_core_temperatures())), // @desc EWW_RAM - The current RAM + Swap usage - "EWW_RAM" => || Ok(DynVal::from(format!("{:.2}", ram()))), + "EWW_RAM" => || Ok(DynVal::from(format!("{:.2}", get_ram()))), // @desc EWW_DISK - Information on on all mounted partitions (Might report inaccurately on some filesystems, like btrfs)\nExample: `{EWW_DISK["/"]}` - "EWW_DISK" => || Ok(DynVal::from(disk())), + "EWW_DISK" => || Ok(DynVal::from(get_disks())), // @desc EWW_BATTERY - Battery capacity in procent of the main battery "EWW_BATTERY" => || Ok(DynVal::from( @@ -43,7 +43,7 @@ pub fn get_inbuilt_vars() -> HashMap { )), // @desc EWW_CPU_USAGE - Average CPU usage (all cores) since the last update (No MacOS support) - "EWW_CPU_USAGE" => || Ok(DynVal::from(get_avg_cpu_usage())), + "EWW_CPU_USAGE" => || Ok(DynVal::from(get_cpus())), // @desc EWW_NET - Bytes up/down on all interfaces "EWW_NET" => || Ok(DynVal::from(net())), diff --git a/crates/eww/src/config/system_stats.rs b/crates/eww/src/config/system_stats.rs index 1ddb4e4..a0d7b63 100644 --- a/crates/eww/src/config/system_stats.rs +++ b/crates/eww/src/config/system_stats.rs @@ -7,7 +7,7 @@ use sysinfo::{ComponentExt, DiskExt, NetworkExt, NetworksExt, ProcessorExt, Syst static SYSTEM: Lazy> = Lazy::new(|| Mutex::new(System::new())); -pub fn disk() -> String { +pub fn get_disks() -> String { let mut c = SYSTEM.lock().unwrap(); c.refresh_disks_list(); @@ -26,13 +26,13 @@ pub fn disk() -> String { ) } -pub fn ram() -> f32 { +pub fn get_ram() -> f32 { let mut c = SYSTEM.lock().unwrap(); c.refresh_memory(); (c.get_used_memory() as f32 + c.get_used_swap() as f32) / 1_000_000f32 } -pub fn cores() -> String { +pub fn get_core_temperatures() -> String { let mut c = SYSTEM.lock().unwrap(); c.refresh_components_list(); c.refresh_components(); @@ -45,7 +45,7 @@ pub fn cores() -> String { ) } -pub fn get_avg_cpu_usage() -> String { +pub fn get_cpus() -> String { let mut c = SYSTEM.lock().unwrap(); c.refresh_cpu(); let processors = c.get_processors(); @@ -133,7 +133,7 @@ pub fn get_battery_capacity() -> Result { #[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "linux"))] pub fn get_battery_capacity() -> Result { - anyhow!("eww doesn't support your OS for getting the battery capacity") + anyhow!("Eww doesn't support your OS for getting the battery capacity") } pub fn net() -> String { From 4c9315a016329fc0c1ca8416ec0e586f780841dc Mon Sep 17 00:00:00 2001 From: druskus20 Date: Sat, 21 Aug 2021 19:12:28 +0200 Subject: [PATCH 2/9] Adding more memory data to EWW_RAM as json fields --- crates/eww/src/config/inbuilt.rs | 2 +- crates/eww/src/config/system_stats.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/eww/src/config/inbuilt.rs b/crates/eww/src/config/inbuilt.rs index 343ac1f..c1cfcbb 100644 --- a/crates/eww/src/config/inbuilt.rs +++ b/crates/eww/src/config/inbuilt.rs @@ -26,7 +26,7 @@ pub fn get_inbuilt_vars() -> HashMap { "EWW_TEMPS" => || Ok(DynVal::from(get_core_temperatures())), // @desc EWW_RAM - The current RAM + Swap usage - "EWW_RAM" => || Ok(DynVal::from(format!("{:.2}", get_ram()))), + "EWW_RAM" => || Ok(DynVal::from(get_ram())), // @desc EWW_DISK - Information on on all mounted partitions (Might report inaccurately on some filesystems, like btrfs)\nExample: `{EWW_DISK["/"]}` "EWW_DISK" => || Ok(DynVal::from(get_disks())), diff --git a/crates/eww/src/config/system_stats.rs b/crates/eww/src/config/system_stats.rs index a0d7b63..f500904 100644 --- a/crates/eww/src/config/system_stats.rs +++ b/crates/eww/src/config/system_stats.rs @@ -26,10 +26,18 @@ pub fn get_disks() -> String { ) } -pub fn get_ram() -> f32 { +pub fn get_ram() -> String { let mut c = SYSTEM.lock().unwrap(); c.refresh_memory(); - (c.get_used_memory() as f32 + c.get_used_swap() as f32) / 1_000_000f32 + format!( + r#"{{"total_mem": {}, "free_mem": {}, "total_swap": {}, "free_swap": {}, "available_mem": {}, "used_mem": {}}}"#, + c.get_total_memory(), + c.get_free_memory(), + c.get_total_swap(), + c.get_free_swap(), + c.get_available_memory(), + c.get_used_memory(), + ) } pub fn get_core_temperatures() -> String { From 86dce341ac80784c0d85cb5f6599e0643776abe2 Mon Sep 17 00:00:00 2001 From: druskus20 Date: Sat, 21 Aug 2021 19:55:04 +0200 Subject: [PATCH 3/9] Updated the docs, renamed EWW_CPU_USAGE to EWW_CPU --- crates/eww/src/config/inbuilt.rs | 18 +++++++++++++----- crates/eww/src/config/system_stats.rs | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/eww/src/config/inbuilt.rs b/crates/eww/src/config/inbuilt.rs index c1cfcbb..8d489d8 100644 --- a/crates/eww/src/config/inbuilt.rs +++ b/crates/eww/src/config/inbuilt.rs @@ -22,10 +22,10 @@ macro_rules! builtin_vars { pub fn get_inbuilt_vars() -> HashMap { builtin_vars! {Duration::new(2, 0), - // @desc EWW_TEMPS - Heat of the components in Celcius\nExample: `{(CPU_TEMPS.core_1 + CPU_TEMPS.core_2) / 2}` - "EWW_TEMPS" => || Ok(DynVal::from(get_core_temperatures())), + // @desc EWW_TEMPS - Heat of the components in Celcius + "EWW_TEMPS" => || Ok(DynVal::from(get_temperatures())), - // @desc EWW_RAM - The current RAM + Swap usage + // @desc EWW_RAM - Information on ram and swap usage in kB. "EWW_RAM" => || Ok(DynVal::from(get_ram())), // @desc EWW_DISK - Information on on all mounted partitions (Might report inaccurately on some filesystems, like btrfs)\nExample: `{EWW_DISK["/"]}` @@ -42,8 +42,16 @@ pub fn get_inbuilt_vars() -> HashMap { } )), - // @desc EWW_CPU_USAGE - Average CPU usage (all cores) since the last update (No MacOS support) - "EWW_CPU_USAGE" => || Ok(DynVal::from(get_cpus())), + // @desc EWW_CPU - Information on the CPU cores: frequency and usage (No MacOS support) + "EWW_CPU" => || Ok(DynVal::from(get_cpus())), + + // TODO: Change this eventually, maybe implement an error system + // @desc EWW_CPU_USAGE - Outdated, use `EWW_CPU` instead + "EWW_CPU_USAGE" => { + log::warn!("EWW_CPU_BATTERY is deprecated, use EWW_CPU instead"); + || Ok(DynVal::from(get_cpus())) + }, + // @desc EWW_NET - Bytes up/down on all interfaces "EWW_NET" => || Ok(DynVal::from(net())), diff --git a/crates/eww/src/config/system_stats.rs b/crates/eww/src/config/system_stats.rs index f500904..8b8d7a7 100644 --- a/crates/eww/src/config/system_stats.rs +++ b/crates/eww/src/config/system_stats.rs @@ -40,7 +40,7 @@ pub fn get_ram() -> String { ) } -pub fn get_core_temperatures() -> String { +pub fn get_temperatures() -> String { let mut c = SYSTEM.lock().unwrap(); c.refresh_components_list(); c.refresh_components(); From 5ca6ba03c41ad04b3104cb3ae6647aecc37d570a Mon Sep 17 00:00:00 2001 From: druskus20 Date: Mon, 23 Aug 2021 00:06:45 +0200 Subject: [PATCH 4/9] Added used space to EWW_DISK --- crates/eww/src/config/system_stats.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/eww/src/config/system_stats.rs b/crates/eww/src/config/system_stats.rs index 8b8d7a7..1c92c1d 100644 --- a/crates/eww/src/config/system_stats.rs +++ b/crates/eww/src/config/system_stats.rs @@ -15,13 +15,18 @@ pub fn get_disks() -> String { "{{ {} }}", c.get_disks() .iter() - .map(|c| format!( - r#""{}": {{"name": {:?}, "total": {}, "free": {}}}"#, - c.get_mount_point().display(), - c.get_name(), - c.get_total_space(), - c.get_available_space(), - )) + .map(|c| { + let total_space = c.get_total_space(); + let available_space = c.get_available_space(); + format!( + r#""{}": {{"name": {:?}, "total": {}, "free": {}, "used": {}}}"#, + c.get_mount_point().display(), + c.get_name(), + total_space, + available_space, + total_space - available_space, + ) + }) .join(",") ) } From 905118f61269457afb235a3157a01d3bf2037abb Mon Sep 17 00:00:00 2001 From: druskus20 Date: Tue, 24 Aug 2021 13:39:04 +0200 Subject: [PATCH 5/9] Added % used ram to EWW_RAM --- crates/eww/src/config/system_stats.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/eww/src/config/system_stats.rs b/crates/eww/src/config/system_stats.rs index 1c92c1d..d22de91 100644 --- a/crates/eww/src/config/system_stats.rs +++ b/crates/eww/src/config/system_stats.rs @@ -34,14 +34,18 @@ pub fn get_disks() -> String { pub fn get_ram() -> String { let mut c = SYSTEM.lock().unwrap(); c.refresh_memory(); + + let total_memory = c.get_total_memory(); + let used_memory = c.get_used_memory(); format!( - r#"{{"total_mem": {}, "free_mem": {}, "total_swap": {}, "free_swap": {}, "available_mem": {}, "used_mem": {}}}"#, - c.get_total_memory(), + r#"{{"total_mem": {}, "free_mem": {}, "total_swap": {}, "free_swap": {}, "available_mem": {}, "used_mem": {}, "used_mem_perc": {}}}"#, + total_memory, c.get_free_memory(), c.get_total_swap(), c.get_free_swap(), c.get_available_memory(), - c.get_used_memory(), + used_memory, + used_memory / total_memory, ) } @@ -66,7 +70,12 @@ pub fn get_cpus() -> String { r#"{{ "cores": [{}], "avg": {} }}"#, processors .iter() - .map(|a| format!(r#"{{"core": "{}", "freq": {}, "usage": {}}}"#, a.get_name(), a.get_frequency(), a.get_cpu_usage())) + .map(|a| format!( + r#"{{"core": "{}", "freq": {}, "usage": {:.0}}}"#, + a.get_name(), + a.get_frequency(), + a.get_cpu_usage() + )) .join(","), processors.iter().map(|a| a.get_cpu_usage()).avg() ) From d216e8a723bca8b1f60978756bfaeebce444088f Mon Sep 17 00:00:00 2001 From: druskus20 Date: Tue, 24 Aug 2021 22:37:53 +0200 Subject: [PATCH 6/9] EWW_NET fixed null interface error --- crates/eww/src/config/system_stats.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eww/src/config/system_stats.rs b/crates/eww/src/config/system_stats.rs index d22de91..93209db 100644 --- a/crates/eww/src/config/system_stats.rs +++ b/crates/eww/src/config/system_stats.rs @@ -160,6 +160,7 @@ pub fn get_battery_capacity() -> Result { pub fn net() -> String { let mut c = SYSTEM.lock().unwrap(); + c.refresh_networks_list(); let interfaces = format!( "{{ {} }}", &c.get_networks() @@ -167,6 +168,5 @@ pub fn net() -> String { .map(|a| format!(r#""{}": {{ "NET_UP": {}, "NET_DOWN": {} }}"#, a.0, a.1.get_transmitted(), a.1.get_received())) .join(","), ); - c.refresh_networks_list(); interfaces } From 0a71f3ccf8a663b10e264acb85fc69cfd9c9f5f3 Mon Sep 17 00:00:00 2001 From: druskus20 Date: Thu, 26 Aug 2021 01:38:00 +0200 Subject: [PATCH 7/9] This is now, how one calculates percentages --- crates/eww/src/config/system_stats.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/eww/src/config/system_stats.rs b/crates/eww/src/config/system_stats.rs index 93209db..bce96fc 100644 --- a/crates/eww/src/config/system_stats.rs +++ b/crates/eww/src/config/system_stats.rs @@ -18,13 +18,15 @@ pub fn get_disks() -> String { .map(|c| { let total_space = c.get_total_space(); let available_space = c.get_available_space(); + let used_space = total_space - available_space; format!( - r#""{}": {{"name": {:?}, "total": {}, "free": {}, "used": {}}}"#, + r#""{}": {{"name": {:?}, "total": {}, "free": {}, "used": {}, "used_perc": {}}}"#, c.get_mount_point().display(), c.get_name(), total_space, available_space, - total_space - available_space, + used_space, + used_space / total_space, ) }) .join(",") @@ -45,7 +47,7 @@ pub fn get_ram() -> String { c.get_free_swap(), c.get_available_memory(), used_memory, - used_memory / total_memory, + (used_memory / total_memory) * 100, ) } From fb2bff513749ffb780fc9b238bd6201349a5ea60 Mon Sep 17 00:00:00 2001 From: druskus20 Date: Thu, 26 Aug 2021 02:26:40 +0200 Subject: [PATCH 8/9] Deprecation warning for EWW_CPU_USAGE --- crates/eww/src/config/inbuilt.rs | 8 -------- crates/yuck/src/format_diagnostic.rs | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/eww/src/config/inbuilt.rs b/crates/eww/src/config/inbuilt.rs index 8d489d8..7f0a668 100644 --- a/crates/eww/src/config/inbuilt.rs +++ b/crates/eww/src/config/inbuilt.rs @@ -45,14 +45,6 @@ pub fn get_inbuilt_vars() -> HashMap { // @desc EWW_CPU - Information on the CPU cores: frequency and usage (No MacOS support) "EWW_CPU" => || Ok(DynVal::from(get_cpus())), - // TODO: Change this eventually, maybe implement an error system - // @desc EWW_CPU_USAGE - Outdated, use `EWW_CPU` instead - "EWW_CPU_USAGE" => { - log::warn!("EWW_CPU_BATTERY is deprecated, use EWW_CPU instead"); - || Ok(DynVal::from(get_cpus())) - }, - - // @desc EWW_NET - Bytes up/down on all interfaces "EWW_NET" => || Ok(DynVal::from(net())), } diff --git a/crates/yuck/src/format_diagnostic.rs b/crates/yuck/src/format_diagnostic.rs index d3b0ae4..b6a28c1 100644 --- a/crates/yuck/src/format_diagnostic.rs +++ b/crates/yuck/src/format_diagnostic.rs @@ -184,15 +184,25 @@ impl ToDiagnostic for ValidationError { "Hint: Define it as a global variable" } }; - diag.with_notes(vec![format!( - "Hint: If you meant to use the literal value \"{}\", surround the value in quotes", - name - )]) + + let mut extra_notes = + vec![format!("Hint: If you meant to use the literal value \"{}\", surround the value in quotes", name)]; + + if let Some(deprecation_note) = variable_deprecation_note(name.to_string()) { + extra_notes.push(deprecation_note) + }; + + diag.with_notes(extra_notes) } } } } +fn variable_deprecation_note(var_name: String) -> Option { + (var_name == "EWW_CPU_USAGE") + .then(|| "Note: EWW_CPU_USAGE has recently been removed, and has now been renamed to EWW_CPU".to_string()) +} + fn lalrpop_error_to_diagnostic( error: &lalrpop_util::ParseError, file_id: usize, From 6ad999f2995bd7cfa3d5897e797866abe6d54734 Mon Sep 17 00:00:00 2001 From: druskus20 Date: Thu, 26 Aug 2021 02:27:43 +0200 Subject: [PATCH 9/9] Fixed percentages and ram usage --- crates/eww/src/config/system_stats.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/eww/src/config/system_stats.rs b/crates/eww/src/config/system_stats.rs index bce96fc..fd322a5 100644 --- a/crates/eww/src/config/system_stats.rs +++ b/crates/eww/src/config/system_stats.rs @@ -26,7 +26,7 @@ pub fn get_disks() -> String { total_space, available_space, used_space, - used_space / total_space, + (used_space as f32 / total_space as f32) * 100f32, ) }) .join(",") @@ -38,16 +38,17 @@ pub fn get_ram() -> String { c.refresh_memory(); let total_memory = c.get_total_memory(); - let used_memory = c.get_used_memory(); + let available_memory = c.get_available_memory(); + let used_memory = total_memory as f32 - available_memory as f32; format!( r#"{{"total_mem": {}, "free_mem": {}, "total_swap": {}, "free_swap": {}, "available_mem": {}, "used_mem": {}, "used_mem_perc": {}}}"#, total_memory, c.get_free_memory(), c.get_total_swap(), c.get_free_swap(), - c.get_available_memory(), + available_memory, used_memory, - (used_memory / total_memory) * 100, + (used_memory / total_memory as f32) * 100f32, ) }