refactor: clean up some states and code

This commit is contained in:
ClementTsang 2021-08-13 22:23:09 -04:00
parent 5749c32bd5
commit fceae8d442
13 changed files with 30 additions and 33 deletions

View File

@ -4,7 +4,7 @@ pub mod filter;
pub mod layout_manager;
mod process_killer;
pub mod query;
pub mod widget_states;
pub mod widgets;
use std::{
cmp::{max, min},
@ -21,10 +21,11 @@ use data_farmer::*;
use data_harvester::{processes, temperature};
pub use filter::*;
use layout_manager::*;
pub use widget_states::*;
pub use widgets::*;
use crate::{
canvas, constants,
canvas,
constants::{self, MAX_SIGNAL},
units::data_units::DataUnit,
utils::error::{BottomError, Result},
Pid,
@ -128,13 +129,6 @@ pub struct AppState {
pub filters: DataFilters,
}
#[cfg(target_os = "windows")]
const MAX_SIGNAL: usize = 1;
#[cfg(target_os = "linux")]
const MAX_SIGNAL: usize = 64;
#[cfg(target_os = "macos")]
const MAX_SIGNAL: usize = 31;
impl AppState {
pub fn reset(&mut self) {
// Reset multi

View File

@ -1 +0,0 @@
//! States for a graph widget.

View File

@ -1 +0,0 @@
//! States for a table widget.

View File

@ -4,26 +4,26 @@ use tui::widgets::TableState;
use crate::{app::layout_manager::BottomWidgetType, constants};
pub mod process_state;
pub use process_state::*;
pub mod process;
pub use process::*;
pub mod net_state;
pub use net_state::*;
pub mod net;
pub use net::*;
pub mod mem_state;
pub use mem_state::*;
pub mod mem;
pub use mem::*;
pub mod cpu_state;
pub use cpu_state::*;
pub mod cpu;
pub use cpu::*;
pub mod disk_state;
pub use disk_state::*;
pub mod disk;
pub use disk::*;
pub mod battery_state;
pub use battery_state::*;
pub mod battery;
pub use self::battery::*;
pub mod temp_state;
pub use temp_state::*;
pub mod temp;
pub use temp::*;
#[derive(Debug)]
pub enum ScrollDirection {

View File

@ -22,6 +22,14 @@ pub const MAX_KEY_TIMEOUT_IN_MILLISECONDS: u64 = 1000;
pub const TABLE_GAP_HEIGHT_LIMIT: u16 = 7;
pub const TIME_LABEL_HEIGHT_LIMIT: u16 = 7;
// For kill signals
#[cfg(target_os = "windows")]
pub const MAX_SIGNAL: usize = 1;
#[cfg(target_os = "linux")]
pub const MAX_SIGNAL: usize = 64;
#[cfg(target_os = "macos")]
pub const MAX_SIGNAL: usize = 31;
// Side borders
pub static SIDE_BORDERS: Lazy<tui::widgets::Borders> =
Lazy::new(|| tui::widgets::Borders::from_bits_truncate(20));

View File

@ -82,13 +82,10 @@ pub enum EventResult {
pub fn handle_mouse_event(event: MouseEvent, app: &mut AppState) -> EventResult {
match event.kind {
MouseEventKind::Down(button) => match button {
MouseButton::Left => {
app.on_left_mouse_up(event.column, event.row);
EventResult::Redraw
}
_ => EventResult::Continue,
},
MouseEventKind::Down(MouseButton::Left) => {
app.on_left_mouse_up(event.column, event.row);
EventResult::Redraw
}
MouseEventKind::ScrollUp => {
app.handle_scroll_up();
EventResult::Redraw