From be4421630e499b02ce7813d7a88af84350a278a2 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Sat, 9 Jul 2022 18:21:28 +0900 Subject: [PATCH] Fix output of memory info It displayed "GiB" where it should have displayed "MiB" --- src/proc.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/proc.rs b/src/proc.rs index 90fc666..e09119f 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -91,7 +91,7 @@ pub fn get_meminfo() -> io::Result { meminfo.read_to_string(&mut meminfo_string)?; } - let mut is_total_giga = false; + let mut is_total_mega = false; let mut total: u32 = 0; let mut available: u32 = 0; for line in meminfo_string.lines() { @@ -115,31 +115,31 @@ pub fn get_meminfo() -> io::Result { } let mut used = total - available; - let mut is_used_giga = false; + let mut is_used_mega = false; if total == 0 { Ok("0".into()) } else { if total > 1024 { total /= 1024; - is_total_giga = true; + is_total_mega = true; } if used > 1024 { used /= 1024; - is_used_giga = true; + is_used_mega = true; } let mut output = format!("{} ", used); - if is_used_giga { - output.push_str("GiB / "); + if is_used_mega { + output.push_str("MiB / "); } else { output.push_str("KiB / "); } output.push_str(&format!("{} ", total)); - if is_total_giga { - output.push_str("GiB"); + if is_total_mega { + output.push_str("MiB"); } else { output.push_str("KiB"); }