Added space, fixed div by 0 error.

This commit is contained in:
ClementTsang 2020-03-01 01:11:22 -05:00
parent 1a54bb45fb
commit 8baa04f976

View File

@ -1559,6 +1559,7 @@ impl Painter {
// the desired lengths.
let num_cpus = cpu_data.len();
if draw_loc.height > 2 {
let remaining_height = (draw_loc.height - 2) as usize;
let required_columns = (num_cpus / remaining_height)
+ (if num_cpus % remaining_height == 0 {
@ -1567,11 +1568,6 @@ impl Painter {
1
});
// debug!(
// "Num cpus: {}, remaining height: {}, required columns: {}",
// num_cpus, remaining_height, required_columns
// );
if required_columns > 0 {
let chunk_vec =
vec![Constraint::Percentage((100 / required_columns) as u16); required_columns];
@ -1582,12 +1578,12 @@ impl Painter {
.split(draw_loc);
let num_spaces = 3;
// +9 due to 3 + 4 + 2 columns for the CPU name + percentage + bar bounds
// +10 due to 4 + 4 + 2 columns for the name & space + percentage + bar bounds
let allowed_width = max(
0,
draw_loc.width as i64
- 2
- (num_spaces * (required_columns - 1) + 9 * required_columns) as i64,
- (num_spaces * (required_columns - 1) + 10 * required_columns) as i64,
) as usize;
let bar_length = allowed_width / required_columns;
@ -1634,6 +1630,7 @@ impl Painter {
}
}
}
}
fn draw_basic_memory<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut app::App, draw_loc: Rect,
@ -1654,8 +1651,8 @@ impl Painter {
.margin(1)
.split(draw_loc);
// +9 due to 3 + 4 + 2 columns for the mem name + percentage + bar bounds
let bar_length = max(0, draw_loc.width as i64 - 2 - 9 as i64) as usize;
// +10 due to 4 + 4 + 2 columns for the name & space + percentage + bar bounds
let bar_length = max(0, draw_loc.width as i64 - 2 - 10 as i64) as usize;
let ram_use_percentage = if let Some(mem) = mem_data.last() {
mem.1
} else {
@ -1669,15 +1666,13 @@ impl Painter {
let num_bars_ram = calculate_basic_use_bars(ram_use_percentage, bar_length);
let num_bars_swap = calculate_basic_use_bars(swap_use_percentage, bar_length);
let mem_label = format!(
"{:3}[{}{}{:3.0}%]\n",
"RAM",
"RAM [{}{}{:3.0}%]\n",
"|".repeat(num_bars_ram),
" ".repeat(bar_length - num_bars_ram),
ram_use_percentage.round(),
);
let swap_label = format!(
"{:3}[{}{}{:3.0}%]\n",
"SWP",
"SWP [{}{}{:3.0}%]\n",
"|".repeat(num_bars_swap),
" ".repeat(bar_length - num_bars_swap),
swap_use_percentage.round(),
@ -1719,7 +1714,7 @@ impl Painter {
.margin(1)
.split(draw_loc);
// +9 due to 3 + 4 + 2 columns for the mem name + percentage + bar bounds
// +9 due to 3 + 4 + 2 columns for the name & space + percentage + bar bounds
let bar_length = max(0, draw_loc.width as i64 - 2 - 9 as i64) as usize;
let rx_use_percentage = if let Some(rx) = rx_data.last() {
rx.1
@ -1734,15 +1729,13 @@ impl Painter {
let num_bars_rx = calculate_basic_use_bars(rx_use_percentage, bar_length);
let num_bars_tx = calculate_basic_use_bars(tx_use_percentage, bar_length);
let rx_label = format!(
"{:3}[{}{}{:3.0}%]\n",
"RX",
"RX [{}{}{:3.0}%]\n",
"|".repeat(num_bars_rx),
" ".repeat(bar_length - num_bars_rx),
rx_use_percentage.round(),
);
let tx_label = format!(
"{:3}[{}{}{:3.0}%]\n",
"TX",
"TX [{}{}{:3.0}%]\n",
"|".repeat(num_bars_tx),
" ".repeat(bar_length - num_bars_tx),
tx_use_percentage.round(),