summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClementTsang <cjhtsang@uwaterloo.ca>2020-02-09 17:11:57 -0500
committerClementTsang <cjhtsang@uwaterloo.ca>2020-02-09 17:11:57 -0500
commit909fbd3571f2981ccb80c681376682316eacf9f1 (patch)
tree05c580e3032f95e71cd6a8ca7afb33236da33c51 /src
parent30f69e2ee01824427fa75a4592155db8127b3c3b (diff)
Made the dd screen prettier.
Diffstat (limited to 'src')
-rw-r--r--src/app.rs48
-rw-r--r--src/canvas.rs42
2 files changed, 65 insertions, 25 deletions
diff --git a/src/app.rs b/src/app.rs
index 3f189adf..563a68e2 100644
--- a/src/app.rs
+++ b/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
pub struct App {
// Sorting
@@ -129,8 +140,6 @@ pub struct App {
awaiting_second_char: bool,
second_char: char,
pub use_dot: bool,
- pub show_help: bool,
- pub show_dd: bool,
pub dd_err: Option<String>,
to_delete_process_list: Option<(String, Vec<u32>)>,
pub is_frozen: bool,
@@ -142,6 +151,8 @@ pub struct App {
enable_searching: bool,
pub data_collection: DataCollection,
pub search_state: AppSearchState,
+ pub delete_dialog_state: AppDeleteDialogState,
+ pub help_dialog_state: AppHelpDialogState,
}
impl App {
@@ -171,8 +182,6 @@ impl App {
awaiting_second_char: false,
second_char: ' ',
use_dot,
- show_help: false,
- show_dd: false,
dd_err: None,
to_delete_process_list: None,
is_frozen: false,
@@ -184,13 +193,15 @@ impl App {
enable_searching: false,
data_collection: DataCollection::default(),
search_state: AppSearchState::default(),
+ delete_dialog_state: AppDeleteDialogState::default(),
+ help_dialog_state: AppHelpDialogState::default(),
}
}
pub fn reset(&mut self) {
self.reset_multi_tap_keys();
- self.show_help = false;
- self.show_dd = false;
+ self.help_dialog_state.is_showing_help = false;
+ self.delete_dialog_state.is_showing_dd = false;
if self.enable_searching {
self.current_widget_selected = WidgetPosition::Process;
self.enable_searching = false;
@@ -204,8 +215,8 @@ impl App {
pub fn on_esc(&mut self) {
self.reset_multi_tap_keys();
if self.is_in_dialog() {
- self.show_help = false;
- self.show_dd = false;
+ self.help_dialog_state.is_showing_help = false;
+ self.delete_dialog_state.is_showing_dd = false;
self.to_delete_process_list = None;
self.dd_err = None;
} else if self.enable_searching {
@@ -220,7 +231,7 @@ impl App {
}
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) {
@@ -336,18 +347,21 @@ impl App {
/// One of two functions allowed to run while in a dialog...
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 self.dd_err.is_none() {
// Also ensure that we didn't just fail a dd...
let dd_result = self.kill_highlighted_process();
+ self.delete_dialog_state.is_on_yes = false;
if let Err(dd_err) = dd_result {
// There was an issue... inform the user...
self.dd_err = Some(dd_err.to_string());
} 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;
}
}
+ } 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;
}
}
+ } 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.show_dd = true;
+ self.delete_dialog_state.is_showing_dd = true;
}
self.reset_multi_tap_keys();
@@ -567,7 +589,7 @@ impl App {
self.currently_selected_process_position = 0;
}
'?' => {
- self.show_help = true;
+ self.help_dialog_state.is_showing_help = true;
}
_ => {}
}
diff --git a/src/canvas.rs b/src/canvas.rs
index fbbdbc39..2ba08d02 100644
--- a/src/canvas.rs
+++ b/src/canvas.rs
@@ -169,7 +169,7 @@ impl Painter {
) -> error::Result<()> {
terminal.autoresize()?;
terminal.draw(|mut f| {
- if app_state.show_help {
+ if app_state.help_dialog_state.is_showing_help {
// Only for the help
let vertical_dialog_chunk = Layout::default()
.direction(Direction::Vertical)
@@ -209,7 +209,7 @@ impl Painter {
.alignment(Alignment::Left)
.wrap(true)
.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()
.direction(Direction::Vertical)
.margin(1)
@@ -245,7 +245,7 @@ impl Painter {
Paragraph::new(dd_text.iter())
.block(
Block::default()
- .title(" Kill Process Error (Press Esc to close) ")
+ .title(" Error ")
.title_style(self.colours.text_style)
.style(self.colours.border_style)
.borders(Borders::ALL),
@@ -258,24 +258,42 @@ impl Painter {
if let Some(first_pid) = to_kill_processes.1.first() {
let dd_text = [
if app_state.is_grouped() {
- Text::raw(format!(
- "\nAre you sure you want to kill {} process(es) with name {}?",
- to_kill_processes.1.len(), to_kill_processes.0
- ))
+ if to_kill_processes.1.len() != 1 {
+ Text::raw(format!(
+ "\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 {
Text::raw(format!(
"\nAre you sure you want to kill process {} with 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."),
+ Text::raw("\nNote that if bottom is frozen, it must be unfrozen for changes to be shown.\n\n"),
+ 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())
.block(
Block::default()
- .title(" Kill Process Confirmation (Press Esc to close) ")
+ .title(" Confirm Kill Process ")
.title_style(self.colours.widget_title_style)
.style(self.colours.border_style)
.borders(Borders::ALL),
@@ -286,11 +304,11 @@ impl Painter {
.render(&mut f, middle_dialog_chunk[1]);
} else {
// 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 {
// 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 {
// TODO: [TUI] Change this back to a more even 33/33/34 when TUI releases