Skip to content

Commit 364c2ba

Browse files
committed
top: tui fix NaN when no swap
1 parent f400fc9 commit 364c2ba

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/uu/top/src/tui/mod.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,27 @@ impl<'a> Tui<'a> {
293293
bar_content,
294294
false,
295295
));
296-
mem_bars.push((
297-
format!("{unit_name} Swap"),
298-
mem.used_swap as f64 / mem.total_swap as f64 * 100.0,
299-
format_memory(mem.total_swap, unit),
300-
0.0,
301-
mem.used_swap as f64 / mem.total_swap as f64,
302-
bar_content,
303-
false,
304-
));
296+
if mem.total_swap > 0 {
297+
mem_bars.push((
298+
format!("{unit_name} Swap"),
299+
mem.used_swap as f64 / mem.total_swap as f64 * 100.0,
300+
format_memory(mem.total_swap, unit),
301+
0.0,
302+
mem.used_swap as f64 / mem.total_swap as f64,
303+
bar_content,
304+
false,
305+
));
306+
} else {
307+
mem_bars.push((
308+
format!("{unit_name} Swap"),
309+
0.0,
310+
0.0,
311+
0.0,
312+
0.0,
313+
bar_content,
314+
false,
315+
));
316+
}
305317
render_bars(mem_bars, &mut *buf, i);
306318
}
307319
}

0 commit comments

Comments
 (0)