mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-24 22:24:53 +02:00
Fixed column organization, need to refactor CPU side to remove any redundant code.
This commit is contained in:
parent
14c2320de2
commit
fcd529aca2
@ -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,
|
||||||
|
@ -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,27 +1590,21 @@ 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)
|
||||||
.horizontal_margin(1)
|
|
||||||
.split(draw_loc);
|
.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
|
||||||
|
- ((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;
|
||||||
@ -1646,10 +1649,16 @@ impl Painter {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let margined_loc = Layout::default()
|
||||||
|
.direction(Direction::Horizontal)
|
||||||
|
.constraints([Constraint::Percentage(100)].as_ref())
|
||||||
|
.horizontal_margin(1)
|
||||||
|
.split(*chunk);
|
||||||
|
|
||||||
Paragraph::new(cpu_column.iter())
|
Paragraph::new(cpu_column.iter())
|
||||||
.block(Block::default())
|
.block(Block::default())
|
||||||
.render(f, *chunk);
|
.render(f, margined_loc[0]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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