refactor: quick variable/struct/file rename (#1620)

Some renames and file movement. No functional changes.
This commit is contained in:
Clement Tsang 2024-11-07 23:54:52 -05:00 committed by GitHub
parent ae14685913
commit 02b947dd2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 56 additions and 50 deletions

View file

@ -3,7 +3,6 @@ pub mod filter;
pub mod frozen_state; pub mod frozen_state;
pub mod layout_manager; pub mod layout_manager;
mod process_killer; mod process_killer;
pub mod query;
pub mod states; pub mod states;
use std::{ use std::{
@ -28,7 +27,7 @@ use crate::{
data_conversion::ConvertedData, data_conversion::ConvertedData,
get_network_points, get_network_points,
utils::data_units::DataUnit, utils::data_units::DataUnit,
widgets::{ProcWidgetColumn, ProcWidgetMode}, widgets::{query::ProcessQuery, ProcWidgetColumn, ProcWidgetMode},
}; };
#[derive(Debug, Clone, Eq, PartialEq, Default)] #[derive(Debug, Clone, Eq, PartialEq, Default)]
@ -671,7 +670,7 @@ impl App {
} }
} }
pub fn get_process_filter(&self, widget_id: u64) -> &Option<query::Query> { pub fn get_process_filter(&self, widget_id: u64) -> &Option<ProcessQuery> {
if let Some(process_widget_state) = self.states.proc_state.widget_states.get(&widget_id) { if let Some(process_widget_state) = self.states.proc_state.widget_states.get(&widget_id) {
&process_widget_state.proc_search.search_state.query &process_widget_state.proc_search.search_state.query
} else { } else {

View file

@ -6,11 +6,11 @@ use unicode_ellipsis::grapheme_width;
use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete, UnicodeSegmentation}; use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete, UnicodeSegmentation};
use crate::{ use crate::{
app::{layout_manager::BottomWidgetType, query::*}, app::layout_manager::BottomWidgetType,
constants, constants,
widgets::{ widgets::{
BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState, query::ProcessQuery, BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState,
ProcWidgetState, TempWidgetState, NetWidgetState, ProcWidgetState, TempWidgetState,
}, },
}; };
@ -90,7 +90,7 @@ pub struct AppSearchState {
pub size_mappings: IndexMap<usize, Range<usize>>, pub size_mappings: IndexMap<usize, Range<usize>>,
/// The query. TODO: Merge this as one enum. /// The query. TODO: Merge this as one enum.
pub query: Option<Query>, pub query: Option<ProcessQuery>,
pub error_message: Option<String>, pub error_message: Option<String>,
} }

View file

@ -519,7 +519,7 @@ pub(crate) fn init_app(
)) ))
} }
pub fn get_widget_layout( fn get_widget_layout(
args: &BottomArgs, config: &Config, args: &BottomArgs, config: &Config,
) -> OptionResult<(BottomLayout, u64, Option<BottomWidgetType>)> { ) -> OptionResult<(BottomLayout, u64, Option<BottomWidgetType>)> {
let cpu_left_legend = is_flag_enabled!(cpu_left_legend, args.cpu, config); let cpu_left_legend = is_flag_enabled!(cpu_left_legend, args.cpu, config);

View file

@ -1,5 +1,6 @@
pub mod proc_widget_column; pub mod proc_widget_column;
pub mod proc_widget_data; pub mod proc_widget_data;
pub mod query;
mod sort_table; mod sort_table;
use std::{borrow::Cow, collections::BTreeMap}; use std::{borrow::Cow, collections::BTreeMap};
@ -9,12 +10,12 @@ use indexmap::IndexSet;
use itertools::Itertools; use itertools::Itertools;
pub use proc_widget_column::*; pub use proc_widget_column::*;
pub use proc_widget_data::*; pub use proc_widget_data::*;
use query::{parse_query, ProcessQuery};
use sort_table::SortTableColumn; use sort_table::SortTableColumn;
use crate::{ use crate::{
app::{ app::{
data_farmer::{DataCollection, ProcessData}, data_farmer::{DataCollection, ProcessData},
query::*,
AppConfigFields, AppSearchState, AppConfigFields, AppSearchState,
}, },
canvas::components::data_table::{ canvas::components::data_table::{
@ -75,7 +76,7 @@ fn make_column(column: ProcColumn) -> SortColumn<ProcColumn> {
match column { match column {
CpuPercent => SortColumn::new(CpuPercent).default_descending(), CpuPercent => SortColumn::new(CpuPercent).default_descending(),
MemoryVal => SortColumn::new(MemoryVal).default_descending(), MemoryValue => SortColumn::new(MemoryValue).default_descending(),
MemoryPercent => SortColumn::new(MemoryPercent).default_descending(), MemoryPercent => SortColumn::new(MemoryPercent).default_descending(),
Pid => SortColumn::new(Pid), Pid => SortColumn::new(Pid),
Count => SortColumn::new(Count), Count => SortColumn::new(Count),
@ -89,9 +90,9 @@ fn make_column(column: ProcColumn) -> SortColumn<ProcColumn> {
State => SortColumn::hard(State, 9), State => SortColumn::hard(State, 9),
Time => SortColumn::new(Time), Time => SortColumn::new(Time),
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
GpuMem => SortColumn::new(GpuMem).default_descending(), GpuMemoryValue => SortColumn::new(GpuMemoryValue).default_descending(),
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
GpuMemPercent => SortColumn::new(GpuMemPercent).default_descending(), GpuMemoryPercent => SortColumn::new(GpuMemoryPercent).default_descending(),
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
GpuUtilPercent => SortColumn::new(GpuUtilPercent).default_descending(), GpuUtilPercent => SortColumn::new(GpuUtilPercent).default_descending(),
} }
@ -247,7 +248,7 @@ impl ProcWidgetState {
ProcWidgetColumn::Cpu => CpuPercent, ProcWidgetColumn::Cpu => CpuPercent,
ProcWidgetColumn::Mem => { ProcWidgetColumn::Mem => {
if mem_as_values { if mem_as_values {
MemoryVal MemoryValue
} else { } else {
MemoryPercent MemoryPercent
} }
@ -262,9 +263,9 @@ impl ProcWidgetState {
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
ProcWidgetColumn::GpuMem => { ProcWidgetColumn::GpuMem => {
if mem_as_values { if mem_as_values {
GpuMem GpuMemoryValue
} else { } else {
GpuMemPercent GpuMemoryPercent
} }
} }
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
@ -280,7 +281,7 @@ impl ProcWidgetState {
if is_command { Command } else { Name }, if is_command { Command } else { Name },
CpuPercent, CpuPercent,
if mem_as_values { if mem_as_values {
MemoryVal MemoryValue
} else { } else {
MemoryPercent MemoryPercent
}, },
@ -305,7 +306,7 @@ impl ProcWidgetState {
match col.inner() { match col.inner() {
CpuPercent => ProcWidgetColumn::Cpu, CpuPercent => ProcWidgetColumn::Cpu,
MemoryVal | MemoryPercent => ProcWidgetColumn::Mem, MemoryValue | MemoryPercent => ProcWidgetColumn::Mem,
Pid | Count => ProcWidgetColumn::PidOrCount, Pid | Count => ProcWidgetColumn::PidOrCount,
Name | Command => ProcWidgetColumn::ProcNameOrCommand, Name | Command => ProcWidgetColumn::ProcNameOrCommand,
ReadPerSecond => ProcWidgetColumn::ReadPerSecond, ReadPerSecond => ProcWidgetColumn::ReadPerSecond,
@ -316,7 +317,7 @@ impl ProcWidgetState {
User => ProcWidgetColumn::User, User => ProcWidgetColumn::User,
Time => ProcWidgetColumn::Time, Time => ProcWidgetColumn::Time,
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
GpuMem | GpuMemPercent => ProcWidgetColumn::GpuMem, GpuMemoryValue | GpuMemoryPercent => ProcWidgetColumn::GpuMem,
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
GpuUtilPercent => ProcWidgetColumn::GpuUtil, GpuUtilPercent => ProcWidgetColumn::GpuUtil,
} }
@ -385,7 +386,7 @@ impl ProcWidgetState {
.unwrap_or(false) .unwrap_or(false)
} }
fn get_query(&self) -> &Option<Query> { fn get_query(&self) -> &Option<ProcessQuery> {
if self.proc_search.search_state.is_invalid_or_blank_search() { if self.proc_search.search_state.is_invalid_or_blank_search() {
&None &None
} else { } else {
@ -741,11 +742,11 @@ impl ProcWidgetState {
if let Some(index) = self.column_mapping.get_index_of(&ProcWidgetColumn::Mem) { if let Some(index) = self.column_mapping.get_index_of(&ProcWidgetColumn::Mem) {
if let Some(mem) = self.get_mut_proc_col(index) { if let Some(mem) = self.get_mut_proc_col(index) {
match mem { match mem {
ProcColumn::MemoryVal => { ProcColumn::MemoryValue => {
*mem = ProcColumn::MemoryPercent; *mem = ProcColumn::MemoryPercent;
} }
ProcColumn::MemoryPercent => { ProcColumn::MemoryPercent => {
*mem = ProcColumn::MemoryVal; *mem = ProcColumn::MemoryValue;
} }
_ => unreachable!(), _ => unreachable!(),
} }
@ -758,11 +759,11 @@ impl ProcWidgetState {
if let Some(index) = self.column_mapping.get_index_of(&ProcWidgetColumn::GpuMem) { if let Some(index) = self.column_mapping.get_index_of(&ProcWidgetColumn::GpuMem) {
if let Some(mem) = self.get_mut_proc_col(index) { if let Some(mem) = self.get_mut_proc_col(index) {
match mem { match mem {
ProcColumn::GpuMem => { ProcColumn::GpuMemoryValue => {
*mem = ProcColumn::GpuMemPercent; *mem = ProcColumn::GpuMemoryPercent;
} }
ProcColumn::GpuMemPercent => { ProcColumn::GpuMemoryPercent => {
*mem = ProcColumn::GpuMem; *mem = ProcColumn::GpuMemoryValue;
} }
_ => unreachable!(), _ => unreachable!(),
} }
@ -1291,7 +1292,7 @@ mod test {
]; ];
let new_columns = vec![ let new_columns = vec![
ProcColumn::Pid, ProcColumn::Pid,
ProcColumn::MemoryVal, ProcColumn::MemoryValue,
ProcColumn::State, ProcColumn::State,
ProcColumn::Name, ProcColumn::Name,
]; ];
@ -1316,7 +1317,7 @@ mod test {
]; ];
let original_columns = vec![ let original_columns = vec![
ProcColumn::Pid, ProcColumn::Pid,
ProcColumn::MemoryVal, ProcColumn::MemoryValue,
ProcColumn::State, ProcColumn::State,
ProcColumn::Name, ProcColumn::Name,
]; ];
@ -1381,7 +1382,7 @@ mod test {
]; ];
let original_columns = vec![ let original_columns = vec![
ProcColumn::Pid, ProcColumn::Pid,
ProcColumn::MemoryVal, ProcColumn::MemoryValue,
ProcColumn::State, ProcColumn::State,
ProcColumn::Name, ProcColumn::Name,
]; ];
@ -1422,7 +1423,7 @@ mod test {
ProcColumn::Name, ProcColumn::Name,
]; ];
let new_columns = vec![ let new_columns = vec![
ProcColumn::MemoryVal, ProcColumn::MemoryValue,
ProcColumn::Pid, ProcColumn::Pid,
ProcColumn::State, ProcColumn::State,
ProcColumn::Name, ProcColumn::Name,

View file

@ -9,7 +9,7 @@ use crate::{
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
pub enum ProcColumn { pub enum ProcColumn {
CpuPercent, CpuPercent,
MemoryVal, MemoryValue,
MemoryPercent, MemoryPercent,
Pid, Pid,
Count, Count,
@ -23,9 +23,9 @@ pub enum ProcColumn {
User, User,
Time, Time,
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
GpuMem, GpuMemoryValue,
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
GpuMemPercent, GpuMemoryPercent,
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
GpuUtilPercent, GpuUtilPercent,
} }
@ -34,7 +34,7 @@ impl ColumnHeader for ProcColumn {
fn text(&self) -> Cow<'static, str> { fn text(&self) -> Cow<'static, str> {
match self { match self {
ProcColumn::CpuPercent => "CPU%", ProcColumn::CpuPercent => "CPU%",
ProcColumn::MemoryVal => "Mem", ProcColumn::MemoryValue => "Mem",
ProcColumn::MemoryPercent => "Mem%", ProcColumn::MemoryPercent => "Mem%",
ProcColumn::Pid => "PID", ProcColumn::Pid => "PID",
ProcColumn::Count => "Count", ProcColumn::Count => "Count",
@ -48,9 +48,9 @@ impl ColumnHeader for ProcColumn {
ProcColumn::User => "User", ProcColumn::User => "User",
ProcColumn::Time => "Time", ProcColumn::Time => "Time",
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
ProcColumn::GpuMem => "GMem", ProcColumn::GpuMemoryValue => "GMem",
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
ProcColumn::GpuMemPercent => "GMem%", ProcColumn::GpuMemoryPercent => "GMem%",
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
ProcColumn::GpuUtilPercent => "GPU%", ProcColumn::GpuUtilPercent => "GPU%",
} }
@ -60,7 +60,7 @@ impl ColumnHeader for ProcColumn {
fn header(&self) -> Cow<'static, str> { fn header(&self) -> Cow<'static, str> {
match self { match self {
ProcColumn::CpuPercent => "CPU%(c)", ProcColumn::CpuPercent => "CPU%(c)",
ProcColumn::MemoryVal => "Mem(m)", ProcColumn::MemoryValue => "Mem(m)",
ProcColumn::MemoryPercent => "Mem%(m)", ProcColumn::MemoryPercent => "Mem%(m)",
ProcColumn::Pid => "PID(p)", ProcColumn::Pid => "PID(p)",
ProcColumn::Count => "Count", ProcColumn::Count => "Count",
@ -74,9 +74,9 @@ impl ColumnHeader for ProcColumn {
ProcColumn::User => "User", ProcColumn::User => "User",
ProcColumn::Time => "Time", ProcColumn::Time => "Time",
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
ProcColumn::GpuMem => "GMem", ProcColumn::GpuMemoryValue => "GMem",
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
ProcColumn::GpuMemPercent => "GMem%", ProcColumn::GpuMemoryPercent => "GMem%",
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
ProcColumn::GpuUtilPercent => "GPU%", ProcColumn::GpuUtilPercent => "GPU%",
} }
@ -94,7 +94,7 @@ impl SortsRow for ProcColumn {
sort_partial_fn(descending)(a.cpu_usage_percent, b.cpu_usage_percent) sort_partial_fn(descending)(a.cpu_usage_percent, b.cpu_usage_percent)
}); });
} }
ProcColumn::MemoryVal | ProcColumn::MemoryPercent => { ProcColumn::MemoryValue | ProcColumn::MemoryPercent => {
data.sort_by(|a, b| sort_partial_fn(descending)(&a.mem_usage, &b.mem_usage)); data.sort_by(|a, b| sort_partial_fn(descending)(&a.mem_usage, &b.mem_usage));
} }
ProcColumn::Pid => { ProcColumn::Pid => {
@ -140,7 +140,7 @@ impl SortsRow for ProcColumn {
data.sort_by(|a, b| sort_partial_fn(descending)(a.time, b.time)); data.sort_by(|a, b| sort_partial_fn(descending)(a.time, b.time));
} }
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
ProcColumn::GpuMem | ProcColumn::GpuMemPercent => { ProcColumn::GpuMemoryValue | ProcColumn::GpuMemoryPercent => {
data.sort_by(|a, b| { data.sort_by(|a, b| {
sort_partial_fn(descending)(&a.gpu_mem_usage, &b.gpu_mem_usage) sort_partial_fn(descending)(&a.gpu_mem_usage, &b.gpu_mem_usage)
}); });

View file

@ -280,7 +280,7 @@ impl ProcWidgetData {
fn to_string(&self, column: &ProcColumn) -> String { fn to_string(&self, column: &ProcColumn) -> String {
match column { match column {
ProcColumn::CpuPercent => format!("{:.1}%", self.cpu_usage_percent), ProcColumn::CpuPercent => format!("{:.1}%", self.cpu_usage_percent),
ProcColumn::MemoryVal | ProcColumn::MemoryPercent => self.mem_usage.to_string(), ProcColumn::MemoryValue | ProcColumn::MemoryPercent => self.mem_usage.to_string(),
ProcColumn::Pid => self.pid.to_string(), ProcColumn::Pid => self.pid.to_string(),
ProcColumn::Count => self.num_similar.to_string(), ProcColumn::Count => self.num_similar.to_string(),
ProcColumn::Name | ProcColumn::Command => self.id.to_prefixed_string(), ProcColumn::Name | ProcColumn::Command => self.id.to_prefixed_string(),
@ -292,7 +292,9 @@ impl ProcWidgetData {
ProcColumn::User => self.user.clone(), ProcColumn::User => self.user.clone(),
ProcColumn::Time => format_time(self.time), ProcColumn::Time => format_time(self.time),
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
ProcColumn::GpuMem | ProcColumn::GpuMemPercent => self.gpu_mem_usage.to_string(), ProcColumn::GpuMemoryValue | ProcColumn::GpuMemoryPercent => {
self.gpu_mem_usage.to_string()
}
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
ProcColumn::GpuUtilPercent => format!("{:.1}%", self.gpu_usage), ProcColumn::GpuUtilPercent => format!("{:.1}%", self.gpu_usage),
} }
@ -310,7 +312,9 @@ impl DataToCell<ProcColumn> for ProcWidgetData {
// differences. // differences.
Some(match column { Some(match column {
ProcColumn::CpuPercent => format!("{:.1}%", self.cpu_usage_percent).into(), ProcColumn::CpuPercent => format!("{:.1}%", self.cpu_usage_percent).into(),
ProcColumn::MemoryVal | ProcColumn::MemoryPercent => self.mem_usage.to_string().into(), ProcColumn::MemoryValue | ProcColumn::MemoryPercent => {
self.mem_usage.to_string().into()
}
ProcColumn::Pid => self.pid.to_string().into(), ProcColumn::Pid => self.pid.to_string().into(),
ProcColumn::Count => self.num_similar.to_string().into(), ProcColumn::Count => self.num_similar.to_string().into(),
ProcColumn::Name | ProcColumn::Command => self.id.to_prefixed_string().into(), ProcColumn::Name | ProcColumn::Command => self.id.to_prefixed_string().into(),
@ -328,7 +332,9 @@ impl DataToCell<ProcColumn> for ProcWidgetData {
ProcColumn::User => self.user.clone().into(), ProcColumn::User => self.user.clone().into(),
ProcColumn::Time => format_time(self.time).into(), ProcColumn::Time => format_time(self.time).into(),
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
ProcColumn::GpuMem | ProcColumn::GpuMemPercent => self.gpu_mem_usage.to_string().into(), ProcColumn::GpuMemoryValue | ProcColumn::GpuMemoryPercent => {
self.gpu_mem_usage.to_string().into()
}
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
ProcColumn::GpuUtilPercent => format!("{:.1}%", self.gpu_usage).into(), ProcColumn::GpuUtilPercent => format!("{:.1}%", self.gpu_usage).into(),
}) })

View file

@ -77,8 +77,8 @@ const AND_LIST: [&str; 2] = ["and", "&&"];
pub(crate) fn parse_query( pub(crate) fn parse_query(
search_query: &str, is_searching_whole_word: bool, is_ignoring_case: bool, search_query: &str, is_searching_whole_word: bool, is_ignoring_case: bool,
is_searching_with_regex: bool, is_searching_with_regex: bool,
) -> QueryResult<Query> { ) -> QueryResult<ProcessQuery> {
fn process_string_to_filter(query: &mut VecDeque<String>) -> QueryResult<Query> { fn process_string_to_filter(query: &mut VecDeque<String>) -> QueryResult<ProcessQuery> {
let lhs = process_or(query)?; let lhs = process_or(query)?;
let mut list_of_ors = vec![lhs]; let mut list_of_ors = vec![lhs];
@ -86,7 +86,7 @@ pub(crate) fn parse_query(
list_of_ors.push(process_or(query)?); list_of_ors.push(process_or(query)?);
} }
Ok(Query { query: list_of_ors }) Ok(ProcessQuery { query: list_of_ors })
} }
fn process_or(query: &mut VecDeque<String>) -> QueryResult<Or> { fn process_or(query: &mut VecDeque<String>) -> QueryResult<Or> {
@ -532,12 +532,12 @@ pub(crate) fn parse_query(
Ok(process_filter) Ok(process_filter)
} }
pub struct Query { pub struct ProcessQuery {
/// Remember, AND > OR, but AND must come after OR when we parse. /// Remember, AND > OR, but AND must come after OR when we parse.
query: Vec<Or>, query: Vec<Or>,
} }
impl Query { impl ProcessQuery {
fn process_regexes( fn process_regexes(
&mut self, is_searching_whole_word: bool, is_ignoring_case: bool, &mut self, is_searching_whole_word: bool, is_ignoring_case: bool,
is_searching_with_regex: bool, is_searching_with_regex: bool,
@ -560,7 +560,7 @@ impl Query {
} }
} }
impl Debug for Query { impl Debug for ProcessQuery {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("{:?}", self.query)) f.write_fmt(format_args!("{:?}", self.query))
} }