diff --git a/src/system/specs.rs b/src/system/specs.rs index fbba0e3..6e44926 100644 --- a/src/system/specs.rs +++ b/src/system/specs.rs @@ -1,6 +1,6 @@ -use std::sync::Mutex; use std::fs::File; use std::io::Read; +use std::ops::Add; use std::rc::Rc; #[cfg(target_os = "linux")] @@ -28,9 +28,6 @@ pub fn get_cpu() -> String { #[cfg(target_os = "linux")] pub fn get_ram_used() -> String { - use std::ops::Add; - - let mut ram: Mutex = Mutex::new(String::new()); let mut temp_buf: String = String::new(); let mut file = File::open("/proc/meminfo").unwrap(); @@ -38,20 +35,26 @@ pub fn get_ram_used() -> String { let lines: &Vec<&str> = &temp_buf.lines().collect(); + let mut total: u128 = 0; + let mut available: u128 = 0; + lines.into_iter().for_each(|line| { - ram.get_mut().unwrap().add("fdlkj"); if line.contains("MemTotal") { - + total = eval_ram(line.to_string()); } else if line.contains("MemAvailable") { - + available = eval_ram(line.to_string()); } }); - let x = ram.lock().unwrap().to_string(); x + format!( + "{}M / {}M", + total - available, + total + ) } #[cfg(target_os = "linux")] -fn eval_ram(line: String) -> String { +fn eval_ram(line: String) -> u128 { let kbs: u128 = line.split(":") .collect::>()[1].to_string() .replace("\t", "") @@ -60,5 +63,5 @@ fn eval_ram(line: String) -> String { .parse::() .unwrap(); - (kbs / 1024).to_string() + (kbs / 1000) } \ No newline at end of file