diff options
-rw-r--r-- | src/app.rs | 20 | ||||
-rw-r--r-- | src/canvas.rs | 55 |
2 files changed, 41 insertions, 34 deletions
@@ -601,10 +601,10 @@ impl App { // CPU -(down)> MEM // MEM -(down)> Network, -(right)> TEMP // TEMP -(down)> Disk, -(left)> MEM, -(up)> CPU - // Disk -(down)> Processes OR PROC_SEARCH, -(left)> MEM, -(up)> TEMP + // Disk -(down)> Processes, -(left)> MEM, -(up)> TEMP // Network -(up)> MEM, -(right)> PROC - // PROC -(up)> Disk OR PROC_SEARCH if enabled, -(left)> Network - // PROC_SEARCH -(up)> Disk, -(down)> PROC, -(left)> Network + // PROC -(up)> Disk, -(down)> PROC_SEARCH, -(left)> Network + // PROC_SEARCH -(up)> PROC, -(left)> Network pub fn move_left(&mut self) { if !self.is_in_dialog() { self.current_widget_selected = match self.current_widget_selected { @@ -634,14 +634,8 @@ impl App { self.current_widget_selected = match self.current_widget_selected { WidgetPosition::Mem => WidgetPosition::Cpu, WidgetPosition::Network => WidgetPosition::Mem, - WidgetPosition::Process => { - if self.is_searching() { - WidgetPosition::ProcessSearch - } else { - WidgetPosition::Disk - } - } - WidgetPosition::ProcessSearch => WidgetPosition::Disk, + WidgetPosition::Process => WidgetPosition::Disk, + WidgetPosition::ProcessSearch => WidgetPosition::Process, WidgetPosition::Temp => WidgetPosition::Cpu, WidgetPosition::Disk => WidgetPosition::Temp, _ => self.current_widget_selected, @@ -656,14 +650,14 @@ impl App { WidgetPosition::Cpu => WidgetPosition::Mem, WidgetPosition::Mem => WidgetPosition::Network, WidgetPosition::Temp => WidgetPosition::Disk, - WidgetPosition::Disk => { + WidgetPosition::Disk => WidgetPosition::Process, + WidgetPosition::Process => { if self.is_searching() { WidgetPosition::ProcessSearch } else { WidgetPosition::Process } } - WidgetPosition::ProcessSearch => WidgetPosition::Process, _ => self.current_widget_selected, }; self.reset_multi_tap_keys(); diff --git a/src/canvas.rs b/src/canvas.rs index b41ca8a6..6bbbb849 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -897,33 +897,46 @@ fn draw_search_field<B: backend::Backend>( &query[(query.len() - width as usize)..] }; - // TODO: [SEARCH] Consider making this look prettier let cursor_position = app_state.get_cursor_position(); - // TODO: [SEARCH] This can be optimized... if the cursor is at the very end or not focused we can skip this - let mut query_with_cursor: Vec<Text> = shrunk_query - .chars() - .enumerate() - .map(|(itx, c)| { - if let app::WidgetPosition::ProcessSearch = app_state.current_widget_selected { - if itx == cursor_position { - return Text::styled( - c.to_string(), - Style::default().fg(TEXT_COLOUR).bg(TABLE_HEADER_COLOUR), - ); - } - } - Text::styled(c.to_string(), Style::default().fg(TEXT_COLOUR)) - }) - .collect::<Vec<_>>(); - if let app::WidgetPosition::ProcessSearch = app_state.current_widget_selected { + let query_with_cursor: Vec<Text> = if let app::WidgetPosition::ProcessSearch = + app_state.current_widget_selected + { if cursor_position >= query.len() { - query_with_cursor.push(Text::styled( + let mut q = vec![Text::styled( + shrunk_query.to_string(), + Style::default().fg(TEXT_COLOUR), + )]; + + q.push(Text::styled( " ".to_string(), Style::default().fg(TEXT_COLOUR).bg(TABLE_HEADER_COLOUR), - )) + )); + + q + } else { + shrunk_query + .chars() + .enumerate() + .map(|(itx, c)| { + if let app::WidgetPosition::ProcessSearch = app_state.current_widget_selected { + if itx == cursor_position { + return Text::styled( + c.to_string(), + Style::default().fg(TEXT_COLOUR).bg(TABLE_HEADER_COLOUR), + ); + } + } + Text::styled(c.to_string(), Style::default().fg(TEXT_COLOUR)) + }) + .collect::<Vec<_>>() } - } + } else { + vec![Text::styled( + shrunk_query.to_string(), + Style::default().fg(TEXT_COLOUR), + )] + }; let mut search_text = vec![if app_state.search_state.is_searching_with_pid() { Text::styled( |