mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-24 13:47:38 +00:00
fix(memory_usage): prevent used swap underflow on windows (#2689)
This commit is contained in:
parent
41e417e1d3
commit
6f387769fe
@ -51,7 +51,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
0 => system.free,
|
||||
_ => system.avail,
|
||||
};
|
||||
let used_memory_kib = system.total - avail_memory_kib;
|
||||
let used_memory_kib = system.total.saturating_sub(avail_memory_kib);
|
||||
let total_memory_kib = system.total;
|
||||
let ram_used = (used_memory_kib as f64 / total_memory_kib as f64) * 100.;
|
||||
let ram_pct = format_pct(ram_used, pct_sign);
|
||||
@ -63,7 +63,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
|
||||
let ram = format_usage_total(used_memory_kib, total_memory_kib);
|
||||
let total_swap_kib = system.swap_total;
|
||||
let used_swap_kib = system.swap_total - system.swap_free;
|
||||
let used_swap_kib = system.swap_total.saturating_sub(system.swap_free);
|
||||
let percent_swap_used = (used_swap_kib as f64 / total_swap_kib as f64) * 100.;
|
||||
let swap_pct = format_pct(percent_swap_used, pct_sign);
|
||||
let swap = format_usage_total(used_swap_kib, total_swap_kib);
|
||||
|
Loading…
Reference in New Issue
Block a user