use crate::{
app::{
data_farmer::{DataCollection, ProcessData, StringPidMap},
data_harvester::processes::ProcessHarvest,
query::*,
AppSearchState, CellContent, ScrollDirection, SortOrder, SortState, SortableState,
TableComponentColumn, TableComponentHeader, TableComponentState, WidthBounds,
},
data_conversion::{binary_byte_string, dec_bytes_per_second_string, TableData, TableRow},
utils::gen_util::sort_partial_fn,
Pid,
};
use concat_string::concat_string;
use fxhash::{FxHashMap, FxHashSet};
use itertools::Itertools;
use std::{
borrow::Cow,
cmp::{max, Reverse},
};
/// 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;
}
}
#[derive(Clone, Debug)]
pub enum ProcWidgetMode {
Tree { collapsed_pids: FxHashSet<Pid> },
Grouped,
Normal,
}
#[derive(Debug, PartialEq, Eq)]
pub enum ProcWidgetColumn {
CpuPercent,
Memory { show_percentage: bool },
PidOrCount { is_count: bool },
ProcNameOrCommand { is_command: bool },
ReadPerSecond,
WritePerSecond,
TotalRead,
TotalWrite,
State,
User,
}
impl ProcWidgetColumn {
const CPU_PERCENT: CellContent = CellContent::Simple(Cow::Borrowed("CPU%"));
const MEM_PERCENT: CellContent = CellContent::Simple(Cow::Borrowed("Mem%"));
const MEM: CellContent = CellContent::Simple(Cow::Borrowed("Mem"));
const READS_PER_SECOND: CellContent = CellContent::Simple(Cow::Borrowed("R/s"));
const WRITES_PER_SECOND: CellContent = CellContent::Simple(Cow::Borrowed("W/s"));
const TOTAL_READ: CellContent = CellContent::Simple(Cow::Borrowed("T.Read"));
const TOTAL_WRITE: CellContent = CellContent::Simple(Cow::Borrowed("T.Write"));
const STATE: CellContent = CellContent::Simple(Cow::Borrowed("State"));
const PROCESS_NAME: CellContent = CellContent::Simple(Cow::Borrowed("Name"));
const COMMAND: CellContent = CellContent::Simple(Cow::Borrowed("Command"));
const PID: CellContent = CellContent::Simple(Cow::Borrowed("PID"));
const COUNT: CellContent = CellContent::Simple(Cow::Borrowed("Count"));
const USER: CellContent = CellContent::Simple(Cow::Borrowed("User"));
const SHORTCUT_CPU_PERCENT: CellContent = CellContent::Simple(Cow::Borrowed("CPU%(c)"));
const SHORTCUT_MEM_PERCENT: C