summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--src/app.rs450
-rw-r--r--src/app/data_farmer.rs2
-rw-r--r--src/app/data_harvester.rs2
-rw-r--r--src/app/data_harvester/network/heim.rs2
-rw-r--r--src/app/data_harvester/processes.rs1
-rw-r--r--src/app/data_harvester/processes/linux.rs2
-rw-r--r--src/app/layout_manager.rs5
-rw-r--r--src/app/query.rs2
-rw-r--r--src/app/states.rs940
-rw-r--r--src/app/widgets.rs102
-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
-rw-r--r--src/bin/main.rs6
-rw-r--r--src/canvas.rs5
-rw-r--r--src/canvas/dialogs/dd_dialog.rs52
-rw-r--r--src/canvas/widgets/mem_graph.rs249
-rw-r--r--src/canvas/widgets/network_graph.rs770
-rw-r--r--src/canvas/widgets/process_table.rs911
-rw-r--r--src/clap.rs7
-rw-r--r--src/constants.rs2
-rw-r--r--src/data_conversion.rs161
-rw-r--r--src/lib.rs4
-rw-r--r--src/options.rs2
-rw-r--r--src/utils/error.rs1
-rw-r--r--tests/layout_management_tests.rs4
-rw-r--r--tests/layout_movement_tests.rs4
38 files changed, 309 insertions, 4098 deletions
diff --git a/src/app.rs b/src/app.rs
index ec577661..4b58b014 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -7,24 +7,20 @@ mod process_killer;
pub mod query;
pub mod widgets;
-use std::{collections::HashMap, time::Instant};
+use std::time::Instant;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent};
use fxhash::FxHashMap;
use indextree::{Arena, NodeId};
-use unicode_width::UnicodeWidthStr;
pub use data_farmer::*;
-use data_harvester::{processes, temperature};
+use data_harvester::temperature;
pub use filter::*;
use layout_manager::*;
pub use widgets::*;
use crate::{
- canvas, constants,
- units::data_units::DataUnit,
- utils::error::{BottomError, Result},
- BottomEvent, Pid,
+ canvas, constants, units::data_units::DataUnit, utils::error::Result, BottomEvent, Pid,
};
use self::event::{ComponentEventResult, EventResult, ReturnSignal};
@@ -91,7 +87,7 @@ pub struct AppConfigFields {
pub hide_time: bool,
pub autohide_time: bool,
pub use_old_network_legend: bool,
- pub table_gap: u16, // TODO: Just make this a bool...
+ pub table_gap: u16, // TODO: [Config, Refactor] Just make this a bool...
pub disable_click: bool,
pub no_write: bool,
pub show_table_scroll_position: bool,
@@ -129,23 +125,8 @@ pub struct AppState {
pub filters: DataFilters,
pub app_config_fields: AppConfigFields,
- // --- Eventually delete/rewrite ---
+ // --- FIXME: TO DELETE/REWRITE ---
pub delete_dialog_state: AppDeleteDialogState,
-
- // --- TO DELETE ---
- pub cpu_state: CpuState,
- pub mem_state: MemState,
- pub net_state: NetState,
- pub proc_state: ProcState,
- pub temp_state: TempState,
- pub disk_state: DiskState,
- pub battery_state: BatteryState,
- pub basic_table_widget_state: Option<BasicTableWidgetState>,
- pub widget_map: HashMap<u64, BottomWidget>,
- pub current_widget: BottomWidget,
-
- pub basic_mode_use_percent: bool,
-
pub is_force_redraw: bool,
pub is_determining_widget_boundary: bool,
@@ -190,17 +171,6 @@ impl AppState {
data_collection: Default::default(),
is_expanded: Default::default(),
delete_dialog_state: Default::default(),
- cpu_state: Default::default(),
- mem_state: Default::default(),
- net_state: Default::default(),
- proc_state: Default::default(),
- temp_state: Default::default(),
- disk_state: Default::default(),
- battery_state: Default::default(),
- basic_table_widget_state: Default::default(),
- widget_map: Default::default(),
- current_widget: Default::default(),
- basic_mode_use_percent: Default::default(),
is_force_redraw: Default::default(),
is_determining_widget_boundary: Default::default(),
frozen_state: Default::default(),
@@ -484,7 +454,7 @@ impl AppState {
BottomEvent::Update(new_data) => {
self.data_collection.eat_data(new_data);
- // TODO: Optimization for dialogs; don't redraw here.
+ // TODO: [Optimization] Optimization for dialogs - don't redraw on an update!
if !self.is_frozen() {
let data_collection = &self.data_collection;
@@ -509,104 +479,6 @@ impl AppState {
}
}
- pub fn is_in_search_widget(&self) -> bool {
- matches!(
- self.current_widget.widget_type,
- BottomWidgetType::ProcSearch
- )
- }
-
- fn is_in_dialog(&self) -> bool {
- self.delete_dialog_state.is_showing_dd
- }
-
- fn ignore_normal_keybinds(&self) -> bool {
- self.is_in_dialog()
- }
-
- pub fn on_tab(&mut self) {
- // Allow usage whilst only in processes
-
- if !self.ignore_normal_keybinds() {
- match self.current_widget.widget_type {
- BottomWidgetType::Cpu => {
- if let Some(cpu_widget_state) = self
- .cpu_state
- .get_mut_widget_state(self.current_widget.widget_id)
- {
- cpu_widget_state.is_multi_graph_mode =
- !cpu_widget_state.is_multi_graph_mode;
- }
- }
- BottomWidgetType::Proc => {
- if let Some(proc_widget_state) = self
- .proc_state
- .get_mut_widget_state(self.current_widget.widget_id)
- {
- // Do NOT allow when in tree mode!
- if !proc_widget_state.is_tree_mode {
- // Toggles process widget grouping state
- proc_widget_state.is_grouped = !(proc_widget_state.is_grouped);
-
- // Forcefully switch off column if we were on it...
- if (proc_widget_state.is_grouped
- && (proc_widget_state.process_sorting_type
- == processes::ProcessSorting::Pid
- || proc_widget_state.process_sorting_type
- == processes::ProcessSorting::User
- || proc_widget_state.process_sorting_type
- == processes::ProcessSorting::State))
- || (!proc_widget_state.is_grouped
- && proc_widget_state.process_sorting_type
- == processes::ProcessSorting::Count)
- {
- proc_widget_state.process_sorting_type =
- processes::ProcessSorting::CpuPercent; // Go back to default, negate PID for group
- proc_widget_state.is_process_sort_descending = true;
- }
-
- proc_widget_state.columns.set_to_sorted_index_from_type(
- &proc_widget_state.process_sorting_type,
- );
-
- proc_widget_state.columns.try_set(
- &processes::ProcessSorting::State,
- !(proc_widget_state.is_grouped),
- );
-
- #[cfg(target_family = "unix")]
- proc_widget_state.columns.try_set(
- &processes::ProcessSorting::User,
- !(proc_widget_state.is_grouped),
- );
-
- proc_widget_state
- .columns
- .toggle(&processes::ProcessSorting::Count);
- proc_widget_state
- .columns
- .toggle(&processes::ProcessSorting::Pid);
-
- proc_widget_state.requires_redraw = true;
- self.proc_state.force_update = Some(self.current_widget.widget_id);
- }
- }
- }
- _ => {}
- }
- }
- }
-
- /// I don't like this, but removing it causes a bunch of breakage.
- /// Use ``proc_widget_state.is_grouped`` if possible!
- pub fn is_grouped(&self, widget_id: u64) -> bool {
- if let Some(proc_widget_state) = self.proc_state.widget_states.get(&widget_id) {
- proc_widget_state.is_grouped
- } else {
- false
- }
- }
-
#[cfg(target_family = "unix")]
pub fn on_number(&mut self, number_char: char) {
if self.delete_dialog_state.is_showing_dd {
@@ -642,149 +514,122 @@ impl AppState {
}
pub fn on_left_key(&mut self) {
- if !self.is_in_dialog() {
- match self.current_widget.widget_type {
- BottomWidgetType::ProcSearch => {
- let is_in_search_widget = self.is_in_search_widget();
- if let Some(proc_widget_state) = self
- .proc_state
- .get_mut_widget_state(self.current_widget.widget_id - 1)
- {
- if is_in_search_widget {
- let prev_cursor = proc_widget_state.get_search_cursor_position();
- proc_widget_state
- .search_walk_back(proc_widget_state.get_search_cursor_position());
- if proc_widget_state.get_search_cursor_position() < prev_cursor {
- let str_slice = &proc_widget_state
- .process_search_state
- .search_state
- .current_search_query
- [proc_widget_state.get_search_cursor_position()..prev_cursor];
- proc_widget_state
- .process_search_state
- .search_state
- .char_cursor_position -= UnicodeWidthStr::width(str_slice);
- proc_widget_state
- .process_search_state
- .search_state
- .cursor_direction = CursorDirection::Left;
- }
- }
- }
- }
- BottomWidgetType::Battery => {
- if !self.canvas_data.battery_data.is_empty() {
- if let Some(battery_widget_state) = self
- .battery_state
- .get_mut_widget_state(self.current_widget.widget_id)
- {
- if battery_widget_state.currently_selected_battery_index > 0 {
- battery_widget_state.currently_selected_battery_index -= 1;
- }
- }
- }
- }
- _ => {}
- }
- } else if self.delete_dialog_state.is_showing_dd {
- #[cfg(target_family = "unix")]
- {
- if self.app_config_fields.is_advanced_kill {
- match self.delete_dialog_state.selected_signal {
- KillSignal::Kill(prev_signal) => {
- self.delete_dialog_state.selected_signal = match prev_signal - 1 {
- 0 => KillSignal::Cancel,
- // 32+33 are skipped
- 33 => KillSignal::Kill(31),
- signal => KillSignal::Kill(signal),
- };
- }
- KillSignal::Cancel => {}
- };
- } else {
- self.delete_dialog_state.selected_signal = KillSignal::default();
- }
- }
- #[cfg(target_os = "windows")]
- {
- self.delete_dialog_state.selected_signal = KillSignal::Kill(1);
- }
- }
+ // if !self.is_in_dialog() {
+ // match self.current_widget.widget_type {
+ // BottomWidgetType::ProcSearch => {
+ // let is_in_search_widget = self.is_in_search_widget();
+ // if let Some(proc_widget_state) = self
+ // .proc_state
+ // .get_mut_widget_state(self.current_widget.widget_id - 1)
+ // {
+ // if is_in_search_widget {
+ // let prev_cursor = proc_widget_state.get_search_cursor_position();
+ // proc_widget_state
+ // .search_walk_back(proc_widget_state.get_search_cursor_position());
+ // if proc_widget_state.get_search_cursor_position() < prev_cursor {
+ // let str_slice = &proc_widget_state
+ // .process_search_state
+ // .search_state
+ // .current_search_query
+ // [proc_widget_state.get_search_cursor_position()..prev_cursor];
+ // proc_widget_state
+ // .process_search_state
+ // .search_state
+ // .char_cursor_position -= UnicodeWidthStr::width(str_slice);
+ // proc_widget_state
+ // .process_search_state
+ // .search_state
+ // .cursor_direction = CursorDirection::Left;
+ // }
+ // }
+ // }
+ // }
+ // _ => {}
+ // }
+ // } else if self.delete_dialog_state.is_showing_dd {
+ // #[cfg(target_family = "unix")]
+ // {
+ // if self.app_config_fields.is_advanced_kill {
+ // match self.delete_dialog_state.selected_signal {
+ // KillSignal::Kill(prev_signal) => {
+ // self.delete_dialog_state.selected_signal = match prev_signal - 1 {
+ // 0 => KillSignal::Cancel,
+ // // 32+33 are skipped
+ // 33 => KillSignal::Kill(31),
+ // signal => KillSignal::Kill(signal),
+ // };
+ // }
+ // KillSignal::Cancel => {}
+ // };
+ // } else {
+ // self.delete_dialog_state.selected_signal = KillSignal::default();
+ // }
+ // }
+ // #[cfg(target_os = "windows")]
+ // {
+ // self.delete_dialog_state.selected_signal = KillSignal::Kill(1);
+ // }
+ // }
}
pub fn on_right_key(&mut self) {
- if !self.is_in_dialog() {
- match self.current_widget.widget_type {
- BottomWidgetType::ProcSearch => {
- let is_in_search_widget = self.is_in_search_widget();
- if let Some(proc_widget_state) = self
- .proc_state
- .get_mut_widget_state(self.current_widget.widget_id - 1)
- {
- if is_in_search_widget {
- let prev_cursor = proc_widget_state.get_search_cursor_position();
- proc_widget_state.search_walk_forward(
- proc_widget_state.get_search_cursor_position(),
- );
- if proc_widget_state.get_search_cursor_position() > prev_cursor {
- let str_slice = &proc_widget_state
- .process_search_state
- .search_state
- .current_search_query
- [prev_cursor..proc_widget_state.get_search_cursor_position()];
- proc_widget_state
- .process_search_state
- .search_state
- .char_cursor_position += UnicodeWidthStr::width(str_slice);
- proc_widget_state
- .process_search_state
- .search_state
- .cursor_direction = CursorDirection::Right;
- }
- }
- }
- }
- BottomWidgetType::Battery => {
- if !self.canvas_data.battery_data.is_empty() {
- let battery_count = self.canvas_data.battery_data.len();
- if let Some(battery_widget_state) = self
- .battery_state
- .get_mut_widget_state(self.current_widget.widget_id)
- {
- if battery_widget_state.currently_selected_battery_index
- < battery_count - 1
- {
- battery_widget_state.currently_selected_battery_index += 1;
- }
- }
- }
- }
- _ => {}
- }
- } else if self.delete_dialog_state.is_showing_dd {
- #[cfg(target_family = "unix")]
- {
- if self.app_config_fields.is_advanced_kill {
- let new_signal = match self.delete_dialog_state.selected_signal {
- KillSignal::Cancel => 1,
- // 32+33 are skipped
- #[cfg(target_os = "linux")]
- KillSignal::Kill(31) => 34,
- #[cfg(target_os = "macos")]
- KillSignal::Kill(31) => 31,
- KillSignal::Kill(64) => 64,
- KillSignal::Kill(signal) => signal + 1,
- };
- self.delete_dialog_state.selected_signal = KillSignal::Kill(new_signal);
- } else {
- self.delete_dialog_state.selected_signal = KillSignal::Cancel;
- }
- }
- #[cfg(target_os = "windows")]
- {
- self.delete_dialog_state.selected_signal = KillSignal::Cancel;
- }
- }
+ // if !self.is_in_dialog() {
+ // match self.current_widget.widget_type {
+ // BottomWidgetType::ProcSearch => {
+ // let is_in_search_widget = self.is_in_search_widget();
+ // if let Some(proc_widget_state) = self
+ // .proc_state
+ // .get_mut_widget_state(self.current_widget.widget_id - 1)
+ // {
+ // if is_in_search_widget {
+ // let prev_cursor = proc_widget_state.get_search_cursor_position();
+ // proc_widget_state.search_walk_forward(
+ // proc_widget_state.get_search_cursor_position(),
+ // );
+ // if proc_widget_state.get_search_cursor_position() > prev_cursor {
+ // let str_slice = &proc_widget_state
+ // .process_search_state
+ // .search_state
+ // .current_search_query
+ // [prev_cursor..proc_widget_state.get_search_cursor_position()];
+ // proc_widget_state
+ // .process_search_state
+ // .search_state
+ // .char_cursor_position += UnicodeWidthStr::width(str_slice);
+ // proc_widget_state
+ // .process_search_state
+ // .search_state
+ // .cursor_direction = CursorDirection::Right;
+ // }
+ // }
+ // }
+ // }
+ // _ => {}
+ // }
+ // } else if self.delete_dialog_state.is_showing_dd {
+ // #[cfg(target_family = "unix")]
+ // {
+ // if self.app_config_fields.is_advanced_kill {
+ // let new_signal = match self.delete_dialog_state.selected_signal {
+ // KillSignal::Cancel => 1,
+ // // 32+33 are skipped
+ // #[cfg(target_os = "linux")]
+ // KillSignal::Kill(31) => 34,
+ // #[cfg(target_os = "macos")]
+ // KillSignal::Kill(31) => 31,
+ // KillSignal::Kill(64) => 64,
+ // KillSignal::Kill(signal) => signal + 1,
+ // };
+ // self.delete_dialog_state.selected_signal = KillSignal::Kill(new_signal);
+ // } else {
+ // self.delete_dialog_state.selected_signal = KillSignal::Cancel;
+ // }
+ // }
+ // #[cfg(target_os = "windows")]
+ // {
+ // self.delete_dialog_state.selected_signal = KillSignal::Cancel;
+ // }
+ // }
}
pub fn start_killing_process(&mut self) {
@@ -828,35 +673,38 @@ impl AppState {
}
pub fn kill_highlighted_process(&mut self) -> Result<()> {
- if let BottomWidgetType::Proc = self.current_widget.widget_type {
- if let Some(current_selected_processes) = &self.to_delete_process_list {
- #[cfg(target_family = "unix")]
- let signal = match self.delete_dialog_state.selected_signal {
- KillSignal::Kill(sig) => sig,
- KillSignal::Cancel => 15, // should never happen, so just TERM
- };
- for pid in &current_selected_processes.1 {
- #[cfg(target_family = "unix")]
- {
- process_killer::kill_process_given_pid(*pid, signal)?;
- }
- #[cfg(target_os = "windows")]
- {
- process_killer::kill_process_given_pid(*pid)?;
- }
- }
- }
- self.to_delete_process_list = None;
- Ok(())
- } else {
- Err(BottomError::GenericError(
- "Cannot kill processes if the current widget is not the Process widget!"
- .to_string(),
- ))
- }
+ // if let BottomWidgetType::Proc = self.current_widget.widget_type {
+ // if let Some(current_selected_processes) = &self.to_delete_process_list {
+ // #[cfg(target_family = "unix")]
+ // let signal = match self.delete_dialog_state.selected_signal {
+ // KillSignal::Kill(sig) => sig,
+ // KillSignal::Cancel => 15, // should never happen, so just TERM
+ // };
+ // for pid in &current_selected_processes.1 {
+ // #[cfg(target_family = "unix")]
+ // {
+ // process_killer::kill_process_given_pid(*pid, signal)?;
+ // }
+ // #[cfg(target_os = "windows")]
+ // {
+ // process_killer::kill_process_given_pid(*pid)?;
+ // }
+ // }
+ // }
+ // self.to_delete_process_list = None;
+ // Ok(())
+ // } else {
+ // Err(BottomError::GenericError(
+ // "Cannot kill processes if the current widget is not the Process widget!"
+ // .to_string(),
+ // ))
+ // }
+
+ Ok(())
}
pub fn get_to_delete_processes(&self) -> Option<(String, Vec<Pid>)> {
- self.to_delete_process_list.clone()
+ // self.to_delete_process_list.clone()
+ todo!()
}
}
diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs
index 7badfe57..6b850f8b 100644
--- a/src/app/data_farmer.rs
+++ b/src/app/data_farmer.rs
@@ -319,7 +319,7 @@ impl DataCollection {
}
fn eat_proc(&mut self, list_of_processes: Vec<processes::ProcessHarvest>) {
- // TODO: Probably more efficient to do this in the data collection step, but it's fine for now.
+ // TODO: [Optimization] Probably more efficient to do this in the data collection step, but it's fine for now.
self.process_name_pid_map.clear();
self.process_cmd_pid_map.clear();
list_of_processes.iter().for_each(|process_harvest| {
diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs
index 2f5613cc..2672022d 100644
--- a/src/app/data_harvester.rs
+++ b/src/app/data_harvester.rs
@@ -149,7 +149,7 @@ impl DataCollector {
self.sys.refresh_memory();
self.mem_total_kb = self.sys.get_total_memory();
- // TODO: Would be good to get this and network list running on a timer instead...?
+ // TODO: [Data Collection] Would be good to get this and network list running on a timer instead...?
// Refresh components list once...
if self.widgets_to_harvest.use_temp {
self.sys.refresh_components_list();
diff --git a/src/app/data_harvester/network/heim.rs b/src/app/data_harvester/network/heim.rs
index 3c12fd73..6d05cc60 100644
--- a/src/app/data_harvester/network/heim.rs
+++ b/src/app/data_harvester/network/heim.rs
@@ -39,7 +39,7 @@ pub async fn get_network_data(
};
if to_keep {
- // TODO: Use bytes as the default instead, perhaps?
+ // TODO: [Optimization] Optimization (Potential)Use bytes as the default instead, perhaps?
// Since you might have to do a double conversion (bytes -> bits -> bytes) in some cases;
// but if you stick to bytes, then in the bytes, case, you do no conversion, and in the bits case,
// you only do one conversion...
diff --git a/src/app/data_harvester/processes.rs b/src/app/data_harvester/processes.rs
index 151d3a55..4b09a078 100644
--- a/src/app/data_harvester/processes.rs
+++ b/src/app/data_harvester/processes.rs
@@ -27,6 +27,7 @@ use std::borrow::Cow;
use crate::Pid;
+// FIXME: [URGENT] Delete this.
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub enum ProcessSorting {
CpuPercent,
diff --git a/src/app/data_harvester/processes/linux.rs b/src/app/data_harvester/processes/linux.rs
index c1b7f4e8..aad67adf 100644
--- a/src/app/data_harvester/processes/linux.rs
+++ b/src/app/data_harvester/processes/linux.rs
@@ -229,8 +229,6 @@ pub fn get_process_data(
pid_mapping: &mut FxHashMap<Pid, PrevProcDetails>, use_current_cpu_total: bool,
time_difference_in_secs: u64, mem_total_kb: u64, user_table: &mut UserTable,
) -> crate::utils::error::Result<Vec<ProcessHarvest>> {
- // TODO: [PROC THREADS] Add threads
-
if let Ok((cpu_usage, cpu_fraction)) = cpu_usage_calculation(prev_idle, prev_non_idle) {
let mut pids_to_clear: FxHashSet<Pid> = pid_mapping.keys().cloned().collect();
diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs
index 48e97774..bde3febb 100644
--- a/src/app/layout_manager.rs
+++ b/src/app/layout_manager.rs
@@ -332,7 +332,7 @@ pub struct LayoutCreationOutput {
/// Creates a new [`Arena<LayoutNode>`] from the given config and returns it, along with the [`NodeId`] representing
/// the root of the newly created [`Arena`], a mapping from [`NodeId`]s to [`BottomWidget`]s, and optionally, a default
/// selected [`NodeId`].
-// FIXME: This is currently jury-rigged "glue" just to work with the existing config system! We are NOT keeping it like this, it's too awful to keep like this!
+// FIXME: [AFTER REFACTOR] This is