summaryrefslogtreecommitdiffstats
path: root/src/app/widgets
diff options
context:
space:
mode:
authorClementTsang <cjhtsang@uwaterloo.ca>2021-09-26 01:18:03 -0400
committerClementTsang <cjhtsang@uwaterloo.ca>2021-09-26 01:54:59 -0400
commit9089231bc46e9732aac522be89877dcd53a06c6d (patch)
tree9db62c188b8c20116e07adf63fcec7ba1f162383 /src/app/widgets
parentb6ca3e0a2274a49b512e8332cb107f8419c9d993 (diff)
refactor: delete more stuff
Mostly previously re-added files during the merge conflict resolution, and a lot of unused code. Still more to delete after I finish rewriting the process kill dialog.
Diffstat (limited to 'src/app/widgets')
-rw-r--r--src/app/widgets/base/scrollable.rs2
-rw-r--r--src/app/widgets/base/sort_text_table.rs2
-rw-r--r--src/app/widgets/base/text_input.rs4
-rw-r--r--src/app/widgets/base/text_table.rs4
-rw-r--r--src/app/widgets/base/time_graph.rs2
-rw-r--r--src/app/widgets/bottom_widgets/basic_mem.rs2
-rw-r--r--src/app/widgets/bottom_widgets/battery.rs22
-rw-r--r--src/app/widgets/bottom_widgets/cpu.rs32
-rw-r--r--src/app/widgets/bottom_widgets/disk.rs30
-rw-r--r--src/app/widgets/bottom_widgets/mem.rs13
-rw-r--r--src/app/widgets/bottom_widgets/net.rs15
-rw-r--r--src/app/widgets/bottom_widgets/process.rs551
-rw-r--r--src/app/widgets/bottom_widgets/temp.rs40
-rw-r--r--src/app/widgets/dialogs/help.rs2
14 files changed, 23 insertions, 698 deletions
diff --git a/src/app/widgets/base/scrollable.rs b/src/app/widgets/base/scrollable.rs
index b8652a9f..5d5620ae 100644
--- a/src/app/widgets/base/scrollable.rs
+++ b/src/app/widgets/base/scrollable.rs
@@ -57,7 +57,7 @@ impl Scrollable {
scroll_direction: ScrollDirection::Down,
num_items,
tui_state,
- gg_manager: MultiKey::register(vec!['g', 'g']), // TODO: Use a static arrayvec
+ gg_manager: MultiKey::register(vec!['g', 'g']), // TODO: [Optimization] Use a static arrayvec
bounds: Rect::default(),
}
}
diff --git a/src/app/widgets/base/sort_text_table.rs b/src/app/widgets/base/sort_text_table.rs
index f1f3b0e4..c8ff4d41 100644
--- a/src/app/widgets/base/sort_text_table.rs
+++ b/src/app/widgets/base/sort_text_table.rs
@@ -5,7 +5,7 @@ use tui::{backend::Backend, layout::Rect, Frame};
use crate::{
app::{
- event::{ReturnSignal, ComponentEventResult},
+ event::{ComponentEventResult, ReturnSignal},
widgets::tui_stuff::BlockBuilder,
Component, TextTable,
},
diff --git a/src/app/widgets/base/text_input.rs b/src/app/widgets/base/text_input.rs
index 32106a15..2b0d0036 100644
--- a/src/app/widgets/base/text_input.rs
+++ b/src/app/widgets/base/text_input.rs
@@ -262,7 +262,7 @@ impl TextInput {
let after_cursor = graphemes.map(|(_, grapheme)| grapheme).collect::<String>();
- // FIXME: This is NOT done! This is an incomplete (but kinda working) implementation, for now.
+ // FIXME: [AFTER REFACTOR] This is NOT done! This is an incomplete (but kinda working) implementation, for now.
let search_text = vec![Spans::from(vec![
Span::styled(
@@ -365,10 +365,10 @@ impl Component for TextInput {
fn handle_mouse_event(&mut self, _event: MouseEvent) -> ComponentEventResult {
// We are assuming this is within bounds...
+ // TODO: [Feature] Add mouse input for text input cursor
// let x = event.column;
// let widget_x = self.bounds.x + 2;
// if x >= widget_x {
- // // TODO: Do this at some point after refactor
// ComponentEventResult::Redraw
// } else {
// ComponentEventResult::NoRedraw
diff --git a/src/app/widgets/base/text_table.rs b/src/app/widgets/base/text_table.rs
index e6d42001..e8281b78 100644
--- a/src/app/widgets/base/text_table.rs
+++ b/src/app/widgets/base/text_table.rs
@@ -46,8 +46,6 @@ pub type TextTableDataRef = [Vec<(Cow<'static, str>, Option<Cow<'static, str>>,
#[derive(Debug)]
pub struct SimpleColumn {
name: Cow<'static, str>,
-
- // TODO: I would remove these in the future, storing them here feels weird...
desired_width: DesiredColumnWidth,
x_bounds: Option<(u16, u16)>,
}
@@ -130,7 +128,7 @@ where
pub show_gap: bool,
/// The bounding box of the [`TextTable`].
- pub bounds: Rect, // TODO: Consider moving bounds to something else?
+ pub bounds: Rect, // TODO: [Refactor, Drawing] Consider moving bounds to something else?
/// The bounds including the border, if there is one.
pub border_bounds: Rect,
diff --git a/src/app/widgets/base/time_graph.rs b/src/app/widgets/base/time_graph.rs
index 47436f71..cc2a8c69 100644
--- a/src/app/widgets/base/time_graph.rs
+++ b/src/app/widgets/base/time_graph.rs
@@ -45,7 +45,7 @@ pub enum AutohideTimer {
},
}
-// TODO: [AUTOHIDE] Not a fan of how this is done, as this should really "trigger" a draw when it's done.
+// TODO: [Refactor] Not a fan of how autohide is currently done, as this should really "trigger" a draw when it's done. Maybe use async/threads?
impl AutohideTimer {
fn start_display_timer(&mut self) {
match self {
diff --git a/src/app/widgets/bottom_widgets/basic_mem.rs b/src/app/widgets/bottom_widgets/basic_mem.rs
index 3658ee7c..5b151001 100644
--- a/src/app/widgets/bottom_widgets/basic_mem.rs
+++ b/src/app/widgets/bottom_widgets/basic_mem.rs
@@ -128,7 +128,7 @@ impl Widget for BasicMem {
fn update_data(&mut self, data_collection: &DataCollection) {
let (memory_labels, swap_labels) = convert_mem_labels(data_collection);
- // TODO: [Data update optimization] Probably should just make another function altogether for basic mode.
+ // TODO: [Optimization] Probably should just make another function altogether for just basic mem mode.
self.mem_data = if let (Some(data), Some((_, fraction))) = (
convert_mem_data_points(data_collection).last(),
memory_labels,
diff --git a/src/app/widgets/bottom_widgets/battery.rs b/src/app/widgets/bottom_widgets/battery.rs
index 8c1d0721..1f9b1a88 100644
--- a/src/app/widgets/bottom_widgets/battery.rs
+++ b/src/app/widgets/bottom_widgets/battery.rs
@@ -1,7 +1,4 @@
-use std::{
- cmp::{max, min},
- collections::HashMap,
-};
+use std::cmp::{max, min};
use crossterm::event::{KeyCode, KeyEvent, MouseEvent};
use tui::{
@@ -23,23 +20,6 @@ use crate::{
options::layout_options::LayoutRule,
};
-#[derive(Default)]
-pub struct BatteryWidgetState {
- pub currently_selected_battery_index: usize,
- pub tab_click_locs: Option<Vec<((u16, u16), (u16, u16))>>,
-}
-
-#[derive(Default)]
-pub struct BatteryState {
- pub widget_states: HashMap<u64, BatteryWidgetState>,
-}
-
-impl BatteryState {
- pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut BatteryWidgetState> {
- self.widget_states.get_mut(&widget_id)
- }
-}
-
/// A table displaying battery information on a per-battery basis.
pub struct BatteryTable {
bounds: Rect,
diff --git a/src/app/widgets/bottom_widgets/cpu.rs b/src/app/widgets/bottom_widgets/cpu.rs
index 6e5e18a5..d82f8500 100644
--- a/src/app/widgets/bottom_widgets/cpu.rs
+++ b/src/app/widgets/bottom_widgets/cpu.rs
@@ -1,4 +1,4 @@
-use std::{borrow::Cow, collections::HashMap, time::Instant};
+use std::borrow::Cow;
use crossterm::event::{KeyEvent, MouseEvent};
use tui::{
@@ -12,39 +12,13 @@ use crate::{
event::{ComponentEventResult, SelectionAction},
text_table::SimpleColumn,
time_graph::TimeGraphData,
- AppConfigFields, AppScrollWidgetState, CanvasTableWidthState, Component, DataCollection,
- TextTable, TimeGraph, Widget,
+ AppConfigFields, Component, DataCollection, TextTable, TimeGraph, Widget,
},
canvas::Painter,
data_conversion::{convert_cpu_data_points, ConvertedCpuData},
options::layout_options::LayoutRule,
};
-pub struct CpuWidgetState {
- pub current_display_time: u64,
- pub is_legend_hidden: bool,
- pub autohide_timer: Option<Instant>,
- pub scroll_state: AppScrollWidgetState,
- pub is_multi_graph_mode: bool,
- pub table_width_state: CanvasTableWidthState,
-}
-
-#[derive(Default)]
-pub struct CpuState {
- pub force_update: Option<u64>,
- pub widget_states: HashMap<u64, CpuWidgetState>,
-}
-
-impl CpuState {
- pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut CpuWidgetState> {
- self.widget_states.get_mut(&widget_id)
- }
-
- pub fn get_widget_state(&self, widget_id: u64) -> Option<&CpuWidgetState> {
- self.widget_states.get(&widget_id)
- }
-}
-
/// Which part of the [`CpuGraph`] is currently selected.
enum CpuGraphSelection {
Graph,
@@ -228,7 +202,7 @@ impl Widget for CpuGraph {
})
.collect::<Vec<_>>();
- // TODO: You MUST draw the table first, otherwise the index may mismatch after a reset. This is a bad gotcha - we should look into auto-updating the table's length!
+ // TODO: [Gotcha, Refactor] You MUST draw the table first, otherwise the index may mismatch after a reset. This is a bad gotcha - we should look into auto-updating the table's length!
self.legend.draw_tui_table(
painter,
f,
diff --git a/src/app/widgets/bottom_widgets/disk.rs b/src/app/widgets/bottom_widgets/disk.rs
index 74b63f86..c3ec8bcd 100644
--- a/src/app/widgets/bottom_widgets/disk.rs
+++ b/src/app/widgets/bottom_widgets/disk.rs
@@ -1,43 +1,17 @@
-use std::collections::HashMap;
-
use crossterm::event::{KeyEvent, MouseEvent};
use tui::{backend::Backend, layout::Rect, widgets::Borders, Frame};
use crate::{
app::{
data_farmer::DataCollection, event::ComponentEventResult,
- sort_text_table::SimpleSortableColumn, text_table::TextTableData, AppScrollWidgetState,
- CanvasTableWidthState, Component, TextTable, Widget,
+ sort_text_table::SimpleSortableColumn, text_table::TextTableData, Component, TextTable,
+ Widget,
},
canvas::Painter,
data_conversion::convert_disk_row,
options::layout_options::LayoutRule,
};
-pub struct DiskWidgetState {
- pub scroll_state: AppScrollWidgetState,
- pub table_width_state: CanvasTableWidthState,
-}
-
-#[derive(Default)]
-pub struct DiskState {
- pub widget_states: HashMap<u64, DiskWidgetState>,
-}
-
-impl DiskState {
- pub fn init(widget_states: HashMap<u64, DiskWidgetState>) -> Self {
- DiskState { widget_states }
- }
-
- pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut DiskWidgetState> {
- self.widget_states.get_mut(&widget_id)
- }
-
- pub fn get_widget_state(&self, widget_id: u64) -> Option<&DiskWidgetState> {
- self.widget_states.get(&widget_id)
- }
-}
-
/// A table displaying disk data.
pub struct DiskTable {
table: TextTable<SimpleSortableColumn>,
diff --git a/src/app/widgets/bottom_widgets/mem.rs b/src/app/widgets/bottom_widgets/mem.rs
index 465e3ab9..c4ada423 100644
--- a/src/app/widgets/bottom_widgets/mem.rs
+++ b/src/app/widgets/bottom_widgets/mem.rs
@@ -1,4 +1,4 @@
-use std::{borrow::Cow, collections::HashMap, time::Instant};
+use std::borrow::Cow;
use crossterm::event::{KeyEvent, MouseEvent};
use tui::{backend::Backend, layout::Rect};
@@ -10,17 +10,6 @@ use crate::{
options::layout_options::LayoutRule,
};
-pub struct MemWidgetState {
- pub current_display_time: u64,
- pub autohide_timer: Option<Instant>,
-}
-
-#[derive(Default)]
-pub struct MemState {
- pub force_update: Option<u64>,
- pub widget_states: HashMap<u64, MemWidgetState>,
-}
-
/// A widget that deals with displaying memory usage on a [`TimeGraph`]. Basically just a wrapper
/// around [`TimeGraph`] as of now.
pub struct MemGraph {
diff --git a/src/app/widgets/bottom_widgets/net.rs b/src/app/widgets/bottom_widgets/net.rs
index 1449aa6a..4be88045 100644
--- a/src/app/widgets/bottom_widgets/net.rs
+++ b/src/app/widgets/bottom_widgets/net.rs
@@ -1,4 +1,4 @@
-use std::{borrow::Cow, collections::HashMap, time::Instant};
+use std::borrow::Cow;
use crossterm::event::{KeyEvent, MouseEvent};
use tui::{
@@ -20,19 +20,6 @@ use crate::{
utils::gen_util::*,
};
-pub struct NetWidgetState {
- pub current_display_time: u64,
- pub autohide_timer: Option<Instant>,
-}
-
-#[derive(Default)]
-pub struct NetState {
- pub force_update: Option<u64>,
- pub widget_states: HashMap<u64, NetWidgetState>,
-}
-
-// --- NEW STUFF BELOW ---
-
/// Returns the max data point and time given a time.
fn get_max_entry(
rx: &[(f64, f64)], tx: &[(f64, f64)], time_start: f64, network_scale_type: &AxisScaling,
diff --git a/src/app/widgets/bottom_widgets/process.rs b/src/app/widgets/bottom_widgets/process.rs
index 3851bfcd..074370b3 100644
--- a/src/app/widgets/bottom_widgets/process.rs
+++ b/src/app/widgets/bottom_widgets/process.rs
@@ -4,13 +4,12 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseButton, MouseEvent,
use float_ord::FloatOrd;
use itertools::{Either, Itertools};
use once_cell::unsync::Lazy;
-use unicode_segmentation::GraphemeCursor;
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
text::{Span, Spans},
- widgets::{Borders, Paragraph, TableState},
+ widgets::{Borders, Paragraph},
Frame,
};
@@ -25,557 +24,17 @@ use crate::{
},
canvas::Painter,
data_conversion::get_string_with_bytes,
- data_harvester::processes::{self, ProcessSorting},
options::{layout_options::LayoutRule, ProcessDefaults},
utils::error::BottomError,
};
-use ProcessSorting::*;
use crate::app::{
does_bound_intersect_coordinate,
sort_text_table::{SimpleSortableColumn, SortStatus, SortableColumn},
text_table::TextTableData,
- AppScrollWidgetState, CanvasTableWidthState, Component, CursorDirection, ScrollDirection,
- SortMenu, SortableTextTable, TextInput, Widget,
+ Component, SortMenu, SortableTextTable, TextInput, Widget,
};
-/// AppSearchState deals with generic searching (I might do this in the future).
-pub struct AppSearchState {
- pub is_enabled: bool,
- pub current_search_query: String,
- pub is_blank_search: bool,
- pub is_invalid_search: bool,
- pub grapheme_cursor: GraphemeCursor,
- pub cursor_direction: CursorDirection,
- pub cursor_bar: usize,
- /// This represents the position in terms of CHARACTERS, not graphemes
- pub char_cursor_position: usize,
- /// The query
- pub query: Option<Query>,
- pub error_message: Option<String>,
-}
-
-impl Default for AppSearchState {
- fn default() -> Self {
- AppSearchState {
- is_enabled: false,
- current_search_query: String::default(),
- is_invalid_search: false,
- is_blank_search: true,
- grapheme_cursor: GraphemeCursor::new(0, 0, true),
- cursor_direction: CursorDirection::Right,
- cursor_bar: 0,
- char_cursor_position: 0,
- query: None,
- error_message: None,
- }
- }
-}
-
-impl AppSearchState {
- /// Returns a reset but still enabled app search state
- pub fn reset(&mut self) {
- *self = AppSearchState {
- is_enabled: self.is_enabled,
- ..AppSearchState::default()
- }
- }
-
- pub fn is_invalid_or_blank_search(&self) -> bool {
- self.is_blank_search || self.is_invalid_search
- }
-}
-
-/// ProcessSearchState only deals with process' search's current settings and state.
-pub struct ProcessSearchState {
- pub search_state: AppSearchState,
- pub is_ignoring_case: bool,
- pub is_searching_whole_word: bool,
- pub is_searching_with_regex: bool,
-}
-
-impl Default for ProcessSearchState {
- fn default() -> Self {
- ProcessSearchState {
- search_state: AppSearchState::default(),
- is_ignoring_case: true,
- is_searching_whole_word: false,
- is_searching_with_regex: false,
- }
- }
-}
-
-impl ProcessSearchState {
- pub fn search_toggle_ignore_case(&mut self) {
- self.is_ignoring_case = !self.is_ignoring_case;
- }
-
- pub fn search_toggle_whole_word(&mut self) {
- self.is_searching_whole_word = !self.is_searching_whole_word;
- }
-
- pub fn search_toggle_regex(&mut self) {
- self.is_searching_with_regex = !self.is_searching_with_regex;
- }
-}
-
-pub struct ColumnInfo {
- pub enabled: bool,
- pub shortcut: Option<&'static str>,
-}
-
-pub struct ProcColumn {
- pub ordered_columns: Vec<ProcessSorting>,
- /// The y location of headers. Since they're all aligned, it's just one value.
- pub column_header_y_loc: Option<u16>,
- /// The x start and end bounds for each header.
- pub column_header_x_locs: Option<Vec<(u16, u16)>>,
- pub column_mapping: HashMap<ProcessSorting, ColumnInfo>,
- pub longest_header_len: u16,
- pub column_state: TableState,
- pub scroll_direction: ScrollDirection,
- pub current_scroll_position: usize,
- pub previous_scroll_position: usize,
- pub backup_prev_scroll_position: usize,
-}
-
-impl Default for ProcColumn {
- fn default() -> Self {
- let ordered_columns = vec![
- Count,
- Pid,
- ProcessName,
- Command,
- CpuPercent,
- Mem,
- MemPercent,
- ReadPerSecond,
- WritePerSecond,
- TotalRead,
- TotalWrite,
- User,
- State,
- ];
-
- let mut column_mapping = HashMap::new();
- let mut longest_header_len = 0;
- for column in ordered_columns.clone() {
- longest_header_len = std::cmp::max(longest_header_len, column.to_string().len());
- match column {
- CpuPercent => {
- column_mapping.insert(
- column,
- ColumnInfo {
- enabled: true,
- shortcut: Some("c"),
- // hard_width: None,
- // max_soft_width: None,
- },
- );
- }
- MemPercent => {
- column_mapping.insert(
- column,
- ColumnInfo {
- enabled: true,
- shortcut: Some("m"),
- // hard_width: None,
- // max_soft_width: None,
- },
- );
- }
- Mem => {
- column_mapping.insert(
- column,
- ColumnInfo {
- enabled: false,
- shortcut: Some("m"),
- // hard_width: None,
- // max_soft_width: None,
- },
- );
- }
- ProcessName => {
- column_mapping.insert(
- column,
- ColumnInfo {
- enabled: true,
- shortcut: Some("n"),
- // hard_width: None,
- // max_soft_width: None,
- },
- );
- }
- Command => {
- column_mapping.insert(
- column,
- ColumnInfo {
- enabled: false,
- shortcut: Some("n"),
- // hard_width: None,
- // max_soft_width: None,
- },
- );
- }
- Pid => {
- column_mapping.insert(
- column,
- ColumnInfo {
- enabled: true,
- shortcut: Some("p"),
- // hard_width: None,
- // max_soft_width: None,
- },
- );
- }
- Count => {
- column_mapping.insert(
- column,
- ColumnInfo {
- enabled: false,
- shortcut: None,
- // hard_width: None,
- // max_soft_width: None,
- },
- );
- }
- User => {
- column_mapping.insert(
- column,
- ColumnInfo {
- enabled: cfg!(target_family = "unix"),
- shortcut: None,
- },
- );
- }
- _ => {
- column_mapping.insert(
- column,
- ColumnInfo {
- enabled: true,
- shortcut: None,
- // hard_width: None,
- // max_soft_width: None,
- },
- );
- }
- }
- }
- let longest_header_len = longest_header_len as u16;
-
- ProcColumn {
- ordered_columns,
- column_mapping,
- longest_header_len,
- column_state: TableState::default(),
- scroll_direction: ScrollDirection::default(),
- current_scroll_position: 0,
- previous_scroll_position: 0,
- backup_prev_scroll_position: 0,
- column_header_y_loc: None,
- column_header_x_locs: None,
- }
- }
-}
-
-impl ProcColumn {
- /// Returns its new status.
- pub fn toggle(&mut self, column: &ProcessSorting) -> Option<bool> {
- if let Some(mapping) = self.column_mapping.get_mut(column) {
- mapping.enabled = !(mapping.enabled);
- Some(mapping.enabled)
- } else {
- None
- }
- }
-
- pub fn try_set(&mut self, column: &ProcessSorting, setting: bool) -> Option<bool> {
- if let Some(mapping) = self.column_mapping.get_mut(column) {
- mapping.enabled = setting;
- Some(mapping.enabled)
- } else {
- None
- }
- }
-
- pub fn try_enable(&mut self, column: &ProcessSorting) -> Option<bool> {
- if let Some(mapping) = self.column_mapping.get_mut(column) {
- mapping.enabled = true;
- Some(mapping.enabled)
- } else {
- None
- }
- }
-
- pub fn try_disable(&mut self, column: &ProcessSorting) -> Option<bool> {
- if let Some(mapping) = self.column_mapping.get_mut(column) {
- mapping.enabled = false;
- Some(mapping.enabled)
- } else {
- None
- }
- }
-
- pub fn is_enabled(&self, column: &ProcessSorting) -> bool {
- if let Some(mapping) = self.column_mapping.get(column) {
- mapping.enabled
- } else {
- false
- }
- }
-
- pub fn get_enabled_columns_len(&self) -> usize {
- self.ordered_columns
- .iter()
- .filter_map(|column_type| {
- if let Some(col_map) = self.column_mapping.get(column_type) {
- if col_map.enabled {
- Some(1)
- } else {
- None
- }
- } else {
- None
- }
- })
- .sum()
- }
-
- /// NOTE: ALWAYS call this when opening the sorted window.
- pub fn set_to_sorted_index_from_type(&mut self, proc_sorting_type: &ProcessSorting) {
- // TODO [Custom Columns]: If we add custom columns, this may be needed! Since column indices will change, this runs the risk of OOB. So, when you change columns, CALL THIS AND ADAPT!
- let mut true_index = 0;
- for column in &self.ordered_columns {
- if *column == *proc_sorting_type {
- break;
- }
- if self.column_mapping.get(column).unwrap().enabled {
- true_index += 1;
- }
- }
-
- self.current_scroll_position = true_index;
- self.backup_prev_scroll_position = self.previous_scroll_position;
- }
-
- /// This function sets the scroll position based on the index.
- pub fn set_to_sorted_index_from_visual_index(&mut self, visual_index: usize) {
- self.current_scroll_position = visual_index;
- self.backup_prev_scroll_position = self.previous_scroll_position;
- }
-
- pub fn get_column_headers(
- &self, proc_sorting_type: &ProcessSorting, sort_reverse: bool,
- ) -> Vec<String> {
- const DOWN_ARROW: char = '▼';
- const UP_ARROW: char = '▲';
-
- // TODO: Gonna have to figure out how to do left/right GUI notation if we add it.
- self.ordered_columns
- .iter()
- .filter_map(|column_type| {
- let mapping = self.column_mapping.get(column_type).unwrap();
- let mut command_str = String::default();
- if let Some(command) = mapping.shortcut {
- command_str = format!("({})", command);
- }
-
- if mapping.enabled {
- Some(format!(
- "{}{}{}",
- column_type.to_string(),
- command_str.as_str(),
- if proc_sorting_type == column_type {
- if sort_reverse {
- DOWN_ARROW
- } else {
- UP_ARROW
- }
- } else {
- ' '
- }
- ))
- } else {
- None
- }
- })
- .collect()
- }
-}
-
-pub struct ProcWidgetState {
- pub process_search_state: ProcessSearchState,
- pub is_grouped: bool,
- pub scroll_state: AppScrollWidgetState,
- pub process_sorting_type: processes::ProcessSorting,
- pub is_process_sort_descending: bool,
- pub is_using_command: bool,
- pub current_column_index: usize,
- pub is_sort_open: bool,
- pub columns: ProcColumn,
- pub is_tree_mode: bool,
- pub table_width_state: CanvasTableWidthState,
- pub requires_redraw: bool,
-}
-
-impl ProcWidgetState {
- /// Updates sorting when using the column list.
- /// ...this really should be part of the ProcColumn struct (along with the sorting fields),
- /// but I'm too lazy.
- ///
- /// Sorry, future me, you're gonna have to refactor this later. Too busy getting
- /// the feature to work in the first place! :)
- pub fn update_sorting_with_columns(&mut self) {
- let mut true_index = 0;
- let mut enabled_index = 0;
- let target_itx = self.columns.current_scroll_position;
- for column in &self.columns.ordered_columns {
- let enabled = self.columns.column_mapping.get(column).unwrap().enabled;
- if enabled_index == target_itx && enabled {
- break;
- }
- if enabled {
- enabled_index += 1;
- }
- true_index += 1;
- }
-
- if let Some(new_sort_type) = self.columns.ordered_columns.get(true_index) {
- if *new_sort_type == self.process_sorting_type {
- // Just reverse the search if we're reselecting!
- self.is_process_sort_descending = !(self.is_process_sort_descending);
- } else {
- self.process_sorting_type = new_sort_type.clone();
- match self.process_sorting_type {
- ProcessSorting::State
- | ProcessSorting::Pid
- | ProcessSorting::ProcessName
- | ProcessSorting::Command => {
- // Also invert anything that uses alphabetical sorting by default.
- self.is_process_sort_descending = false;
- }
- _ => {
- self.is_process_sort_descending = true;
- }
- }
- }
- }
- }
-
- pub fn toggle_command_and_name(&mut self, is_using_command: bool) {
- if let Some(pn) = self
- .columns
- .column_mapping
- .get_mut(&ProcessSorting::ProcessName)
- {
- pn.enabled = !is_using_command;
- }
- if let Some(c) = self
- .columns
- .column_mapping
- .get_mut(&ProcessSorting::Command)
- {
- c.enabled = is_using_command;
- }
- }
-
- pub fn get_search_cursor_position(&self) -> usize {
- self.process_search_state
- .search_state
- .grapheme_cursor
- .cur_cursor()
- }
-
- pub fn get_char_cursor_position(&self) -> usize {
- self.process_search_state.search_state.char_cursor_position
- }
-
- pub fn is_search_enabled(&self) -> bool {
- self.process_search_state.search_state.is_enabled
- }
-
- pub fn get_current_search_query(&self) -> &String {
- &self.process_search_state.search_state.current_search_query
- }
-
- pub fn update_query(&mut self) {
- if self
- .process_search_state
- .search_state
- .current_search_query
- .is_empty()
- {
- self.process_search_state.search_state.is_blank_search = true;
- self.process_search_state.search_state.is_invalid_search = false;
- self.process_search_state.search_state.error_message = None;
- } else {
- let parsed_query = parse_query(
- self.get_current_search_query(),
- self.process_search_state.is_searching_whole_word,
- self.process_search_state.is_ignoring_case,
- self.process_search_state.is_searching_with_regex,
- );
- // debug!("Parsed query: {:#?}", parsed_query);
-
- if let Ok(parsed_query) = parsed_query {
- self.process_search_state.search_state.query = Some(parsed_query);
- self.process_search_state.search_state.is_blank_search = false;
- self.process_search_state.search_state.is_invalid_search = false;
- self.process_search_state.search_state.error_message = None;
- } else if let Err(err) = parsed_query {
- self.process_search_state.search_state.is_blank_search = false;
- self.process_search_state.search_state.is_invalid_search = true;
- self.process_search_state.search_state.error_message = Some(err.to_string());
- }
- }
- self.scroll_state.previous_scroll_position = 0;
- self.scroll_state.current_scroll_position = 0;
- }
-
- pub fn clear_search(&mut self) {
- self.process_search_state.search_state.reset();
- }
-
- pub fn search_walk_forward(&mut self, start_position: usize) {
- self.process_search_state
- .search_state
- .grapheme_cursor
- .next_bo