mirror of
https://github.com/Atsukoro1/ponyfetch.git
synced 2025-02-18 18:34:24 +01:00
fix: 🐛 RAM display
This commit is contained in:
parent
84abc4ddcb
commit
1215df5a2c
1 changed files with 14 additions and 5 deletions
|
@ -33,21 +33,29 @@ pub fn get_ram_used() -> String {
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
let mut ram_used = String::new();
|
let mut ram_used = String::new();
|
||||||
|
let mut ram_total = String::new();
|
||||||
|
|
||||||
let output = Command::new("wmic")
|
let output = Command::new("wmic")
|
||||||
.args(&["OS", "get", "FreePhysicalMemory"])
|
.args(&["OS", "get", "FreePhysicalMemory,TotalVisibleMemorySize"])
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to execute process");
|
.expect("Failed to execute process");
|
||||||
|
|
||||||
let output = String::from_utf8_lossy(&output.stdout);
|
let output = String::from_utf8_lossy(&output.stdout);
|
||||||
|
|
||||||
for line in output.lines() {
|
for line in output.lines() {
|
||||||
if !line.contains("FreePhysicalMemory") && line.trim().len() > 0 {
|
if line.contains("Memory") || line.trim().len() == 0 {continue};
|
||||||
ram_used = line.to_string();
|
|
||||||
}
|
let mut split = line.split_whitespace();
|
||||||
|
|
||||||
|
ram_used = split.next().unwrap().to_string();
|
||||||
|
ram_total = split.next().unwrap().to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
ram_used
|
format!(
|
||||||
|
"{}MB / {}MB",
|
||||||
|
(ram_total.parse::<u64>().unwrap() - ram_used.parse::<u64>().unwrap()) / 1024,
|
||||||
|
ram_total.parse::<u64>().unwrap() / 1024
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
|
@ -120,6 +128,7 @@ pub fn get_ram_used() -> String {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
fn eval_ram(line: String) -> u128 {
|
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()
|
||||||
|
|
Loading…
Reference in a new issue