mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-27 07:34:27 +02:00
Add table indicator to basic.
This commit is contained in:
parent
9cad3bb4ec
commit
f3ebed6185
22
src/app.rs
22
src/app.rs
@ -38,6 +38,18 @@ impl WidgetPosition {
|
|||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_pretty_name(self) -> String {
|
||||||
|
match self {
|
||||||
|
WidgetPosition::Cpu | WidgetPosition::BasicCpu => "CPU",
|
||||||
|
WidgetPosition::Mem | WidgetPosition::BasicMem => "Memory",
|
||||||
|
WidgetPosition::Disk => "Disks",
|
||||||
|
WidgetPosition::Temp => "Temperature",
|
||||||
|
WidgetPosition::Network | WidgetPosition::BasicNet => "Network",
|
||||||
|
WidgetPosition::Process | WidgetPosition::ProcessSearch => "Processes",
|
||||||
|
}
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -259,7 +271,7 @@ 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 last_basic_table_widget_selected: WidgetPosition,
|
pub previous_basic_table_selected: WidgetPosition,
|
||||||
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>,
|
||||||
@ -302,7 +314,7 @@ impl App {
|
|||||||
} else {
|
} else {
|
||||||
current_widget_selected
|
current_widget_selected
|
||||||
},
|
},
|
||||||
last_basic_table_widget_selected: if current_widget_selected.is_widget_table() {
|
previous_basic_table_selected: if current_widget_selected.is_widget_table() {
|
||||||
current_widget_selected
|
current_widget_selected
|
||||||
} else {
|
} else {
|
||||||
WidgetPosition::Process
|
WidgetPosition::Process
|
||||||
@ -1139,7 +1151,7 @@ impl App {
|
|||||||
if !self.is_in_dialog() && !self.is_expanded {
|
if !self.is_in_dialog() && !self.is_expanded {
|
||||||
if self.app_config_fields.use_basic_mode {
|
if self.app_config_fields.use_basic_mode {
|
||||||
if self.current_widget_selected.is_widget_table() {
|
if self.current_widget_selected.is_widget_table() {
|
||||||
self.last_basic_table_widget_selected = self.current_widget_selected;
|
self.previous_basic_table_selected = self.current_widget_selected;
|
||||||
}
|
}
|
||||||
self.current_widget_selected = match self.current_widget_selected {
|
self.current_widget_selected = match self.current_widget_selected {
|
||||||
WidgetPosition::BasicMem => WidgetPosition::BasicCpu,
|
WidgetPosition::BasicMem => WidgetPosition::BasicCpu,
|
||||||
@ -1175,8 +1187,8 @@ impl App {
|
|||||||
if !self.is_in_dialog() && !self.is_expanded {
|
if !self.is_in_dialog() && !self.is_expanded {
|
||||||
if self.app_config_fields.use_basic_mode {
|
if self.app_config_fields.use_basic_mode {
|
||||||
self.current_widget_selected = match self.current_widget_selected {
|
self.current_widget_selected = match self.current_widget_selected {
|
||||||
WidgetPosition::BasicMem => self.last_basic_table_widget_selected,
|
WidgetPosition::BasicMem => self.previous_basic_table_selected,
|
||||||
WidgetPosition::BasicNet => self.last_basic_table_widget_selected,
|
WidgetPosition::BasicNet => self.previous_basic_table_selected,
|
||||||
WidgetPosition::BasicCpu => WidgetPosition::BasicMem,
|
WidgetPosition::BasicCpu => WidgetPosition::BasicMem,
|
||||||
WidgetPosition::Process => {
|
WidgetPosition::Process => {
|
||||||
if self.is_searching() {
|
if self.is_searching() {
|
||||||
|
@ -435,7 +435,8 @@ impl Painter {
|
|||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints([
|
||||||
Constraint::Length(cpu_height),
|
Constraint::Length(cpu_height),
|
||||||
Constraint::Length(3),
|
Constraint::Length(2),
|
||||||
|
Constraint::Length(2),
|
||||||
Constraint::Min(5),
|
Constraint::Min(5),
|
||||||
].as_ref())
|
].as_ref())
|
||||||
.split(f.size());
|
.split(f.size());
|
||||||
@ -450,10 +451,11 @@ impl Painter {
|
|||||||
self.draw_basic_cpu(&mut f, app_state, vertical_chunks[0]);
|
self.draw_basic_cpu(&mut f, app_state, vertical_chunks[0]);
|
||||||
self.draw_basic_memory(&mut f, app_state, middle_chunks[0]);
|
self.draw_basic_memory(&mut f, app_state, middle_chunks[0]);
|
||||||
self.draw_basic_network(&mut f, app_state, middle_chunks[1]);
|
self.draw_basic_network(&mut f, app_state, middle_chunks[1]);
|
||||||
|
self.draw_basic_table_arrows(&mut f, app_state, vertical_chunks[2]);
|
||||||
if app_state.current_widget_selected.is_widget_table() {
|
if app_state.current_widget_selected.is_widget_table() {
|
||||||
self.draw_specific_table(&mut f, app_state, vertical_chunks[2], false, app_state.current_widget_selected);
|
self.draw_specific_table(&mut f, app_state, vertical_chunks[3], false, app_state.current_widget_selected);
|
||||||
} else {
|
} else {
|
||||||
self.draw_specific_table(&mut f, app_state, vertical_chunks[2], false, app_state.last_basic_table_widget_selected);
|
self.draw_specific_table(&mut f, app_state, vertical_chunks[3], false, app_state.previous_basic_table_selected);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: [TUI] Change this back to a more even 33/33/34 when TUI releases
|
// TODO: [TUI] Change this back to a more even 33/33/34 when TUI releases
|
||||||
@ -1810,4 +1812,57 @@ impl Painter {
|
|||||||
.block(Block::default())
|
.block(Block::default())
|
||||||
.render(f, total_loc[0]);
|
.render(f, total_loc[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_basic_table_arrows<B: Backend>(
|
||||||
|
&self, f: &mut Frame<'_, B>, app_state: &mut app::App, draw_loc: Rect,
|
||||||
|
) {
|
||||||
|
// Effectively a paragraph with a ton of spacing
|
||||||
|
|
||||||
|
// TODO: [MODULARITY] This is hard coded. Gross.
|
||||||
|
let (left_table, right_table) = if app_state.current_widget_selected.is_widget_table() {
|
||||||
|
match app_state.current_widget_selected {
|
||||||
|
WidgetPosition::Process | WidgetPosition::ProcessSearch => {
|
||||||
|
(WidgetPosition::Temp, WidgetPosition::Disk)
|
||||||
|
}
|
||||||
|
WidgetPosition::Disk => (WidgetPosition::Process, WidgetPosition::Temp),
|
||||||
|
WidgetPosition::Temp => (WidgetPosition::Disk, WidgetPosition::Process),
|
||||||
|
_ => (WidgetPosition::Disk, WidgetPosition::Temp),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match app_state.previous_basic_table_selected {
|
||||||
|
WidgetPosition::Process | WidgetPosition::ProcessSearch => {
|
||||||
|
(WidgetPosition::Temp, WidgetPosition::Disk)
|
||||||
|
}
|
||||||
|
WidgetPosition::Disk => (WidgetPosition::Process, WidgetPosition::Temp),
|
||||||
|
WidgetPosition::Temp => (WidgetPosition::Disk, WidgetPosition::Process),
|
||||||
|
_ => (WidgetPosition::Disk, WidgetPosition::Temp),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let left_name = left_table.get_pretty_name();
|
||||||
|
let right_name = right_table.get_pretty_name();
|
||||||
|
|
||||||
|
let num_spaces = max(
|
||||||
|
0,
|
||||||
|
draw_loc.width as i64 - 2 - 4 - (left_name.len() + right_name.len()) as i64,
|
||||||
|
) as usize;
|
||||||
|
|
||||||
|
let arrow_text = vec![
|
||||||
|
Text::Styled(
|
||||||
|
format!("\n◄ {}", right_name).into(),
|
||||||
|
self.colours.text_style,
|
||||||
|
),
|
||||||
|
Text::Raw(" ".repeat(num_spaces).into()),
|
||||||
|
Text::Styled(format!("{} ►", left_name).into(), self.colours.text_style),
|
||||||
|
];
|
||||||
|
|
||||||
|
let margined_draw_loc = Layout::default()
|
||||||
|
.constraints([Constraint::Percentage(100)].as_ref())
|
||||||
|
.horizontal_margin(1)
|
||||||
|
.split(draw_loc);
|
||||||
|
|
||||||
|
Paragraph::new(arrow_text.iter())
|
||||||
|
.block(Block::default())
|
||||||
|
.render(f, margined_draw_loc[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user