mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-23 13:45:12 +02:00
Made the dd screen prettier.
This commit is contained in:
parent
30f69e2ee0
commit
909fbd3571
48
src/app.rs
48
src/app.rs
@ -105,6 +105,17 @@ impl AppSearchState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct AppDeleteDialogState {
|
||||||
|
pub is_showing_dd: bool,
|
||||||
|
pub is_on_yes: bool, // Defaults to "No"
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct AppHelpDialogState {
|
||||||
|
pub is_showing_help: bool,
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: [OPT] Group like fields together... this is kinda gross to step through
|
// TODO: [OPT] Group like fields together... this is kinda gross to step through
|
||||||
pub struct App {
|
pub struct App {
|
||||||
// Sorting
|
// Sorting
|
||||||
@ -129,8 +140,6 @@ pub struct App {
|
|||||||
awaiting_second_char: bool,
|
awaiting_second_char: bool,
|
||||||
second_char: char,
|
second_char: char,
|
||||||
pub use_dot: bool,
|
pub use_dot: bool,
|
||||||
pub show_help: bool,
|
|
||||||
pub show_dd: bool,
|
|
||||||
pub dd_err: Option<String>,
|
pub dd_err: Option<String>,
|
||||||
to_delete_process_list: Option<(String, Vec<u32>)>,
|
to_delete_process_list: Option<(String, Vec<u32>)>,
|
||||||
pub is_frozen: bool,
|
pub is_frozen: bool,
|
||||||
@ -142,6 +151,8 @@ pub struct App {
|
|||||||
enable_searching: bool,
|
enable_searching: bool,
|
||||||
pub data_collection: DataCollection,
|
pub data_collection: DataCollection,
|
||||||
pub search_state: AppSearchState,
|
pub search_state: AppSearchState,
|
||||||
|
pub delete_dialog_state: AppDeleteDialogState,
|
||||||
|
pub help_dialog_state: AppHelpDialogState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
@ -171,8 +182,6 @@ impl App {
|
|||||||
awaiting_second_char: false,
|
awaiting_second_char: false,
|
||||||
second_char: ' ',
|
second_char: ' ',
|
||||||
use_dot,
|
use_dot,
|
||||||
show_help: false,
|
|
||||||
show_dd: false,
|
|
||||||
dd_err: None,
|
dd_err: None,
|
||||||
to_delete_process_list: None,
|
to_delete_process_list: None,
|
||||||
is_frozen: false,
|
is_frozen: false,
|
||||||
@ -184,13 +193,15 @@ impl App {
|
|||||||
enable_searching: false,
|
enable_searching: false,
|
||||||
data_collection: DataCollection::default(),
|
data_collection: DataCollection::default(),
|
||||||
search_state: AppSearchState::default(),
|
search_state: AppSearchState::default(),
|
||||||
|
delete_dialog_state: AppDeleteDialogState::default(),
|
||||||
|
help_dialog_state: AppHelpDialogState::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
self.reset_multi_tap_keys();
|
self.reset_multi_tap_keys();
|
||||||
self.show_help = false;
|
self.help_dialog_state.is_showing_help = false;
|
||||||
self.show_dd = false;
|
self.delete_dialog_state.is_showing_dd = false;
|
||||||
if self.enable_searching {
|
if self.enable_searching {
|
||||||
self.current_widget_selected = WidgetPosition::Process;
|
self.current_widget_selected = WidgetPosition::Process;
|
||||||
self.enable_searching = false;
|
self.enable_searching = false;
|
||||||
@ -204,8 +215,8 @@ impl App {
|
|||||||
pub fn on_esc(&mut self) {
|
pub fn on_esc(&mut self) {
|
||||||
self.reset_multi_tap_keys();
|
self.reset_multi_tap_keys();
|
||||||
if self.is_in_dialog() {
|
if self.is_in_dialog() {
|
||||||
self.show_help = false;
|
self.help_dialog_state.is_showing_help = false;
|
||||||
self.show_dd = false;
|
self.delete_dialog_state.is_showing_dd = false;
|
||||||
self.to_delete_process_list = None;
|
self.to_delete_process_list = None;
|
||||||
self.dd_err = None;
|
self.dd_err = None;
|
||||||
} else if self.enable_searching {
|
} else if self.enable_searching {
|
||||||
@ -220,7 +231,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_in_dialog(&self) -> bool {
|
fn is_in_dialog(&self) -> bool {
|
||||||
self.show_help || self.show_dd
|
self.help_dialog_state.is_showing_help || self.delete_dialog_state.is_showing_dd
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_grouping(&mut self) {
|
pub fn toggle_grouping(&mut self) {
|
||||||
@ -336,18 +347,21 @@ impl App {
|
|||||||
|
|
||||||
/// One of two functions allowed to run while in a dialog...
|
/// One of two functions allowed to run while in a dialog...
|
||||||
pub fn on_enter(&mut self) {
|
pub fn on_enter(&mut self) {
|
||||||
if self.show_dd {
|
if self.delete_dialog_state.is_showing_dd && self.delete_dialog_state.is_on_yes {
|
||||||
// If within dd...
|
// If within dd...
|
||||||
if self.dd_err.is_none() {
|
if self.dd_err.is_none() {
|
||||||
// Also ensure that we didn't just fail a dd...
|
// Also ensure that we didn't just fail a dd...
|
||||||
let dd_result = self.kill_highlighted_process();
|
let dd_result = self.kill_highlighted_process();
|
||||||
|
self.delete_dialog_state.is_on_yes = false;
|
||||||
if let Err(dd_err) = dd_result {
|
if let Err(dd_err) = dd_result {
|
||||||
// There was an issue... inform the user...
|
// There was an issue... inform the user...
|
||||||
self.dd_err = Some(dd_err.to_string());
|
self.dd_err = Some(dd_err.to_string());
|
||||||
} else {
|
} else {
|
||||||
self.show_dd = false;
|
self.delete_dialog_state.is_showing_dd = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
self.delete_dialog_state.is_showing_dd = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,6 +408,10 @@ impl App {
|
|||||||
self.search_state.current_cursor_position -= 1;
|
self.search_state.current_cursor_position -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if self.delete_dialog_state.is_showing_dd && !self.delete_dialog_state.is_on_yes {
|
||||||
|
self.delete_dialog_state.is_on_yes = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,6 +424,10 @@ impl App {
|
|||||||
self.search_state.current_cursor_position += 1;
|
self.search_state.current_cursor_position += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if self.delete_dialog_state.is_showing_dd && self.delete_dialog_state.is_on_yes {
|
||||||
|
self.delete_dialog_state.is_on_yes = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,7 +507,7 @@ impl App {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.to_delete_process_list = Some(current_process);
|
self.to_delete_process_list = Some(current_process);
|
||||||
self.show_dd = true;
|
self.delete_dialog_state.is_showing_dd = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.reset_multi_tap_keys();
|
self.reset_multi_tap_keys();
|
||||||
@ -567,7 +589,7 @@ impl App {
|
|||||||
self.currently_selected_process_position = 0;
|
self.currently_selected_process_position = 0;
|
||||||
}
|
}
|
||||||
'?' => {
|
'?' => {
|
||||||
self.show_help = true;
|
self.help_dialog_state.is_showing_help = true;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ impl Painter {
|
|||||||
) -> error::Result<()> {
|
) -> error::Result<()> {
|
||||||
terminal.autoresize()?;
|
terminal.autoresize()?;
|
||||||
terminal.draw(|mut f| {
|
terminal.draw(|mut f| {
|
||||||
if app_state.show_help {
|
if app_state.help_dialog_state.is_showing_help {
|
||||||
// Only for the help
|
// Only for the help
|
||||||
let vertical_dialog_chunk = Layout::default()
|
let vertical_dialog_chunk = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
@ -209,7 +209,7 @@ impl Painter {
|
|||||||
.alignment(Alignment::Left)
|
.alignment(Alignment::Left)
|
||||||
.wrap(true)
|
.wrap(true)
|
||||||
.render(&mut f, middle_dialog_chunk[1]);
|
.render(&mut f, middle_dialog_chunk[1]);
|
||||||
} else if app_state.show_dd {
|
} else if app_state.delete_dialog_state.is_showing_dd {
|
||||||
let vertical_dialog_chunk = Layout::default()
|
let vertical_dialog_chunk = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.margin(1)
|
.margin(1)
|
||||||
@ -245,7 +245,7 @@ impl Painter {
|
|||||||
Paragraph::new(dd_text.iter())
|
Paragraph::new(dd_text.iter())
|
||||||
.block(
|
.block(
|
||||||
Block::default()
|
Block::default()
|
||||||
.title(" Kill Process Error (Press Esc to close) ")
|
.title(" Error ")
|
||||||
.title_style(self.colours.text_style)
|
.title_style(self.colours.text_style)
|
||||||
.style(self.colours.border_style)
|
.style(self.colours.border_style)
|
||||||
.borders(Borders::ALL),
|
.borders(Borders::ALL),
|
||||||
@ -258,24 +258,42 @@ impl Painter {
|
|||||||
if let Some(first_pid) = to_kill_processes.1.first() {
|
if let Some(first_pid) = to_kill_processes.1.first() {
|
||||||
let dd_text = [
|
let dd_text = [
|
||||||
if app_state.is_grouped() {
|
if app_state.is_grouped() {
|
||||||
Text::raw(format!(
|
if to_kill_processes.1.len() != 1 {
|
||||||
"\nAre you sure you want to kill {} process(es) with name {}?",
|
Text::raw(format!(
|
||||||
to_kill_processes.1.len(), to_kill_processes.0
|
"\nAre you sure you want to kill {} processes with the name {}?",
|
||||||
))
|
to_kill_processes.1.len(), to_kill_processes.0
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
Text::raw(format!(
|
||||||
|
"\nAre you sure you want to kill {} process with the name {}?",
|
||||||
|
to_kill_processes.1.len(), to_kill_processes.0
|
||||||
|
))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Text::raw(format!(
|
Text::raw(format!(
|
||||||
"\nAre you sure you want to kill process {} with PID {}?",
|
"\nAre you sure you want to kill process {} with PID {}?",
|
||||||
to_kill_processes.0, first_pid
|
to_kill_processes.0, first_pid
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
Text::raw("\n\nPress ENTER to proceed, ESC to exit."),
|
Text::raw("\nNote that if bottom is frozen, it must be unfrozen for changes to be shown.\n\n"),
|
||||||
Text::raw("\nNote that if bottom is frozen, it must be unfrozen for changes to be shown."),
|
if app_state.delete_dialog_state.is_on_yes {
|
||||||
|
Text::styled("Yes", self.colours.currently_selected_text_style)
|
||||||
|
} else {
|
||||||
|
Text::raw("Yes")
|
||||||
|
},
|
||||||
|
Text::raw(" "),
|
||||||
|
if app_state.delete_dialog_state.is_on_yes {
|
||||||
|
Text::raw("No")
|
||||||
|
} else {
|
||||||
|
Text::styled("No", self.colours.currently_selected_text_style)
|
||||||
|
},
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
Paragraph::new(dd_text.iter())
|
Paragraph::new(dd_text.iter())
|
||||||
.block(
|
.block(
|
||||||
Block::default()
|
Block::default()
|
||||||
.title(" Kill Process Confirmation (Press Esc to close) ")
|
.title(" Confirm Kill Process ")
|
||||||
.title_style(self.colours.widget_title_style)
|
.title_style(self.colours.widget_title_style)
|
||||||
.style(self.colours.border_style)
|
.style(self.colours.border_style)
|
||||||
.borders(Borders::ALL),
|
.borders(Borders::ALL),
|
||||||
@ -286,11 +304,11 @@ impl Painter {
|
|||||||
.render(&mut f, middle_dialog_chunk[1]);
|
.render(&mut f, middle_dialog_chunk[1]);
|
||||||
} else {
|
} else {
|
||||||
// This is a bit nasty, but it works well... I guess.
|
// This is a bit nasty, but it works well... I guess.
|
||||||
app_state.show_dd = false;
|
app_state.delete_dialog_state.is_showing_dd = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This is a bit nasty, but it works well... I guess.
|
// This is a bit nasty, but it works well... I guess.
|
||||||
app_state.show_dd = false;
|
app_state.delete_dialog_state.is_showing_dd = false;
|
||||||
}
|
}
|
||||||
} 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user