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 layout_manager;
mod process_killer;
pub mod query;
pub mod states;
use std::{
@ -28,7 +27,7 @@ use crate::{
data_conversion::ConvertedData,
get_network_points,
utils::data_units::DataUnit,
widgets::{ProcWidgetColumn, ProcWidgetMode},
widgets::{query::ProcessQuery, ProcWidgetColumn, ProcWidgetMode},
};
#[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) {
&process_widget_state.proc_search.search_state.query
} else {

View file

@ -6,11 +6,11 @@ use unicode_ellipsis::grapheme_width;
use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete, UnicodeSegmentation};
use crate::{
app::{layout_manager::BottomWidgetType, query::*},
app::layout_manager::BottomWidgetType,
constants,
widgets::{
BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState,
ProcWidgetState, TempWidgetState,
query::ProcessQuery, BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState,
NetWidgetState, ProcWidgetState, TempWidgetState,
},
};
@ -90,7 +90,7 @@ pub struct AppSearchState {
pub size_mappings: IndexMap<usize, Range<usize>>,
/// The query. TODO: Merge this as one enum.
pub query: Option<Query>,
pub query: Option<ProcessQuery>,
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,
) -> OptionResult<(BottomLayout, u64, Option<BottomWidgetType>)> {
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_data;
pub mod query;
mod sort_table;
use std::{borrow::Cow, collections::BTreeMap};
@ -9,12 +10,12 @@ use indexmap::IndexSet;
use itertools::Itertools;
pub use proc_widget_column::*;
pub use proc_widget_data::*;
use query::{parse_query, ProcessQuery};
use sort_table::SortTableColumn;
use crate::{
app::{
data_farmer::{DataCollection, ProcessData},
query::*,
AppConfigFields, AppSearchState,
},
canvas::components::data_table::{
@ -75,7 +76,7 @@ fn make_column(column: ProcColumn) -> SortColumn<ProcColumn> {
match column {
CpuPercent => SortColumn::new(CpuPercent).default_descending(),
MemoryVal => SortColumn::new(MemoryVal).default_descending(),
MemoryValue => SortColumn::new(MemoryValue).default_descending(),
MemoryPercent => SortColumn::new(MemoryPercent).default_descending(),
Pid => SortColumn::new(Pid),
Count => SortColumn::new(Count),
@ -89,9 +90,9 @@ fn make_column(column: ProcColumn) -> SortColumn<ProcColumn> {
State => SortColumn::hard(State, 9),
Time => SortColumn::new(Time),
#[cfg(feature = "gpu")]
GpuMem => SortColumn::new(GpuMem).default_descending(),
GpuMemoryValue => SortColumn::new(GpuMemoryValue).default_descending(),
#[cfg(feature = "gpu")]
GpuMemPercent => SortColumn::new(GpuMemPercent).default_descending(),
GpuMemoryPercent => SortColumn::new(GpuMemoryPercent).default_descending(),
#[cfg(feature = "gpu")]
GpuUtilPercent => SortColumn::new(GpuUtilPercent).default_descending(),
}
@ -247,7 +248,7 @@ impl ProcWidgetState {
ProcWidgetColumn::Cpu => CpuPercent,
ProcWidgetColumn::Mem => {
if mem_as_values {
MemoryVal
MemoryValue
} else {
MemoryPercent
}
@ -262,9 +263,9 @@ impl ProcWidgetState {
#[cfg(feature = "gpu")]
ProcWidgetColumn::GpuMem => {
if mem_as_values {
GpuMem
GpuMemoryValue
} else {
GpuMemPercent
GpuMemoryPercent
}
}
#[cfg(feature = "gpu")]
@ -280,7 +281,7 @@ impl ProcWidgetState {
if is_command { Command } else { Name },
CpuPercent,
if mem_as_values {
MemoryVal
MemoryValue
} else {
MemoryPercent
},
@ -305,7 +306,7 @@ impl ProcWidgetState {
match col.inner() {
CpuPercent => ProcWidgetColumn::Cpu,
MemoryVal | MemoryPercent => ProcWidgetColumn::Mem,
MemoryValue | MemoryPercent => ProcWidgetColumn::Mem,
Pid | Count => ProcWidgetColumn::PidOrCount,
Name | Command => ProcWidgetColumn::ProcNameOrCommand,
ReadPerSecond => ProcWidgetColumn::ReadPerSecond,
@ -316,7 +317,7 @@ impl ProcWidgetState {
User => ProcWidgetColumn::User,
Time => ProcWidgetColumn::Time,
#[cfg(feature = "gpu")]
GpuMem | GpuMemPercent => ProcWidgetColumn::GpuMem,
GpuMemoryValue | GpuMemoryPercent => ProcWidgetColumn::GpuMem,
#[cfg(feature = "gpu")]
GpuUtilPercent => ProcWidgetColumn::GpuUtil,
}
@ -385,7 +386,7 @@ impl ProcWidgetState {
.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() {
&None
} else {
@ -741,11 +742,11 @@ impl ProcWidgetState {
if let Some(index) = self.column_mapping.get_index_of(&ProcWidgetColumn::Mem) {
if let Some(mem) = self.get_mut_proc_col(index) {
match mem {
ProcColumn::MemoryVal => {
ProcColumn::MemoryValue => {
*mem = ProcColumn::MemoryPercent;
}
ProcColumn::MemoryPercent => {
*mem = ProcColumn::MemoryVal;
*mem = ProcColumn::MemoryValue;
}
_ => unreachable!(),
}
@ -758,11 +759,11 @@ impl ProcWidgetState {
if let Some(index) = self.column_mapping.get_index_of(&ProcWidgetColumn::GpuMem) {
if let Some(mem) = self.get_mut_proc_col(index) {
match mem {
ProcColumn::GpuMem => {
*mem = ProcColumn::GpuMemPercent;
ProcColumn::GpuMemoryValue => {
*mem = ProcColumn::GpuMemoryPercent;
}
ProcColumn::GpuMemPercent => {
*mem = ProcColumn::GpuMem;
ProcColumn::GpuMemoryPercent => {
*mem = ProcColumn::GpuMemoryValue;
}
_ => unreachable!(),
}
@ -1291,7 +1292,7 @@ mod test {
];
let new_columns = vec![
ProcColumn::Pid,
ProcColumn::MemoryVal,
ProcColumn::MemoryValue,
ProcColumn::State,
ProcColumn::Name,
];
@ -1316,7 +1317,7 @@ mod test {
];
let original_columns = vec![
ProcColumn::Pid,
ProcColumn::MemoryVal,
ProcColumn::MemoryValue,
ProcColumn::State,
ProcColumn::Name,
];
@ -1381,7 +1382,7 @@ mod test {
];
let original_columns = vec![
ProcColumn::Pid,
ProcColumn::MemoryVal,
ProcColumn::MemoryValue,
ProcColumn::State,
ProcColumn::Name,
];
@ -1422,7 +1423,7 @@ mod test {
ProcColumn::Name,
];
let new_columns = vec![
ProcColumn::MemoryVal,
ProcColumn::MemoryValue,
ProcColumn::Pid,
ProcColumn::State,
ProcColumn::Name,

View file

@ -9,7 +9,7 @@ use crate::{
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
pub enum ProcColumn {
CpuPercent,
MemoryVal,
MemoryValue,
MemoryPercent,
Pid,
Count,
@ -23,9 +23,9 @@ pub enum ProcColumn {
User,
Time,
#[cfg(feature = "gpu")]
GpuMem,
GpuMemoryValue,
#[cfg(feature = "gpu")]
GpuMemPercent,
GpuMemoryPercent,
#[cfg(feature = "gpu")]
GpuUtilPercent,
}
@ -34,7 +34,7 @@ impl ColumnHeader for ProcColumn {
fn text(&self) -> Cow<'static, str> {
match self {
ProcColumn::CpuPercent => "CPU%",
ProcColumn::MemoryVal => "Mem",
ProcColumn::MemoryValue => "Mem",
ProcColumn::MemoryPercent => "Mem%",
ProcColumn::Pid => "PID",
ProcColumn::Count => "Count",
@ -48,9 +48,9 @@ impl ColumnHeader for ProcColumn {
ProcColumn::User => "User",
ProcColumn::Time => "Time",
#[cfg(feature = "gpu")]
ProcColumn::GpuMem => "GMem",
ProcColumn::GpuMemoryValue => "GMem",
#[cfg(feature = "gpu")]
ProcColumn::GpuMemPercent => "GMem%",
ProcColumn::GpuMemoryPercent => "GMem%",
#[cfg(feature = "gpu")]
ProcColumn::GpuUtilPercent => "GPU%",
}
@ -60,7 +60,7 @@ impl ColumnHeader for ProcColumn {
fn header(&self) -> Cow<'static, str> {
match self {
ProcColumn::CpuPercent => "CPU%(c)",
ProcColumn::MemoryVal => "Mem(m)",
ProcColumn::MemoryValue => "Mem(m)",
ProcColumn::MemoryPercent => "Mem%(m)",
ProcColumn::Pid => "PID(p)",
ProcColumn::Count => "Count",
@ -74,9 +74,9 @@ impl ColumnHeader for ProcColumn {
ProcColumn::User => "User",
ProcColumn::Time => "Time",
#[cfg(feature = "gpu")]
ProcColumn::GpuMem => "GMem",
ProcColumn::GpuMemoryValue => "GMem",
#[cfg(feature = "gpu")]
ProcColumn::GpuMemPercent => "GMem%",
ProcColumn::GpuMemoryPercent => "GMem%",
#[cfg(feature = "gpu")]
ProcColumn::GpuUtilPercent => "GPU%",
}
@ -94,7 +94,7 @@ impl SortsRow for ProcColumn {
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));
}
ProcColumn::Pid => {
@ -140,7 +140,7 @@ impl SortsRow for ProcColumn {
data.sort_by(|a, b| sort_partial_fn(descending)(a.time, b.time));
}
#[cfg(feature = "gpu")]
ProcColumn::GpuMem | ProcColumn::GpuMemPercent => {
ProcColumn::GpuMemoryValue | ProcColumn::GpuMemoryPercent => {
data.sort_by(|a, b| {
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 {
match column {
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::Count => self.num_similar.to_string(),
ProcColumn::Name | ProcColumn::Command => self.id.to_prefixed_string(),
@ -292,7 +292,9 @@ impl ProcWidgetData {
ProcColumn::User => self.user.clone(),
ProcColumn::Time => format_time(self.time),
#[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")]
ProcColumn::GpuUtilPercent => format!("{:.1}%", self.gpu_usage),
}
@ -310,7 +312,9 @@ impl DataToCell<ProcColumn> for ProcWidgetData {
// differences.
Some(match column {
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::Count => self.num_similar.to_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::Time => format_time(self.time).into(),
#[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")]
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(
search_query: &str, is_searching_whole_word: bool, is_ignoring_case: bool,
is_searching_with_regex: bool,
) -> QueryResult<Query> {
fn process_string_to_filter(query: &mut VecDeque<String>) -> QueryResult<Query> {
) -> QueryResult<ProcessQuery> {
fn process_string_to_filter(query: &mut VecDeque<String>) -> QueryResult<ProcessQuery> {
let lhs = process_or(query)?;
let mut list_of_ors = vec![lhs];
@ -86,7 +86,7 @@ pub(crate) fn parse_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> {
@ -532,12 +532,12 @@ pub(crate) fn parse_query(
Ok(process_filter)
}
pub struct Query {
pub struct ProcessQuery {
/// Remember, AND > OR, but AND must come after OR when we parse.
query: Vec<Or>,
}
impl Query {
impl ProcessQuery {
fn process_regexes(
&mut self, is_searching_whole_word: bool, is_ignoring_case: 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 {
f.write_fmt(format_args!("{:?}", self.query))
}