From 4870ff365a91b68eb0b9528c75375f01ce539e75 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Fri, 20 Jan 2023 00:08:02 -0500 Subject: [PATCH] refactor: change name of some stuff, add some comments (#992) * some quick refactoring first * add todo for bug report template --- .github/ISSUE_TEMPLATE/bug_report.yml | 2 ++ Cargo.toml | 2 +- src/app.rs | 10 +++++----- src/app/states.rs | 10 +++++----- src/lib.rs | 5 ----- src/options.rs | 6 +++--- src/widgets/process_table.rs | 10 +++++----- 7 files changed, 21 insertions(+), 24 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index ef237c73..af590166 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -88,6 +88,8 @@ body: **Note: if you installed from `bottom` from cargo, please ensure that you installed the right crate (https://crates.io/crates/bottom).** placeholder: Installed bottom through the Arch official repos. + # TODO: After some point also add in a `btm check` invocation + - type: textarea id: reproduce validations: diff --git a/Cargo.toml b/Cargo.toml index d1a2aa63..f5a0ad6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ doctest = true doc = true [profile.release] -# debug = true +# debug = true # Might be nice to have a custom profile for flamegraphs. # strip = false debug = 0 strip = "symbols" diff --git a/src/app.rs b/src/app.rs index 311aceb1..bbba3ea2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -12,7 +12,7 @@ pub use states::*; use typed_builder::*; use unicode_segmentation::{GraphemeCursor, UnicodeSegmentation}; -use crate::widgets::{ProcWidget, ProcWidgetMode}; +use crate::widgets::{ProcWidgetMode, ProcWidgetState}; use crate::{ constants, data_conversion::ConvertedData, @@ -1190,7 +1190,7 @@ impl App { .proc_state .get_mut_widget_state(self.current_widget.widget_id) { - proc_widget_state.select_column(ProcWidget::CPU); + proc_widget_state.select_column(ProcWidgetState::CPU); } } } @@ -1200,7 +1200,7 @@ impl App { .proc_state .get_mut_widget_state(self.current_widget.widget_id) { - proc_widget_state.select_column(ProcWidget::MEM); + proc_widget_state.select_column(ProcWidgetState::MEM); } } else if let Some(disk) = self .disk_state @@ -1215,7 +1215,7 @@ impl App { .proc_state .get_mut_widget_state(self.current_widget.widget_id) { - proc_widget_state.select_column(ProcWidget::PID_OR_COUNT); + proc_widget_state.select_column(ProcWidgetState::PID_OR_COUNT); } } else if let Some(disk) = self .disk_state @@ -1240,7 +1240,7 @@ impl App { .proc_state .get_mut_widget_state(self.current_widget.widget_id) { - proc_widget_state.select_column(ProcWidget::PROC_NAME_OR_CMD); + proc_widget_state.select_column(ProcWidgetState::PROC_NAME_OR_CMD); } } else if let Some(disk) = self .disk_state diff --git a/src/app/states.rs b/src/app/states.rs index e4141e4f..30e20291 100644 --- a/src/app/states.rs +++ b/src/app/states.rs @@ -9,7 +9,7 @@ use crate::{ utils::gen_util::str_width, widgets::{ BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState, - ProcWidget, TempWidgetState, + ProcWidgetState, TempWidgetState, }, }; @@ -251,19 +251,19 @@ impl AppSearchState { } pub struct ProcState { - pub widget_states: HashMap, + pub widget_states: HashMap, } impl ProcState { - pub fn init(widget_states: HashMap) -> Self { + pub fn init(widget_states: HashMap) -> Self { ProcState { widget_states } } - pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut ProcWidget> { + pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut ProcWidgetState> { self.widget_states.get_mut(&widget_id) } - pub fn get_widget_state(&self, widget_id: u64) -> Option<&ProcWidget> { + pub fn get_widget_state(&self, widget_id: u64) -> Option<&ProcWidgetState> { self.widget_states.get(&widget_id) } } diff --git a/src/lib.rs b/src/lib.rs index e6e32ee1..7f764e9c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -113,11 +113,6 @@ pub fn handle_key_event_or_break( ) -> bool { // debug!("KeyEvent: {:?}", event); - // TODO: [PASTE] Note that this does NOT support some emojis like flags. This is due to us - // catching PER CHARACTER right now WITH A forced throttle! This means multi-char will not work. - // We can solve this (when we do paste probably) while keeping the throttle (mainly meant for movement) - // by throttling after *bulk+singular* actions, not just singular ones. - if event.modifiers.is_empty() { // Required catch for searching - otherwise you couldn't search with q. if event.code == KeyCode::Char('q') && !app.is_in_search_widget() { diff --git a/src/options.rs b/src/options.rs index 5c160310..08690537 100644 --- a/src/options.rs +++ b/src/options.rs @@ -24,7 +24,7 @@ use crate::{ utils::error::{self, BottomError}, widgets::{ BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState, - ProcWidget, ProcWidgetMode, TempWidgetState, + ProcWidgetMode, ProcWidgetState, TempWidgetState, }, }; @@ -198,7 +198,7 @@ pub fn build_app( let mut cpu_state_map: HashMap = HashMap::new(); let mut mem_state_map: HashMap = HashMap::new(); let mut net_state_map: HashMap = HashMap::new(); - let mut proc_state_map: HashMap = HashMap::new(); + let mut proc_state_map: HashMap = HashMap::new(); let mut temp_state_map: HashMap = HashMap::new(); let mut disk_state_map: HashMap = HashMap::new(); let mut battery_state_map: HashMap = HashMap::new(); @@ -326,7 +326,7 @@ pub fn build_app( proc_state_map.insert( widget.widget_id, - ProcWidget::new( + ProcWidgetState::new( &app_config_fields, mode, is_case_sensitive, diff --git a/src/widgets/process_table.rs b/src/widgets/process_table.rs index 46d6ef60..03b74ad0 100644 --- a/src/widgets/process_table.rs +++ b/src/widgets/process_table.rs @@ -72,7 +72,7 @@ type ProcessTable = SortDataTable; type SortTable = DataTable, SortTableColumn>; type StringPidMap = FxHashMap>; -pub struct ProcWidget { +pub struct ProcWidgetState { pub mode: ProcWidgetMode, /// The state of the search box. @@ -92,7 +92,7 @@ pub struct ProcWidget { pub force_update_data: bool, } -impl ProcWidget { +impl ProcWidgetState { pub const PID_OR_COUNT: usize = 0; pub const PROC_NAME_OR_CMD: usize = 1; pub const CPU: usize = 2; @@ -222,7 +222,7 @@ impl ProcWidget { let id_pid_map = FxHashMap::default(); - let mut table = ProcWidget { + let mut table = ProcWidgetState { proc_search: process_search_state, table, sort_table, @@ -240,7 +240,7 @@ impl ProcWidget { pub fn is_using_command(&self) -> bool { self.table .columns - .get(ProcWidget::PROC_NAME_OR_CMD) + .get(ProcWidgetState::PROC_NAME_OR_CMD) .map(|col| matches!(col.inner(), ProcColumn::Command)) .unwrap_or(false) } @@ -248,7 +248,7 @@ impl ProcWidget { pub fn is_mem_percent(&self) -> bool { self.table .columns - .get(ProcWidget::MEM) + .get(ProcWidgetState::MEM) .map(|col| matches!(col.inner(), ProcColumn::MemoryPercent)) .unwrap_or(false) }