-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Remove a looot of redundant config code refactor: Move some state content over refactor: rename folder refactor: More renaming and pruning of old unused code.
- Loading branch information
1 parent
0c3f9da
commit a95a967
Showing
33 changed files
with
462 additions
and
734 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#[derive(Debug, Clone)] | ||
pub struct Filter { | ||
pub is_list_ignored: bool, | ||
pub list: Vec<regex::Regex>, | ||
} | ||
|
||
/// For filtering out information | ||
#[derive(Debug, Clone)] | ||
pub struct DataFilters { | ||
pub disk_filter: Option<Filter>, | ||
pub mount_filter: Option<Filter>, | ||
pub temp_filter: Option<Filter>, | ||
pub net_filter: Option<Filter>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::collections::HashMap; | ||
|
||
#[derive(Default)] | ||
pub struct BatteryWidgetState { | ||
pub currently_selected_battery_index: usize, | ||
pub tab_click_locs: Option<Vec<((u16, u16), (u16, u16))>>, | ||
} | ||
|
||
pub struct BatteryState { | ||
pub widget_states: HashMap<u64, BatteryWidgetState>, | ||
} | ||
|
||
impl BatteryState { | ||
pub fn init(widget_states: HashMap<u64, BatteryWidgetState>) -> Self { | ||
BatteryState { widget_states } | ||
} | ||
|
||
pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut BatteryWidgetState> { | ||
self.widget_states.get_mut(&widget_id) | ||
} | ||
|
||
pub fn get_widget_state(&self, widget_id: u64) -> Option<&BatteryWidgetState> { | ||
self.widget_states.get(&widget_id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::{collections::HashMap, time::Instant}; | ||
|
||
use super::{AppScrollWidgetState, CanvasTableWidthState}; | ||
|
||
pub struct CpuWidgetState { | ||
pub current_display_time: u64, | ||
pub is_legend_hidden: bool, | ||
pub autohide_timer: Option<Instant>, | ||
pub scroll_state: AppScrollWidgetState, | ||
pub is_multi_graph_mode: bool, | ||
pub table_width_state: CanvasTableWidthState, | ||
} | ||
|
||
impl CpuWidgetState { | ||
pub fn init(current_display_time: u64, autohide_timer: Option<Instant>) -> Self { | ||
CpuWidgetState { | ||
current_display_time, | ||
is_legend_hidden: false, | ||
autohide_timer, | ||
scroll_state: AppScrollWidgetState::default(), | ||
is_multi_graph_mode: false, | ||
table_width_state: CanvasTableWidthState::default(), | ||
} | ||
} | ||
} | ||
|
||
pub struct CpuState { | ||
pub force_update: Option<u64>, | ||
pub widget_states: HashMap<u64, CpuWidgetState>, | ||
} | ||
|
||
impl CpuState { | ||
pub fn init(widget_states: HashMap<u64, CpuWidgetState>) -> Self { | ||
CpuState { | ||
force_update: None, | ||
widget_states, | ||
} | ||
} | ||
|
||
pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut CpuWidgetState> { | ||
self.widget_states.get_mut(&widget_id) | ||
} | ||
|
||
pub fn get_widget_state(&self, widget_id: u64) -> Option<&CpuWidgetState> { | ||
self.widget_states.get(&widget_id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::collections::HashMap; | ||
|
||
use super::{AppScrollWidgetState, CanvasTableWidthState}; | ||
|
||
pub struct DiskWidgetState { | ||
pub scroll_state: AppScrollWidgetState, | ||
pub table_width_state: CanvasTableWidthState, | ||
} | ||
|
||
impl DiskWidgetState { | ||
pub fn init() -> Self { | ||
DiskWidgetState { | ||
scroll_state: AppScrollWidgetState::default(), | ||
table_width_state: CanvasTableWidthState::default(), | ||
} | ||
} | ||
} | ||
|
||
pub struct DiskState { | ||
pub widget_states: HashMap<u64, DiskWidgetState>, | ||
} | ||
|
||
impl DiskState { | ||
pub fn init(widget_states: HashMap<u64, DiskWidgetState>) -> Self { | ||
DiskState { widget_states } | ||
} | ||
|
||
pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut DiskWidgetState> { | ||
self.widget_states.get_mut(&widget_id) | ||
} | ||
|
||
pub fn get_widget_state(&self, widget_id: u64) -> Option<&DiskWidgetState> { | ||
self.widget_states.get(&widget_id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//! States for a graph widget. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::{collections::HashMap, time::Instant}; | ||
|
||
pub struct MemWidgetState { | ||
pub current_display_time: u64, | ||
pub autohide_timer: Option<Instant>, | ||
} | ||
|
||
impl MemWidgetState { | ||
pub fn init(current_display_time: u64, autohide_timer: Option<Instant>) -> Self { | ||
MemWidgetState { | ||
current_display_time, | ||
autohide_timer, | ||
} | ||
} | ||
} | ||
|
||
pub struct MemState { | ||
pub force_update: Option<u64>, | ||
pub widget_states: HashMap<u64, MemWidgetState>, | ||
} | ||
|
||
impl MemState { | ||
pub fn init(widget_states: HashMap<u64, MemWidgetState>) -> Self { | ||
MemState { | ||
force_update: None, | ||
widget_states, | ||
} | ||
} | ||
|
||
pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut MemWidgetState> { | ||
self.widget_states.get_mut(&widget_id) | ||
} | ||
|
||
pub fn get_widget_state(&self, widget_id: u64) -> Option<&MemWidgetState> { | ||
self.widget_states.get(&widget_id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
use std::time::Instant; | ||
|
||
use tui::widgets::TableState; | ||
|
||
use crate::{app::layout_manager::BottomWidgetType, constants}; | ||
|
||
pub mod process_state; | ||
pub use process_state::*; | ||
|
||
pub mod net_state; | ||
pub use net_state::*; | ||
|
||
pub mod mem_state; | ||
pub use mem_state::*; | ||
|
||
pub mod cpu_state; | ||
pub use cpu_state::*; | ||
|
||
pub mod disk_state; | ||
pub use disk_state::*; | ||
|
||
pub mod battery_state; | ||
pub use battery_state::*; | ||
|
||
pub mod temp_state; | ||
pub use temp_state::*; | ||
|
||
#[derive(Debug)] | ||
pub enum ScrollDirection { | ||
// UP means scrolling up --- this usually DECREMENTS | ||
Up, | ||
// DOWN means scrolling down --- this usually INCREMENTS | ||
Down, | ||
} | ||
|
||
impl Default for ScrollDirection { | ||
fn default() -> Self { | ||
ScrollDirection::Down | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum CursorDirection { | ||
Left, | ||
Right, | ||
} | ||
|
||
/// AppScrollWidgetState deals with fields for a scrollable app's current state. | ||
#[derive(Default)] | ||
pub struct AppScrollWidgetState { | ||
pub current_scroll_position: usize, | ||
pub previous_scroll_position: usize, | ||
pub scroll_direction: ScrollDirection, | ||
pub table_state: TableState, | ||
} | ||
|
||
#[derive(PartialEq)] | ||
pub enum KillSignal { | ||
Cancel, | ||
Kill(usize), | ||
} | ||
|
||
impl Default for KillSignal { | ||
#[cfg(target_family = "unix")] | ||
fn default() -> Self { | ||
KillSignal::Kill(15) | ||
} | ||
#[cfg(target_os = "windows")] | ||
fn default() -> Self { | ||
KillSignal::Kill(1) | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct AppDeleteDialogState { | ||
pub is_showing_dd: bool, | ||
pub selected_signal: KillSignal, | ||
/// tl x, tl y, br x, br y, index/signal | ||
pub button_positions: Vec<(u16, u16, u16, u16, usize)>, | ||
pub keyboard_signal_select: usize, | ||
pub last_number_press: Option<Instant>, | ||
pub scroll_pos: usize, | ||
} | ||
|
||
pub struct AppHelpDialogState { | ||
pub is_showing_help: bool, | ||
pub scroll_state: ParagraphScrollState, | ||
pub index_shortcuts: Vec<u16>, | ||
} | ||
|
||
impl Default for AppHelpDialogState { | ||
fn default() -> Self { | ||
AppHelpDialogState { | ||
is_showing_help: false, | ||
scroll_state: ParagraphScrollState::default(), | ||
index_shortcuts: vec![0; constants::HELP_TEXT.len()], | ||
} | ||
} | ||
} | ||
|
||
/// Meant for canvas operations involving table column widths. | ||
#[derive(Default)] | ||
pub struct CanvasTableWidthState { | ||
pub desired_column_widths: Vec<u16>, | ||
pub calculated_column_widths: Vec<u16>, | ||
} | ||
|
||
pub struct BasicTableWidgetState { | ||
// Since this is intended (currently) to only be used for ONE widget, that's | ||
// how it's going to be written. If we want to allow for multiple of these, | ||
// then we can expand outwards with a normal BasicTableState and a hashmap | ||
pub currently_displayed_widget_type: BottomWidgetType, | ||
pub currently_displayed_widget_id: u64, | ||
pub widget_id: i64, | ||
pub left_tlc: Option<(u16, u16)>, | ||
pub left_brc: Option<(u16, u16)>, | ||
pub right_tlc: Option<(u16, u16)>, | ||
pub right_brc: Option<(u16, u16)>, | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct ParagraphScrollState { | ||
pub current_scroll_index: u16, | ||
pub max_scroll_index: u16, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::{collections::HashMap, time::Instant}; | ||
|
||
pub struct NetWidgetState { | ||
pub current_display_time: u64, | ||
pub autohide_timer: Option<Instant>, | ||
// pub draw_max_range_cache: f64, | ||
// pub draw_labels_cache: Vec<String>, | ||
// pub draw_time_start_cache: f64, | ||
// TODO: Re-enable these when we move net details state-side! | ||
// pub unit_type: DataUnitTypes, | ||
// pub scale_type: AxisScaling, | ||
} | ||
|
||
impl NetWidgetState { | ||
pub fn init( | ||
current_display_time: u64, | ||
autohide_timer: Option<Instant>, | ||
// unit_type: DataUnitTypes, | ||
// scale_type: AxisScaling, | ||
) -> Self { | ||
NetWidgetState { | ||
current_display_time, | ||
autohide_timer, | ||
// draw_max_range_cache: 0.0, | ||
// draw_labels_cache: vec![], | ||
// draw_time_start_cache: 0.0, | ||
// unit_type, | ||
// scale_type, | ||
} | ||
} | ||
} | ||
pub struct NetState { | ||
pub force_update: Option<u64>, | ||
pub widget_states: HashMap<u64, NetWidgetState>, | ||
} | ||
|
||
impl NetState { | ||
pub fn init(widget_states: HashMap<u64, NetWidgetState>) -> Self { | ||
NetState { | ||
force_update: None, | ||
widget_states, | ||
} | ||
} | ||
|
||
pub fn get_mut_widget_state(&mut self, widget_id: u64) -> Option<&mut NetWidgetState> { | ||
self.widget_states.get_mut(&widget_id) | ||
} | ||
|
||
pub fn get_widget_state(&self, widget_id: u64) -> Option<&NetWidgetState> { | ||
self.widget_states.get(&widget_id) | ||
} | ||
} |
Oops, something went wrong.