mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-23 21:55:11 +02:00
Added space, fixed div by 0 error.
This commit is contained in:
parent
1a54bb45fb
commit
8baa04f976
@ -1559,6 +1559,7 @@ impl Painter {
|
|||||||
// the desired lengths.
|
// the desired lengths.
|
||||||
|
|
||||||
let num_cpus = cpu_data.len();
|
let num_cpus = cpu_data.len();
|
||||||
|
if draw_loc.height > 2 {
|
||||||
let remaining_height = (draw_loc.height - 2) as usize;
|
let remaining_height = (draw_loc.height - 2) as usize;
|
||||||
let required_columns = (num_cpus / remaining_height)
|
let required_columns = (num_cpus / remaining_height)
|
||||||
+ (if num_cpus % remaining_height == 0 {
|
+ (if num_cpus % remaining_height == 0 {
|
||||||
@ -1567,11 +1568,6 @@ impl Painter {
|
|||||||
1
|
1
|
||||||
});
|
});
|
||||||
|
|
||||||
// debug!(
|
|
||||||
// "Num cpus: {}, remaining height: {}, required columns: {}",
|
|
||||||
// num_cpus, remaining_height, required_columns
|
|
||||||
// );
|
|
||||||
|
|
||||||
if required_columns > 0 {
|
if required_columns > 0 {
|
||||||
let chunk_vec =
|
let chunk_vec =
|
||||||
vec![Constraint::Percentage((100 / required_columns) as u16); required_columns];
|
vec![Constraint::Percentage((100 / required_columns) as u16); required_columns];
|
||||||
@ -1582,12 +1578,12 @@ impl Painter {
|
|||||||
.split(draw_loc);
|
.split(draw_loc);
|
||||||
|
|
||||||
let num_spaces = 3;
|
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(
|
let allowed_width = max(
|
||||||
0,
|
0,
|
||||||
draw_loc.width as i64
|
draw_loc.width as i64
|
||||||
- 2
|
- 2
|
||||||
- (num_spaces * (required_columns - 1) + 9 * required_columns) as i64,
|
- (num_spaces * (required_columns - 1) + 10 * required_columns) as i64,
|
||||||
) as usize;
|
) as usize;
|
||||||
|
|
||||||
let bar_length = allowed_width / required_columns;
|
let bar_length = allowed_width / required_columns;
|
||||||
@ -1603,7 +1599,7 @@ impl Painter {
|
|||||||
|
|
||||||
let num_bars = calculate_basic_use_bars(use_percentage, bar_length);
|
let num_bars = calculate_basic_use_bars(use_percentage, bar_length);
|
||||||
format!(
|
format!(
|
||||||
"{:3}[{}{}{:3.0}%]\n",
|
"{:3} [{}{}{:3.0}%]\n",
|
||||||
if cpu_index == 0 && app_state.app_config_fields.show_average_cpu {
|
if cpu_index == 0 && app_state.app_config_fields.show_average_cpu {
|
||||||
"AVG".to_string()
|
"AVG".to_string()
|
||||||
} else {
|
} else {
|
||||||
@ -1634,6 +1630,7 @@ impl Painter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn draw_basic_memory<B: Backend>(
|
fn draw_basic_memory<B: Backend>(
|
||||||
&self, f: &mut Frame<'_, B>, app_state: &mut app::App, draw_loc: Rect,
|
&self, f: &mut Frame<'_, B>, app_state: &mut app::App, draw_loc: Rect,
|
||||||
@ -1654,8 +1651,8 @@ impl Painter {
|
|||||||
.margin(1)
|
.margin(1)
|
||||||
.split(draw_loc);
|
.split(draw_loc);
|
||||||
|
|
||||||
// +9 due to 3 + 4 + 2 columns for the mem name + percentage + bar bounds
|
// +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 - 9 as i64) as usize;
|
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() {
|
let ram_use_percentage = if let Some(mem) = mem_data.last() {
|
||||||
mem.1
|
mem.1
|
||||||
} else {
|
} else {
|
||||||
@ -1669,15 +1666,13 @@ impl Painter {
|
|||||||
let num_bars_ram = calculate_basic_use_bars(ram_use_percentage, bar_length);
|
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 num_bars_swap = calculate_basic_use_bars(swap_use_percentage, bar_length);
|
||||||
let mem_label = format!(
|
let mem_label = format!(
|
||||||
"{:3}[{}{}{:3.0}%]\n",
|
"RAM [{}{}{:3.0}%]\n",
|
||||||
"RAM",
|
|
||||||
"|".repeat(num_bars_ram),
|
"|".repeat(num_bars_ram),
|
||||||
" ".repeat(bar_length - num_bars_ram),
|
" ".repeat(bar_length - num_bars_ram),
|
||||||
ram_use_percentage.round(),
|
ram_use_percentage.round(),
|
||||||
);
|
);
|
||||||
let swap_label = format!(
|
let swap_label = format!(
|
||||||
"{:3}[{}{}{:3.0}%]\n",
|
"SWP [{}{}{:3.0}%]\n",
|
||||||
"SWP",
|
|
||||||
"|".repeat(num_bars_swap),
|
"|".repeat(num_bars_swap),
|
||||||
" ".repeat(bar_length - num_bars_swap),
|
" ".repeat(bar_length - num_bars_swap),
|
||||||
swap_use_percentage.round(),
|
swap_use_percentage.round(),
|
||||||
@ -1719,7 +1714,7 @@ impl Painter {
|
|||||||
.margin(1)
|
.margin(1)
|
||||||
.split(draw_loc);
|
.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 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() {
|
let rx_use_percentage = if let Some(rx) = rx_data.last() {
|
||||||
rx.1
|
rx.1
|
||||||
@ -1734,15 +1729,13 @@ impl Painter {
|
|||||||
let num_bars_rx = calculate_basic_use_bars(rx_use_percentage, bar_length);
|
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 num_bars_tx = calculate_basic_use_bars(tx_use_percentage, bar_length);
|
||||||
let rx_label = format!(
|
let rx_label = format!(
|
||||||
"{:3}[{}{}{:3.0}%]\n",
|
"RX [{}{}{:3.0}%]\n",
|
||||||
"RX",
|
|
||||||
"|".repeat(num_bars_rx),
|
"|".repeat(num_bars_rx),
|
||||||
" ".repeat(bar_length - num_bars_rx),
|
" ".repeat(bar_length - num_bars_rx),
|
||||||
rx_use_percentage.round(),
|
rx_use_percentage.round(),
|
||||||
);
|
);
|
||||||
let tx_label = format!(
|
let tx_label = format!(
|
||||||
"{:3}[{}{}{:3.0}%]\n",
|
"TX [{}{}{:3.0}%]\n",
|
||||||
"TX",
|
|
||||||
"|".repeat(num_bars_tx),
|
"|".repeat(num_bars_tx),
|
||||||
" ".repeat(bar_length - num_bars_tx),
|
" ".repeat(bar_length - num_bars_tx),
|
||||||
tx_use_percentage.round(),
|
tx_use_percentage.round(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user