Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 80 additions & 18 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,17 @@ impl App {
self.process_kill_dialog.on_esc();
self.is_force_redraw = true;
} else if self.help_dialog_state.is_showing_help {
self.help_dialog_state.is_showing_help = false;
self.help_dialog_state.scroll_state.current_scroll_index = 0;
self.is_force_redraw = true;
if self.help_dialog_state.is_searching {
// Exit help search mode first; keep help dialog open
self.help_dialog_state.is_searching = false;
self.help_dialog_state.search_query.clear();
self.help_dialog_state.search_cursor_index = 0;
self.is_force_redraw = true;
} else {
self.help_dialog_state.is_showing_help = false;
self.help_dialog_state.scroll_state.current_scroll_index = 0;
self.is_force_redraw = true;
}
} else {
match self.current_widget.widget_type {
BottomWidgetType::Proc => {
Expand Down Expand Up @@ -455,6 +463,9 @@ impl App {
if self.process_kill_dialog.is_open() {
// Not the best way of doing things for now but works as glue.
self.process_kill_dialog.on_enter();
} else if self.help_dialog_state.is_showing_help && self.help_dialog_state.is_searching {
// Do not close help when searching; just trigger a redraw
self.is_force_redraw = true;
} else if !self.is_in_dialog() {
match self.current_widget.widget_type {
BottomWidgetType::ProcSearch => {
Expand Down Expand Up @@ -490,6 +501,15 @@ impl App {
}

pub fn on_delete(&mut self) {
if self.help_dialog_state.is_showing_help && self.help_dialog_state.is_searching {
let len = self.help_dialog_state.search_query.len();
let idx = self.help_dialog_state.search_cursor_index.min(len);
if idx < len {
self.help_dialog_state.search_query.remove(idx);
}
self.is_force_redraw = true;
return;
}
match self.current_widget.widget_type {
BottomWidgetType::ProcSearch => {
let is_in_search_widget = self.is_in_search_widget();
Expand Down Expand Up @@ -540,7 +560,14 @@ impl App {
}

pub fn on_backspace(&mut self) {
if let BottomWidgetType::ProcSearch = self.current_widget.widget_type {
if self.help_dialog_state.is_showing_help && self.help_dialog_state.is_searching {
if self.help_dialog_state.search_cursor_index > 0 {
let idx = self.help_dialog_state.search_cursor_index - 1;
self.help_dialog_state.search_query.remove(idx);
self.help_dialog_state.search_cursor_index = idx;
}
self.is_force_redraw = true;
} else if let BottomWidgetType::ProcSearch = self.current_widget.widget_type {
let is_in_search_widget = self.is_in_search_widget();
if let Some(proc_widget_state) = self
.states
Expand Down Expand Up @@ -607,6 +634,15 @@ impl App {
}

pub fn on_left_key(&mut self) {
// Move help search cursor left if searching in help dialog
if self.help_dialog_state.is_showing_help && self.help_dialog_state.is_searching {
if self.help_dialog_state.search_cursor_index > 0 {
self.help_dialog_state.search_cursor_index -= 1;
self.is_force_redraw = true;
}
return;
}

if !self.is_in_dialog() {
match self.current_widget.widget_type {
BottomWidgetType::Proc => {
Expand Down Expand Up @@ -655,6 +691,16 @@ impl App {
}

pub fn on_right_key(&mut self) {
// Move help search cursor right if searching in help dialog
if self.help_dialog_state.is_showing_help && self.help_dialog_state.is_searching {
let len = self.help_dialog_state.search_query.len();
if self.help_dialog_state.search_cursor_index < len {
self.help_dialog_state.search_cursor_index += 1;
self.is_force_redraw = true;
}
return;
}

if !self.is_in_dialog() {
match self.current_widget.widget_type {
BottomWidgetType::Proc => {
Expand Down Expand Up @@ -720,9 +766,8 @@ impl App {
proc_widget_state.toggle_current_tree_branch_entry();
}
}
} else if self.process_kill_dialog.is_open() {
// Either select the current option,
// or scroll to the next one
} else if self.help_dialog_state.is_showing_help && self.help_dialog_state.is_searching {
self.on_char_key(' ');
}
}

Expand Down Expand Up @@ -992,20 +1037,37 @@ impl App {
}
self.handle_char(caught_char);
} else if self.help_dialog_state.is_showing_help {
match caught_char {
'1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => {
let potential_index = caught_char.to_digit(10);
if let Some(potential_index) = potential_index {
let potential_index = potential_index as usize;
if (potential_index) < self.help_dialog_state.index_shortcuts.len() {
self.help_scroll_to_or_max(
self.help_dialog_state.index_shortcuts[potential_index],
);
if self.help_dialog_state.is_searching {
let idx = self
.help_dialog_state
.search_cursor_index
.min(self.help_dialog_state.search_query.len());
self.help_dialog_state.search_query.insert(idx, caught_char);
self.help_dialog_state.search_cursor_index = idx + 1;
self.is_force_redraw = true;
} else {
match caught_char {
'1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => {
let potential_index = caught_char.to_digit(10);
if let Some(potential_index) = potential_index {
let potential_index = potential_index as usize;
if (potential_index) < self.help_dialog_state.index_shortcuts.len() {
self.help_scroll_to_or_max(
self.help_dialog_state.index_shortcuts[potential_index],
);
}
}
}
'j' | 'k' | 'g' | 'G' => self.handle_char(caught_char),
'/' => {
// Start help dialog search; place cursor at end of current query
self.help_dialog_state.is_searching = true;
self.help_dialog_state.search_cursor_index =
self.help_dialog_state.search_query.len();
self.is_force_redraw = true;
}
_ => {}
}
'j' | 'k' | 'g' | 'G' => self.handle_char(caught_char),
_ => {}
}
} else if self.process_kill_dialog.is_open() {
self.process_kill_dialog.on_char(caught_char);
Expand Down
6 changes: 6 additions & 0 deletions src/app/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub struct AppHelpDialogState {
pub height: u16,
pub scroll_state: ParagraphScrollState,
pub index_shortcuts: Vec<u16>,
pub is_searching: bool,
pub search_query: String,
pub search_cursor_index: usize,
}

impl Default for AppHelpDialogState {
Expand All @@ -45,6 +48,9 @@ impl Default for AppHelpDialogState {
height: 0,
scroll_state: ParagraphScrollState::default(),
index_shortcuts: vec![0; constants::HELP_TEXT.len()],
is_searching: false,
search_query: String::new(),
search_cursor_index: 0,
}
}
}
Expand Down
Loading