aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Lawrence <scott+git@ineffectivetheory.com>2024-11-28 11:54:01 -0700
committerScott Lawrence <scott+git@ineffectivetheory.com>2024-11-28 11:54:01 -0700
commit027cd739765ba7bde027c32df2e2246314df9e88 (patch)
tree57984ec7db478298d152a2270e8f650e30ebac1e
parent31926e63a3764ceaafbcb35e85254c0c0adde1a6 (diff)
downloadvaranus-027cd739765ba7bde027c32df2e2246314df9e88.tar.gz
varanus-027cd739765ba7bde027c32df2e2246314df9e88.tar.bz2
varanus-027cd739765ba7bde027c32df2e2246314df9e88.zip
Printing out memory used
-rw-r--r--src/main.rs44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 053bf09..2a72d18 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -24,6 +24,10 @@
*
* Forecast
*
+ * Installation / packaging
+ *
+ * Desktop display (a la conky?)
+ *
*/
use std::error;
@@ -89,7 +93,7 @@ struct Cli {
delay: f64,
#[arg(short='s', long, default_value="varanus.sock")]
socket: String,
- #[arg(short='f', long)]
+ #[arg(short='f', long, default_value="")]
format: String,
#[arg(long)]
power: bool,
@@ -278,6 +282,33 @@ impl Drop for Listener {
}
}
+fn human(k: u64) -> String {
+ let mut x: f64 = k as f64;
+ let mut i = 0;
+ let cs = ["", "K", "M", "G", "T", "P"];
+ while x >= 1000. && i < cs.len() {
+ x /= 1000.;
+ i += 1;
+ }
+ let c = cs[i];
+ format!("{x:.1}{c}")
+}
+
+fn display_power(state: &State) {
+}
+
+fn display_memory(state: &State) {
+ let mem = &state.memory;
+ let fs = human(mem.free);
+ let us = human(mem.total - mem.free);
+ let ts = human(mem.total);
+ let per = 100. * (mem.total - mem.free) as f64 / mem.total as f64;
+ println!("Memory used: {us} / {ts} ({per:.0}%)")
+}
+
+fn format(fmt: &str, state: &State) {
+}
+
fn main() {
let args = Cli::parse();
if args.daemon {
@@ -301,7 +332,16 @@ fn main() {
} else {
match get_state(args.socket.clone()) {
Ok(state) => {
- println!("{:#?}", state)
+ if args.power {
+ display_power(&state);
+ }
+ if args.memory {
+ display_memory(&state);
+ }
+ if args.format.len() > 0 {
+ format(&args.format, &state);
+ }
+ //println!("{:#?}", state)
},
Err(_) => eprintln!("Couldn't open {}", &args.socket)
}