From d27ab9a9176ba1d21d364b26e70c734d35266249 Mon Sep 17 00:00:00 2001 From: Atsukoro1 Date: Thu, 1 Dec 2022 11:32:32 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Ram=20working?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/system/specs.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) 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