mirror of
https://github.com/Atsukoro1/ponyfetch.git
synced 2024-11-30 15:48: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::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
use std::ops::Add;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
|
@ -28,9 +28,6 @@ pub fn get_cpu() -> String {
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub fn get_ram_used() -> String {
|
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 temp_buf: String = String::new();
|
||||||
|
|
||||||
let mut file = File::open("/proc/meminfo").unwrap();
|
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 lines: &Vec<&str> = &temp_buf.lines().collect();
|
||||||
|
|
||||||
|
let mut total: u128 = 0;
|
||||||
|
let mut available: u128 = 0;
|
||||||
|
|
||||||
lines.into_iter().for_each(|line| {
|
lines.into_iter().for_each(|line| {
|
||||||
ram.get_mut().unwrap().add("fdlkj");
|
|
||||||
if line.contains("MemTotal") {
|
if line.contains("MemTotal") {
|
||||||
|
total = eval_ram(line.to_string());
|
||||||
} else if line.contains("MemAvailable") {
|
} 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")]
|
#[cfg(target_os = "linux")]
|
||||||
fn eval_ram(line: String) -> String {
|
fn eval_ram(line: String) -> u128 {
|
||||||
let kbs: u128 = line.split(":")
|
let kbs: u128 = line.split(":")
|
||||||
.collect::<Vec<&str>>()[1].to_string()
|
.collect::<Vec<&str>>()[1].to_string()
|
||||||
.replace("\t", "")
|
.replace("\t", "")
|
||||||
|
@ -60,5 +63,5 @@ fn eval_ram(line: String) -> String {
|
||||||
.parse::<u128>()
|
.parse::<u128>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
(kbs / 1024).to_string()
|
(kbs / 1000)
|
||||||
}
|
}
|
Loading…
Reference in a new issue