mirror of
https://github.com/Atsukoro1/ponyfetch.git
synced 2024-11-27 14:28:00 +01:00
feat: 🎸 Ram working
This commit is contained in:
parent
628c5e6125
commit
d27ab9a917
1 changed files with 13 additions and 10 deletions
|
@ -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<String> = 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::<Vec<&str>>()[1].to_string()
|
||||
.replace("\t", "")
|
||||
|
@ -60,5 +63,5 @@ fn eval_ram(line: String) -> String {
|
|||
.parse::<u128>()
|
||||
.unwrap();
|
||||
|
||||
(kbs / 1024).to_string()
|
||||
(kbs / 1000)
|
||||
}
|
Loading…
Reference in a new issue