Some basic setup for adding graph filtering; added delete key to allow dd-ing, some refactoring.
This commit is contained in:
parent
882e5d9289
commit
74df90010d
188
src/app.rs
188
src/app.rs
|
@ -60,7 +60,7 @@ impl Default for AppScrollState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// AppSearchState deals with generic searching (mainly for graph filtering)
|
/// AppSearchState deals with generic searching (I might do this in the future).
|
||||||
pub struct AppSearchState {
|
pub struct AppSearchState {
|
||||||
is_enabled: bool,
|
is_enabled: bool,
|
||||||
current_search_query: String,
|
current_search_query: String,
|
||||||
|
@ -157,6 +157,61 @@ pub struct AppConfigFields {
|
||||||
pub use_current_cpu_total: bool,
|
pub use_current_cpu_total: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Network specific
|
||||||
|
pub struct NetworkState {
|
||||||
|
pub is_showing_tray: bool,
|
||||||
|
pub is_showing_rx: bool,
|
||||||
|
pub is_showing_tx: bool,
|
||||||
|
pub zoom_level: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for NetworkState {
|
||||||
|
fn default() -> Self {
|
||||||
|
NetworkState {
|
||||||
|
is_showing_tray: false,
|
||||||
|
is_showing_rx: true,
|
||||||
|
is_showing_tx: true,
|
||||||
|
zoom_level: 100.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// CPU specific
|
||||||
|
pub struct CpuState {
|
||||||
|
pub is_showing_tray: bool,
|
||||||
|
pub zoom_level: f64,
|
||||||
|
pub core_show_vec: Vec<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for CpuState {
|
||||||
|
fn default() -> Self {
|
||||||
|
CpuState {
|
||||||
|
is_showing_tray: false,
|
||||||
|
zoom_level: 100.0,
|
||||||
|
core_show_vec: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Memory specific
|
||||||
|
pub struct MemState {
|
||||||
|
pub is_showing_tray: bool,
|
||||||
|
pub is_showing_ram: bool,
|
||||||
|
pub is_showing_swap: bool,
|
||||||
|
pub zoom_level: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for MemState {
|
||||||
|
fn default() -> Self {
|
||||||
|
MemState {
|
||||||
|
is_showing_tray: false,
|
||||||
|
is_showing_ram: true,
|
||||||
|
is_showing_swap: true,
|
||||||
|
zoom_level: 100.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub process_sorting_type: processes::ProcessSorting,
|
pub process_sorting_type: processes::ProcessSorting,
|
||||||
pub process_sorting_reverse: bool,
|
pub process_sorting_reverse: bool,
|
||||||
|
@ -178,6 +233,9 @@ pub struct App {
|
||||||
pub help_dialog_state: AppHelpDialogState,
|
pub help_dialog_state: AppHelpDialogState,
|
||||||
pub app_config_fields: AppConfigFields,
|
pub app_config_fields: AppConfigFields,
|
||||||
pub is_expanded: bool,
|
pub is_expanded: bool,
|
||||||
|
pub cpu_state: CpuState,
|
||||||
|
pub mem_state: MemState,
|
||||||
|
pub net_state: NetworkState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
@ -214,6 +272,9 @@ impl App {
|
||||||
use_current_cpu_total,
|
use_current_cpu_total,
|
||||||
},
|
},
|
||||||
is_expanded: false,
|
is_expanded: false,
|
||||||
|
cpu_state: CpuState::default(),
|
||||||
|
mem_state: MemState::default(),
|
||||||
|
net_state: NetworkState::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,10 +301,26 @@ impl App {
|
||||||
self.delete_dialog_state.is_on_yes = false;
|
self.delete_dialog_state.is_on_yes = false;
|
||||||
self.to_delete_process_list = None;
|
self.to_delete_process_list = None;
|
||||||
self.dd_err = None;
|
self.dd_err = None;
|
||||||
} else if self.process_search_state.search_state.is_enabled {
|
} else if !self.is_expanded {
|
||||||
|
match self.current_widget_selected {
|
||||||
|
WidgetPosition::Process | WidgetPosition::ProcessSearch => {
|
||||||
|
if self.process_search_state.search_state.is_enabled {
|
||||||
self.current_widget_selected = WidgetPosition::Process;
|
self.current_widget_selected = WidgetPosition::Process;
|
||||||
self.process_search_state.search_state.is_enabled = false;
|
self.process_search_state.search_state.is_enabled = false;
|
||||||
} else if self.is_expanded {
|
}
|
||||||
|
}
|
||||||
|
WidgetPosition::Cpu => {
|
||||||
|
self.cpu_state.is_showing_tray = false;
|
||||||
|
}
|
||||||
|
WidgetPosition::Mem => {
|
||||||
|
self.mem_state.is_showing_tray = false;
|
||||||
|
}
|
||||||
|
WidgetPosition::Network => {
|
||||||
|
self.net_state.is_showing_tray = false;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
self.is_expanded = false;
|
self.is_expanded = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,7 +363,7 @@ impl App {
|
||||||
self.enable_grouping
|
self.enable_grouping
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable_searching(&mut self) {
|
pub fn on_slash(&mut self) {
|
||||||
if !self.is_in_dialog() {
|
if !self.is_in_dialog() {
|
||||||
match self.current_widget_selected {
|
match self.current_widget_selected {
|
||||||
WidgetPosition::Process | WidgetPosition::ProcessSearch => {
|
WidgetPosition::Process | WidgetPosition::ProcessSearch => {
|
||||||
|
@ -294,6 +371,15 @@ impl App {
|
||||||
self.process_search_state.search_state.is_enabled = true;
|
self.process_search_state.search_state.is_enabled = true;
|
||||||
self.current_widget_selected = WidgetPosition::ProcessSearch;
|
self.current_widget_selected = WidgetPosition::ProcessSearch;
|
||||||
}
|
}
|
||||||
|
WidgetPosition::Cpu => {
|
||||||
|
self.cpu_state.is_showing_tray = true;
|
||||||
|
}
|
||||||
|
WidgetPosition::Mem => {
|
||||||
|
self.mem_state.is_showing_tray = true;
|
||||||
|
}
|
||||||
|
WidgetPosition::Network => {
|
||||||
|
self.net_state.is_showing_tray = true;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -414,8 +500,11 @@ impl App {
|
||||||
self.delete_dialog_state.is_showing_dd = false;
|
self.delete_dialog_state.is_showing_dd = false;
|
||||||
}
|
}
|
||||||
} else if !self.is_in_dialog() {
|
} else if !self.is_in_dialog() {
|
||||||
// Pop-out mode.
|
// Pop-out mode. We ignore if in process search.
|
||||||
self.is_expanded = true;
|
match self.current_widget_selected {
|
||||||
|
WidgetPosition::ProcessSearch => {}
|
||||||
|
_ => self.is_expanded = true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,6 +622,47 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn start_dd(&mut self) {
|
||||||
|
if self
|
||||||
|
.app_scroll_positions
|
||||||
|
.process_scroll_state
|
||||||
|
.current_scroll_position
|
||||||
|
< self.canvas_data.finalized_process_data.len() as u64
|
||||||
|
{
|
||||||
|
let current_process = if self.is_grouped() {
|
||||||
|
let group_pids = &self.canvas_data.finalized_process_data[self
|
||||||
|
.app_scroll_positions
|
||||||
|
.process_scroll_state
|
||||||
|
.current_scroll_position
|
||||||
|
as usize]
|
||||||
|
.group_pids;
|
||||||
|
|
||||||
|
let mut ret = ("".to_string(), group_pids.clone());
|
||||||
|
|
||||||
|
for pid in group_pids {
|
||||||
|
if let Some(process) = self.canvas_data.process_data.get(&pid) {
|
||||||
|
ret.0 = process.name.clone();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret
|
||||||
|
} else {
|
||||||
|
let process = self.canvas_data.finalized_process_data[self
|
||||||
|
.app_scroll_positions
|
||||||
|
.process_scroll_state
|
||||||
|
.current_scroll_position
|
||||||
|
as usize]
|
||||||
|
.clone();
|
||||||
|
(process.name.clone(), vec![process.pid])
|
||||||
|
};
|
||||||
|
|
||||||
|
self.to_delete_process_list = Some(current_process);
|
||||||
|
self.delete_dialog_state.is_showing_dd = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.reset_multi_tap_keys();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn on_char_key(&mut self, caught_char: char) {
|
pub fn on_char_key(&mut self, caught_char: char) {
|
||||||
// Forbid any char key presses when showing a dialog box...
|
// Forbid any char key presses when showing a dialog box...
|
||||||
if !self.is_in_dialog() {
|
if !self.is_in_dialog() {
|
||||||
|
@ -565,7 +695,7 @@ impl App {
|
||||||
} else {
|
} else {
|
||||||
match caught_char {
|
match caught_char {
|
||||||
'/' => {
|
'/' => {
|
||||||
self.enable_searching();
|
self.on_slash();
|
||||||
}
|
}
|
||||||
'd' => {
|
'd' => {
|
||||||
if let WidgetPosition::Process = self.current_widget_selected {
|
if let WidgetPosition::Process = self.current_widget_selected {
|
||||||
|
@ -576,49 +706,7 @@ impl App {
|
||||||
self.awaiting_second_char = false;
|
self.awaiting_second_char = false;
|
||||||
self.second_char = None;
|
self.second_char = None;
|
||||||
|
|
||||||
if self
|
self.start_dd();
|
||||||
.app_scroll_positions
|
|
||||||
.process_scroll_state
|
|
||||||
.current_scroll_position < self
|
|
||||||
.canvas_data
|
|
||||||
.finalized_process_data
|
|
||||||
.len() as u64
|
|
||||||
{
|
|
||||||
let current_process = if self.is_grouped() {
|
|
||||||
let group_pids = &self
|
|
||||||
.canvas_data
|
|
||||||
.finalized_process_data[self
|
|
||||||
.app_scroll_positions
|
|
||||||
.process_scroll_state
|
|
||||||
.current_scroll_position as usize]
|
|
||||||
.group_pids;
|
|
||||||
|
|
||||||
let mut ret = ("".to_string(), group_pids.clone());
|
|
||||||
|
|
||||||
for pid in group_pids {
|
|
||||||
if let Some(process) =
|
|
||||||
self.canvas_data.process_data.get(&pid)
|
|
||||||
{
|
|
||||||
ret.0 = process.name.clone();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret
|
|
||||||
} else {
|
|
||||||
let process = self.canvas_data.finalized_process_data
|
|
||||||
[self
|
|
||||||
.app_scroll_positions
|
|
||||||
.process_scroll_state
|
|
||||||
.current_scroll_position as usize]
|
|
||||||
.clone();
|
|
||||||
(process.name.clone(), vec![process.pid])
|
|
||||||
};
|
|
||||||
|
|
||||||
self.to_delete_process_list = Some(current_process);
|
|
||||||
self.delete_dialog_state.is_showing_dd = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.reset_multi_tap_keys();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -295,8 +295,6 @@ fn handle_key_event_or_break(
|
||||||
event: KeyEvent, app: &mut app::App, rtx: &std::sync::mpsc::Sender<ResetEvent>,
|
event: KeyEvent, app: &mut app::App, rtx: &std::sync::mpsc::Sender<ResetEvent>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if event.modifiers.is_empty() {
|
if event.modifiers.is_empty() {
|
||||||
// If only a code, and no modifiers, don't bother...
|
|
||||||
|
|
||||||
// Required catch for searching - otherwise you couldn't search with q.
|
// Required catch for searching - otherwise you couldn't search with q.
|
||||||
if event.code == KeyCode::Char('q') && !app.is_in_search_widget() {
|
if event.code == KeyCode::Char('q') && !app.is_in_search_widget() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -314,6 +312,7 @@ fn handle_key_event_or_break(
|
||||||
KeyCode::Enter => app.on_enter(),
|
KeyCode::Enter => app.on_enter(),
|
||||||
KeyCode::Tab => app.on_tab(),
|
KeyCode::Tab => app.on_tab(),
|
||||||
KeyCode::Backspace => app.on_backspace(),
|
KeyCode::Backspace => app.on_backspace(),
|
||||||
|
KeyCode::Delete => app.start_dd(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -324,7 +323,7 @@ fn handle_key_event_or_break(
|
||||||
}
|
}
|
||||||
|
|
||||||
match event.code {
|
match event.code {
|
||||||
KeyCode::Char('f') => app.enable_searching(),
|
KeyCode::Char('f') => app.on_slash(),
|
||||||
KeyCode::Left => app.move_widget_selection_left(),
|
KeyCode::Left => app.move_widget_selection_left(),
|
||||||
KeyCode::Right => app.move_widget_selection_right(),
|
KeyCode::Right => app.move_widget_selection_right(),
|
||||||
KeyCode::Up => app.move_widget_selection_up(),
|
KeyCode::Up => app.move_widget_selection_up(),
|
||||||
|
|
Loading…
Reference in New Issue