mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-23 13:45:12 +02:00
Fixed column organization, need to refactor CPU side to remove any redundant code.
This commit is contained in:
parent
227af7654f
commit
63f2ead48b
@ -244,7 +244,6 @@ pub struct App {
|
|||||||
pub update_process_gui: bool,
|
pub update_process_gui: bool,
|
||||||
pub app_scroll_positions: AppScrollState,
|
pub app_scroll_positions: AppScrollState,
|
||||||
pub current_widget_selected: WidgetPosition,
|
pub current_widget_selected: WidgetPosition,
|
||||||
pub data: data_harvester::Data,
|
|
||||||
awaiting_second_char: bool,
|
awaiting_second_char: bool,
|
||||||
second_char: Option<char>,
|
second_char: Option<char>,
|
||||||
pub dd_err: Option<String>,
|
pub dd_err: Option<String>,
|
||||||
@ -279,7 +278,6 @@ impl App {
|
|||||||
update_process_gui: false,
|
update_process_gui: false,
|
||||||
current_widget_selected,
|
current_widget_selected,
|
||||||
app_scroll_positions: AppScrollState::default(),
|
app_scroll_positions: AppScrollState::default(),
|
||||||
data: data_harvester::Data::default(),
|
|
||||||
awaiting_second_char: false,
|
awaiting_second_char: false,
|
||||||
second_char: None,
|
second_char: None,
|
||||||
dd_err: None,
|
dd_err: None,
|
||||||
|
152
src/canvas.rs
152
src/canvas.rs
@ -423,10 +423,19 @@ impl Painter {
|
|||||||
// Basic mode. This basically removes all graphs but otherwise
|
// Basic mode. This basically removes all graphs but otherwise
|
||||||
// the same info.
|
// the same info.
|
||||||
|
|
||||||
|
let cpu_height = (app_state.canvas_data.cpu_data.len() / 4) as u16
|
||||||
|
+ (
|
||||||
|
if app_state.canvas_data.cpu_data.len() % 4 == 0 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
);
|
||||||
|
debug!("C: {}", cpu_height);
|
||||||
let vertical_chunks = Layout::default()
|
let vertical_chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints([
|
||||||
Constraint::Length(6),
|
Constraint::Length(cpu_height),
|
||||||
Constraint::Length(3),
|
Constraint::Length(3),
|
||||||
Constraint::Min(5),
|
Constraint::Min(5),
|
||||||
].as_ref())
|
].as_ref())
|
||||||
@ -1581,75 +1590,75 @@ impl Painter {
|
|||||||
let num_cpus = cpu_data.len();
|
let num_cpus = cpu_data.len();
|
||||||
if draw_loc.height > 0 {
|
if draw_loc.height > 0 {
|
||||||
let remaining_height = draw_loc.height as usize;
|
let remaining_height = draw_loc.height as usize;
|
||||||
let required_columns = (num_cpus / remaining_height)
|
let required_columns = 4;
|
||||||
+ (if num_cpus % remaining_height == 0 {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
1
|
|
||||||
});
|
|
||||||
|
|
||||||
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];
|
let chunks = Layout::default()
|
||||||
let chunks = Layout::default()
|
.constraints(chunk_vec.as_ref())
|
||||||
.constraints(chunk_vec.as_ref())
|
.direction(Direction::Horizontal)
|
||||||
.direction(Direction::Horizontal)
|
.split(draw_loc);
|
||||||
.horizontal_margin(1)
|
|
||||||
.split(draw_loc);
|
|
||||||
|
|
||||||
let num_spaces = 2;
|
// +9 due to 3 + 4 + 2 columns for the name & space + percentage + bar bounds
|
||||||
// +10 due to 4 + 4 + 2 columns for the name & space + percentage + bar bounds
|
let margin_space = 2;
|
||||||
let remaining_width = max(
|
let remaining_width = max(
|
||||||
0,
|
0,
|
||||||
draw_loc.width as i64 - ((num_spaces + 10) * required_columns) as i64,
|
draw_loc.width as i64
|
||||||
) as usize;
|
- ((9 + margin_space) * required_columns - margin_space) as i64,
|
||||||
|
) as usize;
|
||||||
|
|
||||||
let bar_length = remaining_width / required_columns;
|
let bar_length = remaining_width / required_columns;
|
||||||
|
|
||||||
let cpu_bars = (0..num_cpus)
|
let cpu_bars = (0..num_cpus)
|
||||||
|
.map(|cpu_index| {
|
||||||
|
let use_percentage =
|
||||||
|
if let Some(cpu_usage) = cpu_data[cpu_index].cpu_data.last() {
|
||||||
|
cpu_usage.1
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
let num_bars = calculate_basic_use_bars(use_percentage, bar_length);
|
||||||
|
format!(
|
||||||
|
"{:3}[{}{}{:3.0}%]\n",
|
||||||
|
if app_state.app_config_fields.show_average_cpu {
|
||||||
|
if cpu_index == 0 {
|
||||||
|
"AVG".to_string()
|
||||||
|
} else {
|
||||||
|
(cpu_index - 1).to_string()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cpu_index.to_string()
|
||||||
|
},
|
||||||
|
"|".repeat(num_bars),
|
||||||
|
" ".repeat(bar_length - num_bars),
|
||||||
|
use_percentage.round(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
for (current_row, chunk) in chunks.iter().enumerate() {
|
||||||
|
let start_index = (current_row * remaining_height) as usize;
|
||||||
|
let end_index = min(start_index + remaining_height, num_cpus);
|
||||||
|
let cpu_column: Vec<Text<'_>> = (start_index..end_index)
|
||||||
.map(|cpu_index| {
|
.map(|cpu_index| {
|
||||||
let use_percentage =
|
Text::Styled(
|
||||||
if let Some(cpu_usage) = cpu_data[cpu_index].cpu_data.last() {
|
(&cpu_bars[cpu_index]).into(),
|
||||||
cpu_usage.1
|
self.colours.cpu_colour_styles
|
||||||
} else {
|
[cpu_index as usize % self.colours.cpu_colour_styles.len()],
|
||||||
0.0
|
|
||||||
};
|
|
||||||
|
|
||||||
let num_bars = calculate_basic_use_bars(use_percentage, bar_length);
|
|
||||||
format!(
|
|
||||||
"{:3}[{}{}{:3.0}%]\n",
|
|
||||||
if app_state.app_config_fields.show_average_cpu {
|
|
||||||
if cpu_index == 0 {
|
|
||||||
"AVG".to_string()
|
|
||||||
} else {
|
|
||||||
(cpu_index - 1).to_string()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cpu_index.to_string()
|
|
||||||
},
|
|
||||||
"|".repeat(num_bars),
|
|
||||||
" ".repeat(bar_length - num_bars),
|
|
||||||
use_percentage.round(),
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
for (current_row, chunk) in chunks.iter().enumerate() {
|
let margined_loc = Layout::default()
|
||||||
let start_index = (current_row * remaining_height) as usize;
|
.direction(Direction::Horizontal)
|
||||||
let end_index = min(start_index + remaining_height, num_cpus);
|
.constraints([Constraint::Percentage(100)].as_ref())
|
||||||
let cpu_column: Vec<Text<'_>> = (start_index..end_index)
|
.horizontal_margin(1)
|
||||||
.map(|cpu_index| {
|
.split(*chunk);
|
||||||
Text::Styled(
|
|
||||||
(&cpu_bars[cpu_index]).into(),
|
Paragraph::new(cpu_column.iter())
|
||||||
self.colours.cpu_colour_styles
|
.block(Block::default())
|
||||||
[cpu_index as usize % self.colours.cpu_colour_styles.len()],
|
.render(f, margined_loc[0]);
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
Paragraph::new(cpu_column.iter())
|
|
||||||
.block(Block::default())
|
|
||||||
.render(f, *chunk);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1712,12 +1721,23 @@ impl Painter {
|
|||||||
fn draw_basic_network<B: Backend>(
|
fn draw_basic_network<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,
|
||||||
) {
|
) {
|
||||||
let margined_loc = Layout::default()
|
let divided_loc = Layout::default()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||||
.horizontal_margin(1)
|
|
||||||
.split(draw_loc);
|
.split(draw_loc);
|
||||||
|
|
||||||
|
let net_loc = Layout::default()
|
||||||
|
.direction(Direction::Horizontal)
|
||||||
|
.constraints([Constraint::Percentage(100)].as_ref())
|
||||||
|
.horizontal_margin(1)
|
||||||
|
.split(divided_loc[0]);
|
||||||
|
|
||||||
|
let total_loc = Layout::default()
|
||||||
|
.direction(Direction::Horizontal)
|
||||||
|
.constraints([Constraint::Percentage(100)].as_ref())
|
||||||
|
.horizontal_margin(1)
|
||||||
|
.split(divided_loc[1]);
|
||||||
|
|
||||||
if let WidgetPosition::Network = app_state.current_widget_selected {
|
if let WidgetPosition::Network = app_state.current_widget_selected {
|
||||||
Block::default()
|
Block::default()
|
||||||
.borders(*SIDE_BORDERS)
|
.borders(*SIDE_BORDERS)
|
||||||
@ -1741,13 +1761,11 @@ impl Painter {
|
|||||||
];
|
];
|
||||||
|
|
||||||
Paragraph::new(net_text.iter())
|
Paragraph::new(net_text.iter())
|
||||||
.alignment(Alignment::Center)
|
|
||||||
.block(Block::default())
|
.block(Block::default())
|
||||||
.render(f, margined_loc[0]);
|
.render(f, net_loc[0]);
|
||||||
|
|
||||||
Paragraph::new(total_net_text.iter())
|
Paragraph::new(total_net_text.iter())
|
||||||
.alignment(Alignment::Center)
|
|
||||||
.block(Block::default())
|
.block(Block::default())
|
||||||
.render(f, margined_loc[1]);
|
.render(f, total_loc[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user