mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-25 22:55:06 +02:00
Add CPU row allocation system to more evenly distribute it (aka simple division)
This commit is contained in:
parent
32ca9edf11
commit
c69362000d
@ -30,6 +30,8 @@ Features of bottom include:
|
|||||||
|
|
||||||
- Maximizing of widgets of interest to take up the entire window.
|
- Maximizing of widgets of interest to take up the entire window.
|
||||||
|
|
||||||
|
- Basic mode
|
||||||
|
|
||||||
More details about each widget and compatibility can be found [here](./docs/widgets.md).
|
More details about each widget and compatibility can be found [here](./docs/widgets.md).
|
||||||
|
|
||||||
## Config files
|
## Config files
|
||||||
|
@ -1643,6 +1643,7 @@ impl Painter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let num_cpus = cpu_data.len();
|
let num_cpus = cpu_data.len();
|
||||||
|
if draw_loc.height > 0 {
|
||||||
let remaining_height = draw_loc.height as usize;
|
let remaining_height = draw_loc.height as usize;
|
||||||
const REQUIRED_COLUMNS: usize = 4;
|
const REQUIRED_COLUMNS: usize = 4;
|
||||||
|
|
||||||
@ -1657,7 +1658,8 @@ impl Painter {
|
|||||||
let margin_space = 2;
|
let margin_space = 2;
|
||||||
let remaining_width = max(
|
let remaining_width = max(
|
||||||
0,
|
0,
|
||||||
draw_loc.width as i64 - ((9 + margin_space) * REQUIRED_COLUMNS - margin_space) as i64,
|
draw_loc.width as i64
|
||||||
|
- ((9 + margin_space) * REQUIRED_COLUMNS - margin_space) as i64,
|
||||||
) as usize;
|
) as usize;
|
||||||
|
|
||||||
let bar_length = remaining_width / REQUIRED_COLUMNS;
|
let bar_length = remaining_width / REQUIRED_COLUMNS;
|
||||||
@ -1665,7 +1667,8 @@ impl Painter {
|
|||||||
// CPU (and RAM) percent bars are, uh, "heavily" inspired from htop.
|
// CPU (and RAM) percent bars are, uh, "heavily" inspired from htop.
|
||||||
let cpu_bars = (0..num_cpus)
|
let cpu_bars = (0..num_cpus)
|
||||||
.map(|cpu_index| {
|
.map(|cpu_index| {
|
||||||
let use_percentage = if let Some(cpu_usage) = cpu_data[cpu_index].cpu_data.last() {
|
let use_percentage =
|
||||||
|
if let Some(cpu_usage) = cpu_data[cpu_index].cpu_data.last() {
|
||||||
cpu_usage.1
|
cpu_usage.1
|
||||||
} else {
|
} else {
|
||||||
0.0
|
0.0
|
||||||
@ -1690,9 +1693,16 @@ impl Painter {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
for (current_row, chunk) in chunks.iter().enumerate() {
|
let mut row_counter = num_cpus;
|
||||||
let start_index = (current_row * remaining_height) as usize;
|
let mut start_index = 0;
|
||||||
let end_index = min(start_index + remaining_height, num_cpus);
|
for (itx, chunk) in chunks.iter().enumerate() {
|
||||||
|
let to_divide = REQUIRED_COLUMNS - itx;
|
||||||
|
let how_many_cpus = min(
|
||||||
|
remaining_height,
|
||||||
|
(row_counter / to_divide) + (if row_counter % to_divide == 0 { 0 } else { 1 }),
|
||||||
|
);
|
||||||
|
row_counter -= how_many_cpus;
|
||||||
|
let end_index = min(start_index + how_many_cpus, num_cpus);
|
||||||
let cpu_column: Vec<Text<'_>> = (start_index..end_index)
|
let cpu_column: Vec<Text<'_>> = (start_index..end_index)
|
||||||
.map(|cpu_index| {
|
.map(|cpu_index| {
|
||||||
Text::Styled(
|
Text::Styled(
|
||||||
@ -1703,6 +1713,8 @@ impl Painter {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
start_index += how_many_cpus;
|
||||||
|
|
||||||
let margined_loc = Layout::default()
|
let margined_loc = Layout::default()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints([Constraint::Percentage(100)].as_ref())
|
.constraints([Constraint::Percentage(100)].as_ref())
|
||||||
@ -1714,6 +1726,7 @@ impl Painter {
|
|||||||
.render(f, margined_loc[0]);
|
.render(f, margined_loc[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user