2020-01-25 21:36:14 +00:00
|
|
|
pub mod data_harvester;
|
|
|
|
use data_harvester::{processes, temperature};
|
2019-12-16 07:21:44 +00:00
|
|
|
use std::time::Instant;
|
|
|
|
|
2020-01-29 02:24:52 +00:00
|
|
|
pub mod data_farmer;
|
|
|
|
use data_farmer::*;
|
2020-01-25 21:36:14 +00:00
|
|
|
|
2020-02-02 04:49:44 +00:00
|
|
|
use crate::{canvas, constants, data_conversion::ConvertedProcessData, utils::error::Result};
|
2019-09-08 23:56:23 +00:00
|
|
|
|
2019-09-16 23:05:44 +00:00
|
|
|
mod process_killer;
|
|
|
|
|
2019-09-17 02:39:57 +00:00
|
|
|
#[derive(Clone, Copy)]
|
2020-02-02 04:49:44 +00:00
|
|
|
pub enum WidgetPosition {
|
2019-12-28 06:20:05 +00:00
|
|
|
Cpu,
|
|
|
|
Mem,
|
|
|
|
Disk,
|
|
|
|
Temp,
|
|
|
|
Network,
|
|
|
|
Process,
|
2020-01-12 20:41:27 +00:00
|
|
|
ProcessSearch,
|
2019-09-15 18:16:18 +00:00
|
|
|
}
|
|
|
|
|
2020-01-11 05:42:03 +00:00
|
|
|
#[derive(Debug)]
|
2019-09-16 20:18:42 +00:00
|
|
|
pub enum ScrollDirection {
|
2020-01-11 05:42:03 +00:00
|
|
|
// UP means scrolling up --- this usually DECREMENTS
|
2019-09-16 20:18:42 +00:00
|
|
|
UP,
|
2020-01-11 05:42:03 +00:00
|
|
|
// DOWN means scrolling down --- this usually INCREMENTS
|
2019-09-16 20:18:42 +00:00
|
|
|
DOWN,
|
|
|
|
}
|
|
|
|
|
2020-01-12 23:45:11 +00:00
|
|
|
lazy_static! {
|
|
|
|
static ref BASE_REGEX: std::result::Result<regex::Regex, regex::Error> =
|
|
|
|
regex::Regex::new(".*");
|
|
|
|
}
|
|
|
|
|
2020-01-25 21:36:14 +00:00
|
|
|
/// AppConfigFields is meant to cover basic fields that would normally be set
|
|
|
|
/// by config files or launch options. Don't need to be mutable (set and forget).
|
|
|
|
pub struct AppConfigFields {
|
|
|
|
pub update_rate_in_milliseconds: u64,
|
|
|
|
pub temperature_type: temperature::TemperatureType,
|
|
|
|
pub use_dot: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// AppScrollWidgetState deals with fields for a scrollable app's current state.
|
|
|
|
pub struct AppScrollWidgetState {
|
|
|
|
pub widget_scroll_position: i64,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// AppSearchState only deals with the search's state.
|
|
|
|
pub struct AppSearchState {}
|
|
|
|
|
|
|
|
// TODO: [OPT] Group like fields together... this is kinda gross to step through
|
2019-09-14 20:46:14 +00:00
|
|
|
pub struct App {
|
2019-12-28 06:20:05 +00:00
|
|
|
// Sorting
|
2019-12-06 05:57:04 +00:00
|
|
|
pub process_sorting_type: processes::ProcessSorting,
|
|
|
|
pub process_sorting_reverse: bool,
|
2020-01-18 00:19:20 +00:00
|
|
|
pub update_process_gui: bool,
|
2019-12-28 06:20:05 +00:00
|
|
|
// Positioning
|
2020-01-01 22:55:15 +00:00
|
|
|
pub scroll_direction: ScrollDirection,
|
2019-12-06 05:57:04 +00:00
|
|
|
pub currently_selected_process_position: i64,
|
|
|
|
pub currently_selected_disk_position: i64,
|
|
|
|
pub currently_selected_temperature_position: i64,
|
2020-01-01 22:55:15 +00:00
|
|
|
pub currently_selected_cpu_table_position: i64,
|
2019-12-28 06:20:05 +00:00
|
|
|
pub previous_disk_position: i64,
|
|
|
|
pub previous_temp_position: i64,
|
|
|
|
pub previous_process_position: i64,
|
2020-01-01 22:55:15 +00:00
|
|
|
pub previous_cpu_table_position: i64,
|
2019-12-06 05:57:04 +00:00
|
|
|
pub temperature_type: temperature::TemperatureType,
|
|
|
|
pub update_rate_in_milliseconds: u64,
|
|
|
|
pub show_average_cpu: bool,
|
2020-02-02 04:49:44 +00:00
|
|
|
pub current_widget_selected: WidgetPosition,
|
2020-01-25 21:36:14 +00:00
|
|
|
pub data: data_harvester::Data,
|
2019-12-26 04:30:57 +00:00
|
|
|
awaiting_second_char: bool,
|
|
|
|
second_char: char,
|
2019-12-06 05:57:04 +00:00
|
|
|
pub use_dot: bool,
|
|
|
|
pub show_help: bool,
|
2020-01-02 04:39:47 +00:00
|
|
|
pub show_dd: bool,
|
|
|
|
pub dd_err: Option<String>,
|
2020-02-02 04:49:44 +00:00
|
|
|
to_delete_process_list: Option<Vec<ConvertedProcessData>>,
|
2019-12-06 05:57:04 +00:00
|
|
|
pub is_frozen: bool,
|
2019-12-28 03:39:25 +00:00
|
|
|
pub left_legend: bool,
|
2020-01-01 03:24:54 +00:00
|
|
|
pub use_current_cpu_total: bool,
|
2019-12-16 07:21:44 +00:00
|
|
|
last_key_press: Instant,
|
2020-02-02 04:49:44 +00:00
|
|
|
pub canvas_data: canvas::DisplayableData,
|
2020-01-08 04:39:52 +00:00
|
|
|
enable_grouping: bool,
|
2020-01-25 21:36:14 +00:00
|
|
|
enable_searching: bool,
|
2020-01-12 20:41:27 +00:00
|
|
|
current_search_query: String,
|
|
|
|
searching_pid: bool,
|
2020-01-16 03:49:47 +00:00
|
|
|
pub use_simple: bool,
|
2020-01-12 23:45:11 +00:00
|
|
|
current_regex: std::result::Result<regex::Regex, regex::Error>,
|
2020-01-17 02:33:06 +00:00
|
|
|
current_cursor_position: usize,
|
2020-01-25 21:36:14 +00:00
|
|
|
pub data_collection: DataCollection,
|
2019-09-08 23:56:23 +00:00
|
|
|
}
|
|
|
|
|
2019-09-14 20:46:14 +00:00
|
|
|
impl App {
|
2019-12-28 03:39:25 +00:00
|
|
|
pub fn new(
|
2020-01-08 04:40:53 +00:00
|
|
|
show_average_cpu: bool, temperature_type: temperature::TemperatureType,
|
|
|
|
update_rate_in_milliseconds: u64, use_dot: bool, left_legend: bool,
|
2020-01-01 03:24:54 +00:00
|
|
|
use_current_cpu_total: bool,
|
2019-12-28 03:39:25 +00:00
|
|
|
) -> App {
|
2019-09-09 04:09:58 +00:00
|
|
|
App {
|
2019-12-06 05:57:04 +00:00
|
|
|
process_sorting_type: processes::ProcessSorting::CPU,
|
|
|
|
process_sorting_reverse: true,
|
2020-01-18 00:19:20 +00:00
|
|
|
update_process_gui: false,
|
2019-09-14 20:46:14 +00:00
|
|
|
temperature_type,
|
|
|
|
update_rate_in_milliseconds,
|
2019-09-14 21:07:18 +00:00
|
|
|
show_average_cpu,
|
2020-02-02 04:49:44 +00:00
|
|
|
current_widget_selected: WidgetPosition::Process,
|
2019-12-06 05:57:04 +00:00
|
|
|
scroll_direction: ScrollDirection::DOWN,
|
2020-01-01 22:55:15 +00:00
|
|
|
currently_selected_process_position: 0,
|
|
|
|
currently_selected_disk_position: 0,
|
|
|
|
currently_selected_temperature_position: 0,
|
|
|
|
currently_selected_cpu_table_position: 0,
|
2019-12-06 05:57:04 +00:00
|
|
|
previous_process_position: 0,
|
|
|
|
previous_disk_position: 0,
|
|
|
|
previous_temp_position: 0,
|
2020-01-01 22:55:15 +00:00
|
|
|
previous_cpu_table_position: 0,
|
2020-01-25 21:36:14 +00:00
|
|
|
data: data_harvester::Data::default(),
|
2019-12-26 04:30:57 +00:00
|
|
|
awaiting_second_char: false,
|
|
|
|
second_char: ' ',
|
2019-09-25 04:48:53 +00:00
|
|
|
use_dot,
|
2019-12-06 05:57:04 +00:00
|
|
|
show_help: false,
|
2020-01-02 04:39:47 +00:00
|
|
|
show_dd: false,
|
|
|
|
dd_err: None,
|
2020-01-09 03:36:36 +00:00
|
|
|
to_delete_process_list: None,
|
2019-12-06 05:57:04 +00:00
|
|
|
is_frozen: false,
|
2019-12-28 03:39:25 +00:00
|
|
|
left_legend,
|
2020-01-01 03:24:54 +00:00
|
|
|
use_current_cpu_total,
|
2019-12-16 07:21:44 +00:00
|
|
|
last_key_press: Instant::now(),
|
2020-02-02 04:49:44 +00:00
|
|
|
canvas_data: canvas::DisplayableData::default(),
|
2020-01-08 04:39:52 +00:00
|
|
|
enable_grouping: false,
|
2020-01-12 18:15:35 +00:00
|
|
|
enable_searching: false,
|
2020-01-12 20:41:27 +00:00
|
|
|
current_search_query: String::default(),
|
|
|
|
searching_pid: false,
|
2020-01-16 03:49:47 +00:00
|
|
|
use_simple: false,
|
|
|
|
current_regex: BASE_REGEX.clone(), //TODO: [OPT] seems like a thing we can switch to lifetimes to avoid cloning
|
2020-01-17 02:33:06 +00:00
|
|
|
current_cursor_position: 0,
|
2020-01-25 21:36:14 +00:00
|
|
|
data_collection: DataCollection::default(),
|
2019-09-09 04:09:58 +00:00
|
|
|
}
|
2019-09-08 23:56:23 +00:00
|
|
|
}
|
|
|
|
|
2019-12-16 07:21:44 +00:00
|
|
|
pub fn reset(&mut self) {
|
|
|
|
self.reset_multi_tap_keys();
|
2020-01-02 04:39:47 +00:00
|
|
|
self.show_help = false;
|
|
|
|
self.show_dd = false;
|
2020-01-12 20:41:27 +00:00
|
|
|
if self.enable_searching {
|
2020-02-02 04:49:44 +00:00
|
|
|
self.current_widget_selected = WidgetPosition::Process;
|
2020-01-12 20:41:27 +00:00
|
|
|
self.enable_searching = false;
|
|
|
|
}
|
|
|
|
self.current_search_query = String::new();
|
|
|
|
self.searching_pid = false;
|
2020-01-09 03:36:36 +00:00
|
|
|
self.to_delete_process_list = None;
|
2020-01-02 04:39:47 +00:00
|
|
|
self.dd_err = None;
|
2019-12-16 07:21:44 +00:00
|
|
|
}
|
|
|
|
|
2020-01-12 20:41:27 +00:00
|
|
|
pub fn on_esc(&mut self) {
|
|
|
|
self.reset_multi_tap_keys();
|
|
|
|
if self.is_in_dialog() {
|
|
|
|
self.show_help = false;
|
|
|
|
self.show_dd = false;
|
|
|
|
self.to_delete_process_list = None;
|
|
|
|
self.dd_err = None;
|
|
|
|
} else if self.enable_searching {
|
2020-02-02 04:49:44 +00:00
|
|
|
self.current_widget_selected = WidgetPosition::Process;
|
2020-01-12 20:41:27 +00:00
|
|
|
self.enable_searching = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 07:21:44 +00:00
|
|
|
fn reset_multi_tap_keys(&mut self) {
|
2019-12-26 04:30:57 +00:00
|
|
|
self.awaiting_second_char = false;
|
|
|
|
self.second_char = ' ';
|
2019-12-16 07:21:44 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 04:39:47 +00:00
|
|
|
fn is_in_dialog(&self) -> bool {
|
|
|
|
self.show_help || self.show_dd
|
|
|
|
}
|
2019-10-10 02:00:10 +00:00
|
|
|
|
2020-01-08 04:39:52 +00:00
|
|
|
pub fn toggle_grouping(&mut self) {
|
|
|
|
// Disallow usage whilst in a dialog and only in processes
|
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::Process = self.current_widget_selected {
|
2020-01-08 04:39:52 +00:00
|
|
|
self.enable_grouping = !(self.enable_grouping);
|
2020-02-02 04:49:44 +00:00
|
|
|
self.update_process_gui = true;
|
2020-01-08 04:39:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-09 03:54:14 +00:00
|
|
|
pub fn on_tab(&mut self) {
|
2020-02-02 04:49:44 +00:00
|
|
|
match self.current_widget_selected {
|
|
|
|
WidgetPosition::Process => self.toggle_grouping(),
|
|
|
|
WidgetPosition::Disk => {}
|
2020-01-09 03:54:14 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 04:39:52 +00:00
|
|
|
pub fn is_grouped(&self) -> bool {
|
|
|
|
self.enable_grouping
|
|
|
|
}
|
|
|
|
|
2020-01-29 02:24:52 +00:00
|
|
|
pub fn enable_searching(&mut self) {
|
2020-01-12 18:15:35 +00:00
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
match self.current_widget_selected {
|
|
|
|
WidgetPosition::Process | WidgetPosition::ProcessSearch => {
|
2020-01-29 02:24:52 +00:00
|
|
|
// Toggle on
|
|
|
|
self.enable_searching = true;
|
2020-02-02 04:49:44 +00:00
|
|
|
self.current_widget_selected = WidgetPosition::ProcessSearch;
|
2020-01-12 20:41:27 +00:00
|
|
|
}
|
|
|
|
_ => {}
|
2020-01-12 18:15:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_searching(&self) -> bool {
|
|
|
|
self.enable_searching
|
|
|
|
}
|
|
|
|
|
2020-01-12 20:41:27 +00:00
|
|
|
pub fn is_in_search_widget(&self) -> bool {
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
2020-01-12 20:41:27 +00:00
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn search_with_pid(&mut self) {
|
|
|
|
if !self.is_in_dialog() && self.is_searching() {
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
2020-01-12 20:41:27 +00:00
|
|
|
self.searching_pid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn search_with_name(&mut self) {
|
|
|
|
if !self.is_in_dialog() && self.is_searching() {
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
2020-01-12 20:41:27 +00:00
|
|
|
self.searching_pid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_searching_with_pid(&self) -> bool {
|
|
|
|
self.searching_pid
|
|
|
|
}
|
|
|
|
|
2020-01-12 23:45:11 +00:00
|
|
|
pub fn get_current_search_query(&self) -> &String {
|
2020-01-12 20:41:27 +00:00
|
|
|
&self.current_search_query
|
|
|
|
}
|
|
|
|
|
2020-01-16 03:57:00 +00:00
|
|
|
pub fn toggle_simple_search(&mut self) {
|
|
|
|
if !self.is_in_dialog() && self.is_searching() {
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
2020-01-16 03:57:00 +00:00
|
|
|
self.use_simple = !self.use_simple;
|
2020-01-20 01:57:05 +00:00
|
|
|
|
|
|
|
// Update to latest (when simple is on this is not updated)
|
|
|
|
if !self.use_simple {
|
|
|
|
self.current_regex = if self.current_search_query.is_empty() {
|
|
|
|
BASE_REGEX.clone()
|
|
|
|
} else {
|
|
|
|
regex::Regex::new(&(self.current_search_query))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force update to process display in GUI
|
2020-01-18 00:19:20 +00:00
|
|
|
self.update_process_gui = true;
|
2020-01-16 03:57:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-17 02:33:06 +00:00
|
|
|
pub fn get_cursor_position(&self) -> usize {
|
|
|
|
self.current_cursor_position
|
|
|
|
}
|
|
|
|
|
2020-01-02 04:39:47 +00:00
|
|
|
/// One of two functions allowed to run while in a dialog...
|
|
|
|
pub fn on_enter(&mut self) {
|
|
|
|
if self.show_dd {
|
|
|
|
// If within dd...
|
|
|
|
if self.dd_err.is_none() {
|
|
|
|
// Also ensure that we didn't just fail a dd...
|
|
|
|
let dd_result = self.kill_highlighted_process();
|
|
|
|
if let Err(dd_err) = dd_result {
|
|
|
|
// There was an issue... inform the user...
|
|
|
|
self.dd_err = Some(dd_err.to_string());
|
|
|
|
} else {
|
|
|
|
self.show_dd = false;
|
|
|
|
}
|
|
|
|
}
|
2019-10-10 02:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-12 20:41:27 +00:00
|
|
|
pub fn on_backspace(&mut self) {
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
2020-01-17 02:33:06 +00:00
|
|
|
if self.current_cursor_position > 0 {
|
|
|
|
self.current_cursor_position -= 1;
|
|
|
|
self.current_search_query
|
|
|
|
.remove(self.current_cursor_position);
|
|
|
|
|
2020-01-20 01:57:05 +00:00
|
|
|
if !self.use_simple {
|
|
|
|
self.current_regex = if self.current_search_query.is_empty() {
|
|
|
|
BASE_REGEX.clone()
|
|
|
|
} else {
|
|
|
|
regex::Regex::new(&(self.current_search_query))
|
|
|
|
};
|
|
|
|
}
|
2020-01-18 00:19:20 +00:00
|
|
|
self.update_process_gui = true;
|
2020-01-17 02:33:06 +00:00
|
|
|
}
|
2020-01-12 20:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-12 23:45:11 +00:00
|
|
|
pub fn get_current_regex_matcher(&self) -> &std::result::Result<regex::Regex, regex::Error> {
|
|
|
|
&self.current_regex
|
|
|
|
}
|
|
|
|
|
2020-01-17 02:33:06 +00:00
|
|
|
pub fn on_up_key(&mut self) {
|
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
2020-01-17 02:33:06 +00:00
|
|
|
} else {
|
|
|
|
self.decrement_position_count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn on_down_key(&mut self) {
|
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
2020-01-17 02:33:06 +00:00
|
|
|
} else {
|
|
|
|
self.increment_position_count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn on_left_key(&mut self) {
|
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
2020-01-17 02:33:06 +00:00
|
|
|
if self.current_cursor_position > 0 {
|
|
|
|
self.current_cursor_position -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn on_right_key(&mut self) {
|
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
2020-01-17 02:33:06 +00:00
|
|
|
if self.current_cursor_position < self.current_search_query.len() {
|
|
|
|
self.current_cursor_position += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 00:53:42 +00:00
|
|
|
pub fn skip_cursor_beginning(&mut self) {
|
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
2020-01-18 00:53:42 +00:00
|
|
|
self.current_cursor_position = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn skip_cursor_end(&mut self) {
|
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
2020-01-18 00:53:42 +00:00
|
|
|
self.current_cursor_position = self.current_search_query.len();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-02 04:39:47 +00:00
|
|
|
pub fn on_char_key(&mut self, caught_char: char) {
|
|
|
|
// Forbid any char key presses when showing a dialog box...
|
|
|
|
if !self.is_in_dialog() {
|
2019-12-16 07:21:44 +00:00
|
|
|
let current_key_press_inst = Instant::now();
|
2020-01-08 04:40:53 +00:00
|
|
|
if current_key_press_inst
|
|
|
|
.duration_since(self.last_key_press)
|
|
|
|
.as_millis() > constants::MAX_KEY_TIMEOUT_IN_MILLISECONDS
|
|
|
|
{
|
2019-12-16 07:21:44 +00:00
|
|
|
self.reset_multi_tap_keys();
|
|
|
|
}
|
|
|
|
self.last_key_press = current_key_press_inst;
|
|
|
|
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
2020-01-17 02:33:06 +00:00
|
|
|
self.current_search_query
|
|
|
|
.insert(self.current_cursor_position, caught_char);
|
|
|
|
self.current_cursor_position += 1;
|
2020-01-16 03:57:00 +00:00
|
|
|
|
2020-01-20 01:57:05 +00:00
|
|
|
if !self.use_simple {
|
|
|
|
self.current_regex = if self.current_search_query.is_empty() {
|
|
|
|
BASE_REGEX.clone()
|
|
|
|
} else {
|
|
|
|
regex::Regex::new(&(self.current_search_query))
|
|
|
|
};
|
|
|
|
}
|
2020-01-18 00:19:20 +00:00
|
|
|
self.update_process_gui = true;
|
2020-01-12 20:41:27 +00:00
|
|
|
} else {
|
|
|
|
match caught_char {
|
|
|
|
'/' => {
|
2020-01-29 02:24:52 +00:00
|
|
|
self.enable_searching();
|
2020-01-12 18:15:35 +00:00
|
|
|
}
|
2020-01-12 20:41:27 +00:00
|
|
|
'd' => {
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::Process = self.current_widget_selected {
|
2020-01-12 20:41:27 +00:00
|
|
|
if self.awaiting_second_char && self.second_char == 'd' {
|
|
|
|
self.awaiting_second_char = false;
|
|
|
|
self.second_char = ' ';
|
2020-02-02 04:49:44 +00:00
|
|
|
let current_process = Vec::new();
|
|
|
|
|
|
|
|
// TODO: FIX THIS SHITTTTTT
|
|
|
|
|
2020-01-12 20:41:27 +00:00
|
|
|
self.to_delete_process_list = Some(current_process);
|
|
|
|
self.show_dd = true;
|
|
|
|
self.reset_multi_tap_keys();
|
2020-01-09 03:36:36 +00:00
|
|
|
} else {
|
2020-01-12 20:41:27 +00:00
|
|
|
self.awaiting_second_char = true;
|
|
|
|
self.second_char = 'd';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'g' => {
|
|
|
|
if self.awaiting_second_char && self.second_char == 'g' {
|
|
|
|
self.awaiting_second_char = false;
|
|
|
|
self.second_char = ' ';
|
|
|
|
self.skip_to_first();
|
2020-01-01 23:39:59 +00:00
|
|
|
} else {
|
|
|
|
self.awaiting_second_char = true;
|
2020-01-12 20:41:27 +00:00
|
|
|
self.second_char = 'g';
|
2020-01-01 23:39:59 +00:00
|
|
|
}
|
2019-12-26 04:30:57 +00:00
|
|
|
}
|
2020-01-12 20:41:27 +00:00
|
|
|
'G' => self.skip_to_last(),
|
|
|
|
'k' => self.decrement_position_count(),
|
|
|
|
'j' => self.increment_position_count(),
|
|
|
|
'f' => {
|
|
|
|
self.is_frozen = !self.is_frozen;
|
2019-10-10 02:00:10 +00:00
|
|
|
}
|
2020-01-12 20:41:27 +00:00
|
|
|
'c' => {
|
|
|
|
match self.process_sorting_type {
|
|
|
|
processes::ProcessSorting::CPU => {
|
|
|
|
self.process_sorting_reverse = !self.process_sorting_reverse
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
self.process_sorting_type = processes::ProcessSorting::CPU;
|
|
|
|
self.process_sorting_reverse = true;
|
|
|
|
}
|
2019-10-10 02:00:10 +00:00
|
|
|
}
|
2020-01-18 00:19:20 +00:00
|
|
|
self.update_process_gui = true;
|
2020-01-12 20:41:27 +00:00
|
|
|
self.currently_selected_process_position = 0;
|
2019-09-10 22:22:34 +00:00
|
|
|
}
|
2020-01-12 20:41:27 +00:00
|
|
|
'm' => {
|
|
|
|
match self.process_sorting_type {
|
|
|
|
processes::ProcessSorting::MEM => {
|
|
|
|
self.process_sorting_reverse = !self.process_sorting_reverse
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
self.process_sorting_type = processes::ProcessSorting::MEM;
|
|
|
|
self.process_sorting_reverse = true;
|
|
|
|
}
|
2020-01-08 04:40:53 +00:00
|
|
|
}
|
2020-01-18 00:19:20 +00:00
|
|
|
self.update_process_gui = true;
|
2020-01-12 20:41:27 +00:00
|
|
|
self.currently_selected_process_position = 0;
|
|
|
|
}
|
|
|
|
'p' => {
|
|
|
|
// Disable if grouping
|
|
|
|
if !self.enable_grouping {
|
|
|
|
match self.process_sorting_type {
|
|
|
|
processes::ProcessSorting::PID => {
|
|
|
|
self.process_sorting_reverse = !self.process_sorting_reverse
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
self.process_sorting_type = processes::ProcessSorting::PID;
|
|
|
|
self.process_sorting_reverse = false;
|
|
|
|
}
|
|
|
|
}
|
2020-01-18 00:19:20 +00:00
|
|
|
self.update_process_gui = true;
|
2020-01-12 20:41:27 +00:00
|
|
|
self.currently_selected_process_position = 0;
|
2019-10-10 02:00:10 +00:00
|
|
|
}
|
2019-09-10 22:22:34 +00:00
|
|
|
}
|
2020-01-12 20:41:27 +00:00
|
|
|
'n' => {
|
2020-01-08 04:39:52 +00:00
|
|
|
match self.process_sorting_type {
|
2020-01-12 20:41:27 +00:00
|
|
|
processes::ProcessSorting::NAME => {
|
2020-01-08 04:40:53 +00:00
|
|
|
self.process_sorting_reverse = !self.process_sorting_reverse
|
|
|
|
}
|
2020-01-08 04:39:52 +00:00
|
|
|
_ => {
|
2020-01-12 20:41:27 +00:00
|
|
|
self.process_sorting_type = processes::ProcessSorting::NAME;
|
2020-01-08 04:39:52 +00:00
|
|
|
self.process_sorting_reverse = false;
|
|
|
|
}
|
2019-10-10 02:00:10 +00:00
|
|
|
}
|
2020-01-18 00:19:20 +00:00
|
|
|
self.update_process_gui = true;
|
2020-01-08 04:39:52 +00:00
|
|
|
self.currently_selected_process_position = 0;
|
2019-09-10 22:22:34 +00:00
|
|
|
}
|
2020-01-12 20:41:27 +00:00
|
|
|
'?' => {
|
|
|
|
self.show_help = true;
|
2019-09-10 22:22:34 +00:00
|
|
|
}
|
2020-01-12 20:41:27 +00:00
|
|
|
_ => {}
|
2019-09-10 22:22:34 +00:00
|
|
|
}
|
2020-01-12 20:41:27 +00:00
|
|
|
if self.awaiting_second_char && caught_char != self.second_char {
|
|
|
|
self.awaiting_second_char = false;
|
2019-10-10 02:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-17 01:45:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-02 04:39:47 +00:00
|
|
|
pub fn kill_highlighted_process(&mut self) -> Result<()> {
|
|
|
|
// Technically unnecessary but this is a good check...
|
2020-02-02 04:49:44 +00:00
|
|
|
if let WidgetPosition::Process = self.current_widget_selected {
|
2020-01-09 03:36:36 +00:00
|
|
|
if let Some(current_selected_processes) = &(self.to_delete_process_list) {
|
|
|
|
for current_selected_process in current_selected_processes {
|
|
|
|
process_killer::kill_process_given_pid(current_selected_process.pid)?;
|
|
|
|
}
|
2020-01-02 04:39:47 +00:00
|
|
|
}
|
2020-01-09 03:36:36 +00:00
|
|
|
self.to_delete_process_list = None;
|
2020-01-02 04:39:47 +00:00
|
|
|
}
|
2019-09-17 01:45:48 +00:00
|
|
|
Ok(())
|
2019-09-08 23:56:23 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 04:49:44 +00:00
|
|
|
pub fn get_current_highlighted_process_list(&self) -> Option<Vec<ConvertedProcessData>> {
|
2020-01-09 03:36:36 +00:00
|
|
|
self.to_delete_process_list.clone()
|
2020-01-02 04:39:47 +00:00
|
|
|
}
|
|
|
|
|
2019-09-17 02:39:57 +00:00
|
|
|
// For now, these are hard coded --- in the future, they shouldn't be!
|
|
|
|
//
|
|
|
|
// General idea for now:
|
|
|
|
// CPU -(down)> MEM
|
|
|
|
// MEM -(down)> Network, -(right)> TEMP
|
|
|
|
// TEMP -(down)> Disk, -(left)> MEM, -(up)> CPU
|
2020-01-12 20:41:27 +00:00
|
|
|
// Disk -(down)> Processes OR PROC_SEARCH, -(left)> MEM, -(up)> TEMP
|
2019-09-17 02:39:57 +00:00
|
|
|
// Network -(up)> MEM, -(right)> PROC
|
2020-01-12 20:41:27 +00:00
|
|
|
// PROC -(up)> Disk OR PROC_SEARCH if enabled, -(left)> Network
|
|
|
|
// PROC_SEARCH -(up)> Disk, -(down)> PROC, -(left)> Network
|
2020-01-17 02:33:06 +00:00
|
|
|
pub fn move_left(&mut self) {
|
2020-01-02 04:39:47 +00:00
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
self.current_widget_selected = match self.current_widget_selected {
|
|
|
|
WidgetPosition::Process => WidgetPosition::Network,
|
|
|
|
WidgetPosition::ProcessSearch => WidgetPosition::Network,
|
|
|
|
WidgetPosition::Disk => WidgetPosition::Mem,
|
|
|
|
WidgetPosition::Temp => WidgetPosition::Mem,
|
|
|
|
_ => self.current_widget_selected,
|
2020-01-02 04:39:47 +00:00
|
|
|
};
|
|
|
|
self.reset_multi_tap_keys();
|
|
|
|
}
|
2019-09-09 22:34:13 +00:00
|
|
|
}
|
2019-09-08 23:56:23 +00:00
|
|
|
|
2020-01-17 02:33:06 +00:00
|
|
|
pub fn move_right(&mut self) {
|
2020-01-02 04:39:47 +00:00
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
self.current_widget_selected = match self.current_widget_selected {
|
|
|
|
WidgetPosition::Mem => WidgetPosition::Temp,
|
|
|
|
WidgetPosition::Network => WidgetPosition::Process,
|
|
|
|
_ => self.current_widget_selected,
|
2020-01-02 04:39:47 +00:00
|
|
|
};
|
|
|
|
self.reset_multi_tap_keys();
|
|
|
|
}
|
2019-09-09 22:34:13 +00:00
|
|
|
}
|
|
|
|
|
2020-01-17 02:33:06 +00:00
|
|
|
pub fn move_up(&mut self) {
|
2020-01-02 04:39:47 +00:00
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
self.current_widget_selected = match self.current_widget_selected {
|
|
|
|
WidgetPosition::Mem => WidgetPosition::Cpu,
|
|
|
|
WidgetPosition::Network => WidgetPosition::Mem,
|
|
|
|
WidgetPosition::Process => {
|
2020-01-12 20:41:27 +00:00
|
|
|
if self.is_searching() {
|
2020-02-02 04:49:44 +00:00
|
|
|
WidgetPosition::ProcessSearch
|
2020-01-12 20:41:27 +00:00
|
|
|
} else {
|
2020-02-02 04:49:44 +00:00
|
|
|
WidgetPosition::Disk
|
2020-01-12 20:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-02 04:49:44 +00:00
|
|
|
WidgetPosition::ProcessSearch => WidgetPosition::Disk,
|
|
|
|
WidgetPosition::Temp => WidgetPosition::Cpu,
|
|
|
|
WidgetPosition::Disk => WidgetPosition::Temp,
|
|
|
|
_ => self.current_widget_selected,
|
2020-01-02 04:39:47 +00:00
|
|
|
};
|
|
|
|
self.reset_multi_tap_keys();
|
|
|
|
}
|
2019-09-09 22:34:13 +00:00
|
|
|
}
|
2019-09-08 23:56:23 +00:00
|
|
|
|
2020-01-17 02:33:06 +00:00
|
|
|
pub fn move_down(&mut self) {
|
2020-01-02 04:39:47 +00:00
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
self.current_widget_selected = match self.current_widget_selected {
|
|
|
|
WidgetPosition::Cpu => WidgetPosition::Mem,
|
|
|
|
WidgetPosition::Mem => WidgetPosition::Network,
|
|
|
|
WidgetPosition::Temp => WidgetPosition::Disk,
|
|
|
|
WidgetPosition::Disk => {
|
2020-01-12 20:41:27 +00:00
|
|
|
if self.is_searching() {
|
2020-02-02 04:49:44 +00:00
|
|
|
WidgetPosition::ProcessSearch
|
2020-01-12 20:41:27 +00:00
|
|
|
} else {
|
2020-02-02 04:49:44 +00:00
|
|
|
WidgetPosition::Process
|
2020-01-12 20:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-02 04:49:44 +00:00
|
|
|
WidgetPosition::ProcessSearch => WidgetPosition::Process,
|
|
|
|
_ => self.current_widget_selected,
|
2020-01-02 04:39:47 +00:00
|
|
|
};
|
|
|
|
self.reset_multi_tap_keys();
|
|
|
|
}
|
2019-12-26 04:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn skip_to_first(&mut self) {
|
2020-01-02 04:39:47 +00:00
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
match self.current_widget_selected {
|
|
|
|
WidgetPosition::Process => self.currently_selected_process_position = 0,
|
|
|
|
WidgetPosition::Temp => self.currently_selected_temperature_position = 0,
|
|
|
|
WidgetPosition::Disk => self.currently_selected_disk_position = 0,
|
|
|
|
WidgetPosition::Cpu => self.currently_selected_cpu_table_position = 0,
|
2020-01-02 04:39:47 +00:00
|
|
|
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
self.scroll_direction = ScrollDirection::UP;
|
|
|
|
self.reset_multi_tap_keys();
|
2019-12-26 04:30:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn skip_to_last(&mut self) {
|
2020-01-02 04:39:47 +00:00
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
match self.current_widget_selected {
|
|
|
|
WidgetPosition::Process => {
|
2020-01-08 04:40:53 +00:00
|
|
|
self.currently_selected_process_position =
|
|
|
|
self.data.list_of_processes.len() as i64 - 1
|
|
|
|
}
|
2020-02-02 04:49:44 +00:00
|
|
|
WidgetPosition::Temp => {
|
2020-01-08 04:40:53 +00:00
|
|
|
self.currently_selected_temperature_position =
|
2020-01-29 02:24:52 +00:00
|
|
|
self.data.temperature_sensors.len() as i64 - 1
|
2020-01-08 04:40:53 +00:00
|
|
|
}
|
2020-02-02 04:49:44 +00:00
|
|
|
WidgetPosition::Disk => {
|
2020-01-29 02:24:52 +00:00
|
|
|
self.currently_selected_disk_position = self.data.disks.len() as i64 - 1
|
2020-01-08 04:40:53 +00:00
|
|
|
}
|
2020-02-02 04:49:44 +00:00
|
|
|
WidgetPosition::Cpu => {
|
2020-01-27 01:14:14 +00:00
|
|
|
self.currently_selected_cpu_table_position =
|
|
|
|
self.canvas_data.cpu_data.len() as i64 - 1;
|
2020-01-02 04:39:47 +00:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
self.scroll_direction = ScrollDirection::DOWN;
|
|
|
|
self.reset_multi_tap_keys();
|
2019-12-26 04:30:57 +00:00
|
|
|
}
|
2019-09-08 23:56:23 +00:00
|
|
|
}
|
2019-09-15 18:16:18 +00:00
|
|
|
|
|
|
|
pub fn decrement_position_count(&mut self) {
|
2020-01-02 04:39:47 +00:00
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
match self.current_widget_selected {
|
|
|
|
WidgetPosition::Process => self.change_process_position(-1),
|
|
|
|
WidgetPosition::Temp => self.change_temp_position(-1),
|
|
|
|
WidgetPosition::Disk => self.change_disk_position(-1),
|
|
|
|
WidgetPosition::Cpu => self.change_cpu_table_position(-1), // TODO: Temporary, may change if we add scaling
|
2020-01-02 04:39:47 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
self.scroll_direction = ScrollDirection::UP;
|
|
|
|
self.reset_multi_tap_keys();
|
2019-09-15 18:16:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn increment_position_count(&mut self) {
|
2020-01-02 04:39:47 +00:00
|
|
|
if !self.is_in_dialog() {
|
2020-02-02 04:49:44 +00:00
|
|
|
match self.current_widget_selected {
|
|
|
|
WidgetPosition::Process => self.change_process_position(1),
|
|
|
|
WidgetPosition::Temp => self.change_temp_position(1),
|
|
|
|
WidgetPosition::Disk => self.change_disk_position(1),
|
|
|
|
WidgetPosition::Cpu => self.change_cpu_table_position(1), // TODO: Temporary, may change if we add scaling
|
2020-01-02 04:39:47 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
self.scroll_direction = ScrollDirection::DOWN;
|
|
|
|
self.reset_multi_tap_keys();
|
2019-09-15 18:16:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-01 22:55:15 +00:00
|
|
|
fn change_cpu_table_position(&mut self, num_to_change_by: i64) {
|
2020-01-27 01:14:14 +00:00
|
|
|
if self.currently_selected_cpu_table_position + num_to_change_by >= 0
|
|
|
|
&& self.currently_selected_cpu_table_position + num_to_change_by
|
|
|
|
< self.canvas_data.cpu_data.len() as i64
|
|
|
|
{
|
|
|
|
self.currently_selected_cpu_table_position += num_to_change_by;
|
2020-01-01 22:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 05:57:04 +00:00
|
|
|
fn change_process_position(&mut self, num_to_change_by: i64) {
|
2019-09-16 20:18:42 +00:00
|
|
|
if self.currently_selected_process_position + num_to_change_by >= 0
|
2020-01-08 04:40:53 +00:00
|
|
|
&& self.currently_selected_process_position + num_to_change_by
|
|
|
|
< self.data.list_of_processes.len() as i64
|
2019-09-16 20:18:42 +00:00
|
|
|
{
|
|
|
|
self.currently_selected_process_position += num_to_change_by;
|
2019-09-15 18:16:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 05:57:04 +00:00
|
|
|
fn change_temp_position(&mut self, num_to_change_by: i64) {
|
2019-09-25 20:43:13 +00:00
|
|
|
if self.currently_selected_temperature_position + num_to_change_by >= 0
|
2020-01-08 04:40:53 +00:00
|
|
|
&& self.currently_selected_temperature_position + num_to_change_by
|
2020-01-29 02:24:52 +00:00
|
|
|
< self.data.temperature_sensors.len() as i64
|
2019-09-25 20:43:13 +00:00
|
|
|
{
|
2019-09-16 20:18:42 +00:00
|
|
|
self.currently_selected_temperature_position += num_to_change_by;
|
2019-09-15 18:16:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 05:57:04 +00:00
|
|
|
fn change_disk_position(&mut self, num_to_change_by: i64) {
|
2019-09-25 20:43:13 +00:00
|
|
|
if self.currently_selected_disk_position + num_to_change_by >= 0
|
2020-01-08 04:40:53 +00:00
|
|
|
&& self.currently_selected_disk_position + num_to_change_by
|
2020-01-29 02:24:52 +00:00
|
|
|
< self.data.disks.len() as i64
|
2019-09-25 20:43:13 +00:00
|
|
|
{
|
2019-09-16 20:18:42 +00:00
|
|
|
self.currently_selected_disk_position += num_to_change_by;
|
2019-09-15 18:16:18 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-08 23:56:23 +00:00
|
|
|
}
|