diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 66 | ||||
-rw-r--r-- | src/canvas.rs | 15 | ||||
-rw-r--r-- | src/main.rs | 4 |
3 files changed, 42 insertions, 43 deletions
@@ -9,7 +9,7 @@ use crate::{canvas, constants, data_conversion::ConvertedProcessData, utils::err mod process_killer; -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub enum WidgetPosition { Cpu, Mem, @@ -86,7 +86,7 @@ pub struct App { enable_searching: bool, current_search_query: String, searching_pid: bool, - pub use_simple: bool, + pub ignore_case: bool, current_regex: std::result::Result<regex::Regex, regex::Error>, current_cursor_position: usize, pub data_collection: DataCollection, @@ -132,7 +132,7 @@ impl App { enable_searching: false, current_search_query: String::default(), searching_pid: false, - use_simple: false, + ignore_case: false, current_regex: BASE_REGEX.clone(), //TODO: [OPT] seems like a thing we can switch to lifetimes to avoid cloning current_cursor_position: 0, data_collection: DataCollection::default(), @@ -246,26 +246,28 @@ impl App { &self.current_search_query } - pub fn toggle_simple_search(&mut self) { + pub fn toggle_ignore_case(&mut self) { if !self.is_in_dialog() && self.is_searching() { if let WidgetPosition::ProcessSearch = self.current_widget_selected { - self.use_simple = !self.use_simple; - - // Update to latest (when simple is on this is not updated) - if !self.use_simple { - self.current_regex = if self.current_search_query.is_empty() { - BASE_REGEX.clone() - } else { - regex::Regex::new(&(self.current_search_query)) - }; - } - - // Force update to process display in GUI + self.ignore_case = !self.ignore_case; + self.update_regex(); self.update_process_gui = true; } } } + fn update_regex(&mut self) { + self.current_regex = if self.current_search_query.is_empty() { + BASE_REGEX.clone() + } else if self.ignore_case { + regex::Regex::new(&(format!("(?i){}", self.current_search_query))) + } else { + regex::Regex::new(&(self.current_search_query)) + }; + self.previous_process_position = 0; + self.currently_selected_process_position = 0; + } + pub fn get_cursor_position(&self) -> usize { self.current_cursor_position } @@ -294,13 +296,7 @@ impl App { self.current_search_query .remove(self.current_cursor_position); - if !self.use_simple { - self.current_regex = if self.current_search_query.is_empty() { - BASE_REGEX.clone() - } else { - regex::Regex::new(&(self.current_search_query)) - }; - } + self.update_regex(); self.update_process_gui = true; } } @@ -381,13 +377,8 @@ impl App { .insert(self.current_cursor_position, caught_char); self.current_cursor_position += 1; - if !self.use_simple { - self.current_regex = if self.current_search_query.is_empty() { - BASE_REGEX.clone() - } else { - regex::Regex::new(&(self.current_search_query)) - }; - } + self.update_regex(); + self.update_process_gui = true; } else { match caught_char { @@ -401,7 +392,7 @@ impl App { self.second_char = ' '; let current_process = Vec::new(); - // TODO: FIX THIS SHITTTTTT + // TODO: Fix self.to_delete_process_list = Some(current_process); self.show_dd = true; @@ -607,14 +598,15 @@ impl App { match self.current_widget_selected { WidgetPosition::Process => { self.currently_selected_process_position = - self.data.list_of_processes.len() as i64 - 1 + self.canvas_data.finalized_process_data.len() as i64 - 1 } WidgetPosition::Temp => { self.currently_selected_temperature_position = - self.data.temperature_sensors.len() as i64 - 1 + self.canvas_data.temp_sensor_data.len() as i64 - 1 } WidgetPosition::Disk => { - self.currently_selected_disk_position = self.data.disks.len() as i64 - 1 + self.currently_selected_disk_position = + self.canvas_data.disk_data.len() as i64 - 1 } WidgetPosition::Cpu => { self.currently_selected_cpu_table_position = @@ -667,7 +659,7 @@ impl App { fn change_process_position(&mut self, num_to_change_by: i64) { if self.currently_selected_process_position + num_to_change_by >= 0 && self.currently_selected_process_position + num_to_change_by - < self.data.list_of_processes.len() as i64 + < self.canvas_data.finalized_process_data.len() as i64 { self.currently_selected_process_position += num_to_change_by; } @@ -676,7 +668,7 @@ impl App { fn change_temp_position(&mut self, num_to_change_by: i64) { if self.currently_selected_temperature_position + num_to_change_by >= 0 && self.currently_selected_temperature_position + num_to_change_by - < self.data.temperature_sensors.len() as i64 + < self.canvas_data.temp_sensor_data.len() as i64 { self.currently_selected_temperature_position += num_to_change_by; } @@ -685,7 +677,7 @@ impl App { fn change_disk_position(&mut self, num_to_change_by: i64) { if self.currently_selected_disk_position + num_to_change_by >= 0 && self.currently_selected_disk_position + num_to_change_by - < self.data.disks.len() as i64 + < self.canvas_data.disk_data.len() as i64 { self.currently_selected_disk_position += num_to_change_by; } diff --git a/src/canvas.rs b/src/canvas.rs index 093e6815..c4138f29 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -912,10 +912,10 @@ fn draw_search_field<B: backend::Backend>( } else { Text::styled("\nName", Style::default().fg(TABLE_HEADER_COLOUR)) }, - if app_state.use_simple { - Text::styled(" (Simple): ", Style::default().fg(TABLE_HEADER_COLOUR)) + if app_state.ignore_case { + Text::styled(" (Ignore Case): ", Style::default().fg(TABLE_HEADER_COLOUR)) } else { - Text::styled(" (Regex): ", Style::default().fg(TABLE_HEADER_COLOUR)) + Text::styled(": ", Style::default().fg(TABLE_HEADER_COLOUR)) }, ]; @@ -957,13 +957,20 @@ fn draw_processes_table<B: backend::Backend>( // do so by hiding some elements! let num_rows = i64::from(draw_loc.height) - 5; - let start_position = get_start_position( + let position = get_start_position( num_rows, &(app_state.scroll_direction), &mut app_state.previous_process_position, app_state.currently_selected_process_position, ); + // Sanity check + let start_position = if position >= process_data.len() as i64 { + std::cmp::max(0, process_data.len() as i64 - 1) + } else { + position + }; + let sliced_vec: Vec<ConvertedProcessData> = (&process_data[start_position as usize..]).to_vec(); let mut process_counter = 0; diff --git a/src/main.rs b/src/main.rs index 9d739ea0..ae3df136 100644 --- a/src/main.rs +++ b/src/main.rs @@ -131,7 +131,7 @@ fn main() -> error::Result<()> { // Set default search method if matches.is_present("CASE_INSENSITIVE_DEFAULT") { - app.use_simple = true; + app.ignore_case = true; } // Set up up tui and crossterm @@ -256,7 +256,7 @@ fn main() -> error::Result<()> { } } // TODO: [SEARCH] Rename "simple" search to just... search without cases... - KeyCode::Char('s') => app.toggle_simple_search(), + KeyCode::Char('s') => app.toggle_ignore_case(), KeyCode::Char('a') => app.skip_cursor_beginning(), KeyCode::Char('e') => app.skip_cursor_end(), _ => {} |