Skip to content

Commit 4107e29

Browse files
committed
top: tui fix NaN when no swap
1 parent eb52572 commit 4107e29

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
@@ -319,15 +319,27 @@ impl<'a> Tui<'a> {
319319
bar_content,
320320
false,
321321
));
322-
mem_bars.push((
323-
format!("{unit_name} Swap"),
324-
mem.used_swap as f64 / mem.total_swap as f64 * 100.0,
325-
format_memory(mem.total_swap, unit),
326-
0.0,
327-
mem.used_swap as f64 / mem.total_swap as f64,
328-
bar_content,
329-
false,
330-
));
322+
if mem.total_swap > 0 {
323+
mem_bars.push((
324+
format!("{unit_name} Swap"),
325+
mem.used_swap as f64 / mem.total_swap as f64 * 100.0,
326+
format_memory(mem.total_swap, unit),
327+
0.0,
328+
mem.used_swap as f64 / mem.total_swap as f64,
329+
bar_content,
330+
false,
331+
));
332+
} else {
333+
mem_bars.push((
334+
format!("{unit_name} Swap"),
335+
0.0,
336+
0.0,
337+
0.0,
338+
0.0,
339+
bar_content,
340+
false,
341+
));
342+
}
331343
render_bars(mem_bars, &mut *buf, i);
332344
}
333345
}

0 commit comments

Comments
 (0)