summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorClementTsang <cjhtsang@uwaterloo.ca>2021-08-29 19:33:47 -0400
committerClementTsang <cjhtsang@uwaterloo.ca>2021-08-29 19:43:27 -0400
commit48c572dbafb443d505fc73fa0d598db3c727593f (patch)
tree01bc5c2cee29e48a5007b1356458484e5e2072cb /src/app
parent1ec203caa23e2ff4ca3f4cd488d80ee32ee231e7 (diff)
refactor: change up event handling logistics
Slightly move around the ideas of EventResult, ReturnSignalResult, and how they all work. The gist of it is that we now have widgets returning EventResults (and renamed to WidgetEventResult), and the main app event handler returns ReturnSignalResult (now named EventResult). Also add a new signal to handle re-updating data inputs! This is needed for the process, and any sortable/configurable widget.
Diffstat (limited to 'src/app')
-rw-r--r--src/app/data_farmer.rs12
-rw-r--r--src/app/data_harvester.rs17
-rw-r--r--src/app/data_harvester/processes.rs7
-rw-r--r--src/app/data_harvester/processes/linux.rs12
-rw-r--r--src/app/data_harvester/processes/macos.rs10
-rw-r--r--src/app/event.rs20
-rw-r--r--src/app/widgets.rs10
-rw-r--r--src/app/widgets/base/scrollable.rs48
-rw-r--r--src/app/widgets/base/sort_text_table.rs33
-rw-r--r--src/app/widgets/base/text_input.rs48
-rw-r--r--src/app/widgets/base/text_table.rs14
-rw-r--r--src/app/widgets/base/time_graph.rs38
-rw-r--r--src/app/widgets/cpu.rs17
-rw-r--r--src/app/widgets/disk.rs6
-rw-r--r--src/app/widgets/mem.rs6
-rw-r--r--src/app/widgets/net.rs8
-rw-r--r--src/app/widgets/process.rs251
-rw-r--r--src/app/widgets/temp.rs6
18 files changed, 321 insertions, 242 deletions
diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs
index f2d4c957..ccf2688e 100644
--- a/src/app/data_farmer.rs
+++ b/src/app/data_farmer.rs
@@ -14,7 +14,7 @@
/// more points as this is used!
use once_cell::sync::Lazy;
-use std::{cell::RefCell, collections::HashMap, time::Instant, vec::Vec};
+use std::{collections::HashMap, time::Instant, vec::Vec};
use crate::{
data_harvester::{batteries, cpu, disks, memory, network, processes, temperature, Data},
@@ -23,8 +23,6 @@ use crate::{
};
use regex::Regex;
-use super::data_harvester::processes::UserTable;
-
pub type TimeOffset = f64;
pub type Value = f64;
@@ -65,8 +63,6 @@ pub struct DataCollection {
pub io_labels: Vec<(String, String)>,
pub temp_harvest: Vec<temperature::TempHarvest>,
pub battery_harvest: Vec<batteries::BatteryHarvest>,
- #[cfg(target_family = "unix")]
- pub user_table: RefCell<UserTable>,
}
impl Default for DataCollection {
@@ -88,8 +84,6 @@ impl Default for DataCollection {
io_labels: Vec::default(),
temp_harvest: Vec::default(),
battery_harvest: Vec::default(),
- #[cfg(target_family = "unix")]
- user_table: RefCell::new(UserTable::default()),
}
}
}
@@ -107,10 +101,6 @@ impl DataCollection {
self.io_labels_and_prev = Vec::default();
self.temp_harvest = Vec::default();
self.battery_harvest = Vec::default();
- #[cfg(target_family = "unix")]
- {
- *self.user_table.borrow_mut() = UserTable::default();
- }
}
pub fn set_frozen_time(&mut self) {
diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs
index d5ff467d..52bd167a 100644
--- a/src/app/data_harvester.rs
+++ b/src/app/data_harvester.rs
@@ -96,6 +96,9 @@ pub struct DataCollector {
battery_manager: Option<Manager>,
battery_list: Option<Vec<Battery>>,
filters: DataFilters,
+
+ #[cfg(target_family = "unix")]
+ user_table: self::processes::UserTable,
}
impl DataCollector {
@@ -123,6 +126,8 @@ impl DataCollector {
battery_manager: None,
battery_list: None,
filters,
+ #[cfg(target_family = "unix")]
+ user_table: Default::default(),
}
}
@@ -253,9 +258,19 @@ impl DataCollector {
.duration_since(self.last_collection_time)
.as_secs(),
self.mem_total_kb,
+ &mut self.user_table,
+ )
+ }
+ #[cfg(target_os = "macos")]
+ {
+ processes::get_process_data(
+ &self.sys,
+ self.use_current_cpu_total,
+ self.mem_total_kb,
+ &mut self.user_table,
)
}
- #[cfg(not(target_os = "linux"))]
+ #[cfg(target_os = "windows")]
{
processes::get_process_data(
&self.sys,
diff --git a/src/app/data_harvester/processes.rs b/src/app/data_harvester/processes.rs
index 283080b3..3d8d7d5c 100644
--- a/src/app/data_harvester/processes.rs
+++ b/src/app/data_harvester/processes.rs
@@ -23,6 +23,8 @@ cfg_if::cfg_if! {
}
}
+use std::borrow::Cow;
+
use crate::Pid;
// TODO: Add value so we know if it's sorted ascending or descending by default?
@@ -93,5 +95,8 @@ pub struct ProcessHarvest {
/// This is the *effective* user ID.
#[cfg(target_family = "unix")]
- pub uid: Option<libc::uid_t>,
+ pub uid: libc::uid_t,
+
+ #[cfg(target_family = "unix")]
+ pub user: Cow<'static, str>,
}
diff --git a/src/app/data_harvester/processes/linux.rs b/src/app/data_harvester/processes/linux.rs
index 87297837..eb8f8a50 100644
--- a/src/app/data_harvester/processes/linux.rs
+++ b/src/app/data_harvester/processes/linux.rs
@@ -5,7 +5,7 @@ use std::collections::hash_map::Entry;
use crate::utils::error::{self, BottomError};
use crate::Pid;
-use super::ProcessHarvest;
+use super::{ProcessHarvest, UserTable};
use sysinfo::ProcessStatus;
@@ -117,6 +117,7 @@ fn get_linux_cpu_usage(
fn read_proc(
prev_proc: &PrevProcDetails, stat: &Stat, cpu_usage: f64, cpu_fraction: f64,
use_current_cpu_total: bool, time_difference_in_secs: u64, mem_total_kb: u64,
+ user_table: &mut UserTable,
) -> error::Result<(ProcessHarvest, u64)> {
use std::convert::TryFrom;
@@ -196,7 +197,7 @@ fn read_proc(
(0, 0, 0, 0)
};
- let uid = Some(process.owner);
+ let uid = process.owner;
Ok((
ProcessHarvest {
@@ -214,6 +215,10 @@ fn read_proc(
process_state,
process_state_char,
uid,
+ user: user_table
+ .get_uid_to_username_mapping(uid)
+ .map(Into::into)
+ .unwrap_or("N/A".into()),
},
new_process_times,
))
@@ -222,7 +227,7 @@ fn read_proc(
pub fn get_process_data(
prev_idle: &mut f64, prev_non_idle: &mut f64,
pid_mapping: &mut FxHashMap<Pid, PrevProcDetails>, use_current_cpu_total: bool,
- time_difference_in_secs: u64, mem_total_kb: u64,
+ time_difference_in_secs: u64, mem_total_kb: u64, user_table: &mut UserTable,
) -> crate::utils::error::Result<Vec<ProcessHarvest>> {
// TODO: [PROC THREADS] Add threads
@@ -265,6 +270,7 @@ pub fn get_process_data(
use_current_cpu_total,
time_difference_in_secs,
mem_total_kb,
+ user_table,
) {
prev_proc_details.cpu_time = new_process_times;
prev_proc_details.total_read_bytes =
diff --git a/src/app/data_harvester/processes/macos.rs b/src/app/data_harvester/processes/macos.rs
index f0c3980d..a65f2627 100644
--- a/src/app/data_harvester/processes/macos.rs
+++ b/src/app/data_harvester/processes/macos.rs
@@ -1,6 +1,6 @@
//! Process data collection for macOS. Uses sysinfo.
-use super::ProcessHarvest;
+use super::{ProcessHarvest, UserTable};
use sysinfo::{ProcessExt, ProcessStatus, ProcessorExt, System, SystemExt};
fn get_macos_process_cpu_usage(
@@ -35,7 +35,7 @@ fn get_macos_process_cpu_usage(
}
pub fn get_process_data(
- sys: &System, use_current_cpu_total: bool, mem_total_kb: u64,
+ sys: &System, use_current_cpu_total: bool, mem_total_kb: u64, user_table: &mut UserTable,
) -> crate::utils::error::Result<Vec<ProcessHarvest>> {
let mut process_vector: Vec<ProcessHarvest> = Vec::new();
let process_hashmap = sys.get_processes();
@@ -104,7 +104,11 @@ pub fn get_process_data(
total_write_bytes: disk_usage.total_written_bytes,
process_state: process_val.status().to_string(),
process_state_char: convert_process_status_to_char(process_val.status()),
- uid: Some(process_val.uid),
+ uid: process_val.uid,
+ user: user_table
+ .get_uid_to_username_mapping(uid)
+ .map(Into::into)
+ .unwrap_or("N/A".into()),
});
}
diff --git a/src/app/event.rs b/src/app/event.rs
index b0e0e39a..a776a493 100644
--- a/src/app/event.rs
+++ b/src/app/event.rs
@@ -2,15 +2,23 @@ use std::time::{Duration, Instant};
const MAX_TIMEOUT: Duration = Duration::from_millis(400);
-/// These are "signals" that are sent along with an [`EventResult`] to signify a potential additional action
+/// These are "signals" that are sent along with an [`WidgetEventResult`] to signify a potential additional action
/// that the caller must do, along with the "core" result of either drawing or redrawing.
pub enum ReturnSignal {
/// A signal returned when some process widget was told to try to kill a process (or group of processes).
+ ///
+ /// This return signal should trigger a redraw when handled.
KillProcess,
+
+ /// A signal returned when a widget needs the app state to re-trigger its update call. Usually needed for
+ /// widgets where the displayed contents are built only on update.
+ ///
+ /// This return signal should trigger a redraw when handled.
+ Update,
}
-/// The results of handling a [`ReturnSignal`].
-pub enum ReturnSignalResult {
+/// The results of handling an event by the [`AppState`].
+pub enum EventResult {
/// Kill the program.
Quit,
/// Trigger a redraw.
@@ -19,9 +27,9 @@ pub enum ReturnSignalResult {
NoRedraw,
}
-/// The results of handling some user input event, like a mouse or key event, signifying what
-/// the program should then do next.
-pub enum EventResult {
+/// The results of a widget handling some event, like a mouse or key event,
+/// signifying what the program should then do next.
+pub enum WidgetEventResult {
/// Kill the program.
Quit,
/// Trigger a redraw.
diff --git a/src/app/widgets.rs b/src/app/widgets.rs
index 34009939..751157c7 100644
--- a/src/app/widgets.rs
+++ b/src/app/widgets.rs
@@ -6,7 +6,7 @@ use tui::{backend::Backend, layout::Rect, widgets::TableState, Frame};
use crate::{
app::{
- event::{EventResult, SelectionAction},
+ event::{WidgetEventResult, SelectionAction},
layout_manager::BottomWidgetType,
},
canvas::Painter,
@@ -48,15 +48,15 @@ pub trait Component {
/// Handles a [`KeyEvent`].
///
/// Defaults to returning [`EventResult::NoRedraw`], indicating nothing should be done.
- fn handle_key_event(&mut self, event: KeyEvent) -> EventResult {
- EventResult::NoRedraw
+ fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult {
+ WidgetEventResult::NoRedraw
}
/// Handles a [`MouseEvent`].
///
/// Defaults to returning [`EventResult::Continue`], indicating nothing should be done.
- fn handle_mouse_event(&mut self, event: MouseEvent) -> EventResult {
- EventResult::NoRedraw
+ fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult {
+ WidgetEventResult::NoRedraw
}
/// Returns a [`Component`]'s bounding box. Note that these are defined in *global*, *absolute*
diff --git a/src/app/widgets/base/scrollable.rs b/src/app/widgets/base/scrollable.rs
index 7e2a504e..811d7017 100644
--- a/src/app/widgets/base/scrollable.rs
+++ b/src/app/widgets/base/scrollable.rs
@@ -2,7 +2,7 @@ use crossterm::event::{KeyEvent, KeyModifiers, MouseButton, MouseEvent, MouseEve
use tui::{layout::Rect, widgets::TableState};
use crate::app::{
- event::{EventResult, MultiKey, MultiKeyResult},
+ event::{WidgetEventResult, MultiKey, MultiKeyResult},
Component,
};
@@ -128,56 +128,56 @@ impl Scrollable {
}
}
- fn skip_to_first(&mut self) -> EventResult {
+ fn skip_to_first(&mut self) -> WidgetEventResult {
if self.current_index != 0 {
self.update_index(0);
- EventResult::Redraw
+ WidgetEventResult::Redraw
} else {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
}
- fn skip_to_last(&mut self) -> EventResult {
+ fn skip_to_last(&mut self) -> WidgetEventResult {
let last_index = self.num_items - 1;
if self.current_index != last_index {
self.update_index(last_index);
- EventResult::Redraw
+ WidgetEventResult::Redraw
} else {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
}
/// Moves *downward* by *incrementing* the current index.
- fn move_down(&mut self, change_by: usize) -> EventResult {
+ fn move_down(&mut self, change_by: usize) -> WidgetEventResult {
if self.num_items == 0 {
- return EventResult::NoRedraw;
+ return WidgetEventResult::NoRedraw;
}
let new_index = self.current_index + change_by;
if new_index >= self.num_items {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
} else if self.current_index == new_index {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
} else {
self.update_index(new_index);
- EventResult::Redraw
+ WidgetEventResult::Redraw
}
}
/// Moves *upward* by *decrementing* the current index.
- fn move_up(&mut self, change_by: usize) -> EventResult {
+ fn move_up(&mut self, change_by: usize) -> WidgetEventResult {
if self.num_items == 0 {
- return EventResult::NoRedraw;
+ return WidgetEventResult::NoRedraw;
}
let new_index = self.current_index.saturating_sub(change_by);
if self.current_index == new_index {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
} else {
self.update_index(new_index);
- EventResult::Redraw
+ WidgetEventResult::Redraw
}
}
@@ -199,7 +199,7 @@ impl Scrollable {
}
impl Component for Scrollable {
- fn handle_key_event(&mut self, event: KeyEvent) -> EventResult {
+ fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult {
use crossterm::event::KeyCode::{Char, Down, Up};
if event.modifiers == KeyModifiers::NONE || event.modifiers == KeyModifiers::SHIFT {
@@ -210,18 +210,18 @@ impl Component for Scrollable {
Char('k') => self.move_up(1),
Char('g') => match self.gg_manager.input('g') {
MultiKeyResult::Completed => self.skip_to_first(),
- MultiKeyResult::Accepted => EventResult::NoRedraw,
- MultiKeyResult::Rejected => EventResult::NoRedraw,
+ MultiKeyResult::Accepted => WidgetEventResult::NoRedraw,
+ MultiKeyResult::Rejected => WidgetEventResult::NoRedraw,
},
Char('G') => self.skip_to_last(),
- _ => EventResult::NoRedraw,
+ _ => WidgetEventResult::NoRedraw,
}
} else {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
}
- fn handle_mouse_event(&mut self, event: MouseEvent) -> EventResult {
+ fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult {
match event.kind {
MouseEventKind::Down(MouseButton::Left) => {
if self.does_intersect_mouse(&event) {
@@ -244,11 +244,11 @@ impl Component for Scrollable {
}
}
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
MouseEventKind::ScrollDown => self.move_down(1),
MouseEventKind::ScrollUp => self.move_up(1),
- _ => EventResult::NoRedraw,
+ _ => WidgetEventResult::NoRedraw,
}
}
diff --git a/src/app/widgets/base/sort_text_table.rs b/src/app/widgets/base/sort_text_table.rs
index e5d8c8a2..23f46250 100644
--- a/src/app/widgets/base/sort_text_table.rs
+++ b/src/app/widgets/base/sort_text_table.rs
@@ -1,14 +1,13 @@
use std::borrow::Cow;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseButton, MouseEvent, MouseEventKind};
-use tui::{
- backend::Backend,
- layout::Rect,
- widgets::{Block, Table, TableState},
-};
+use tui::{backend::Backend, layout::Rect, widgets::Block};
use crate::{
- app::{event::EventResult, Component, TextTable},
+ app::{
+ event::{ReturnSignal, WidgetEventResult},
+ Component, TextTable,
+ },
canvas::Painter,
};
@@ -243,6 +242,7 @@ impl<S> SortableTextTable<S>
where
S: SortableColumn,
{
+ /// Creates a new [`SortableTextTable`]. Note that `columns` cannot be empty.
pub fn new(columns: Vec<S>) -> Self {
let mut st = Self {
sort_index: 0,
@@ -262,8 +262,13 @@ where
self
}
- pub fn current_index(&self) -> usize {
- self.table.current_index()
+ pub fn current_scroll_index(&self) -> usize {
+ self.table.current_scroll_index()
+ }
+
+ /// Returns the current column.
+ pub fn current_column(&self) -> &S {
+ &self.table.columns[self.sort_index]
}
pub fn columns(&self) -> &[S] {
@@ -310,7 +315,7 @@ where
}
}
- /// Draws a [`Table`] given the [`TextTable`] and the given data.
+ /// Draws a [`tui::widgets::Table`] on screen.
///
/// Note if the number of columns don't match in the [`TextTable`] and data,
/// it will only create as many columns as it can grab data from both sources from.
@@ -327,12 +332,12 @@ impl<S> Component for SortableTextTable<S>
where
S: SortableColumn,
{
- fn handle_key_event(&mut self, event: KeyEvent) -> EventResult {
+ fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult {
for (index, column) in self.table.columns.iter().enumerate() {
if let &Some((shortcut, _)) = column.shortcut() {
if shortcut == event {
self.set_sort_index(index);
- return EventResult::Redraw;
+ return WidgetEventResult::Signal(ReturnSignal::Update);
}
}
}
@@ -340,10 +345,10 @@ where
self.table.scrollable.handle_key_event(event)
}
- fn handle_mouse_event(&mut self, event: MouseEvent) -> EventResult {
+ fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult {
if let MouseEventKind::Down(MouseButton::Left) = event.kind {
if !self.does_intersect_mouse(&event) {
- return EventResult::NoRedraw;
+ return WidgetEventResult::NoRedraw;
}
// Note these are representing RELATIVE coordinates! They *need* the above intersection check for validity!
@@ -355,7 +360,7 @@ where
if let Some((start, end)) = column.get_x_bounds() {
if x >= start && x <= end {
self.set_sort_index(index);
- return EventResult::Redraw;
+ return WidgetEventResult::Signal(ReturnSignal::Update);
}
}
}
diff --git a/src/app/widgets/base/text_input.rs b/src/app/widgets/base/text_input.rs
index 432c04b9..dfe776de 100644
--- a/src/app/widgets/base/text_input.rs
+++ b/src/app/widgets/base/text_input.rs
@@ -2,7 +2,7 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent};
use tui::layout::Rect;
use crate::app::{
- event::EventResult::{self},
+ event::WidgetEventResult::{self},
Component,
};
@@ -22,20 +22,20 @@ impl TextInput {
}
}
- fn set_cursor(&mut self, new_cursor_index: usize) -> EventResult {
+ fn set_cursor(&mut self, new_cursor_index: usize) -> WidgetEventResult {
if self.cursor_index == new_cursor_index {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
} else {
self.cursor_index = new_cursor_index;
- EventResult::Redraw
+ WidgetEventResult::Redraw
}
}
- fn move_back(&mut self, amount_to_subtract: usize) -> EventResult {
+ fn move_back(&mut self, amount_to_subtract: usize) -> WidgetEventResult {
self.set_cursor(self.cursor_index.saturating_sub(amount_to_subtract))
}
- fn move_forward(&mut self, amount_to_add: usize) -> EventResult {
+ fn move_forward(&mut self, amount_to_add: usize) -> WidgetEventResult {
let new_cursor = self.cursor_index + amount_to_add;
if new_cursor >= self.text.len() {
self.set_cursor(self.text.len() - 1)
@@ -44,34 +44,34 @@ impl TextInput {
}
}
- fn clear_text(&mut self) -> EventResult {
+ fn clear_text(&mut self) -> WidgetEventResult {
if self.text.is_empty() {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
} else {
self.text = String::default();
self.cursor_index = 0;
- EventResult::Redraw
+ WidgetEventResult::Redraw
}
}
- fn move_word_forward(&mut self) -> EventResult {
+ fn move_word_forward(&mut self) -> WidgetEventResult {
// TODO: Implement this
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
- fn move_word_back(&mut self) -> EventResult {
+ fn move_word_back(&mut self) -> WidgetEventResult {
// TODO: Implement this
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
- fn clear_previous_word(&mut self) -> EventResult {
+ fn clear_previous_word(&mut self) -> WidgetEventResult {
// TODO: Implement this
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
- fn clear_previous_grapheme(&mut self) -> EventResult {
+ fn clear_previous_grapheme(&mut self) -> WidgetEventResult {
// TODO: Implement this
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
pub fn update(&mut self, new_text: String) {
@@ -92,13 +92,13 @@ impl Component for TextInput {
self.bounds = new_bounds;
}
- fn handle_key_event(&mut self, event: KeyEvent) -> EventResult {
+ fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult {
if event.modifiers.is_empty() {
match event.code {
KeyCode::Left => self.move_back(1),
KeyCode::Right => self.move_forward(1),
KeyCode::Backspace => self.clear_previous_grapheme(),
- _ => EventResult::NoRedraw,
+ _ => WidgetEventResult::NoRedraw,
}
} else if let KeyModifiers::CONTROL = event.modifiers {
match event.code {
@@ -107,20 +107,20 @@ impl Component for TextInput {
KeyCode::Char('u') => self.clear_text(),
KeyCode::Char('w') => self.clear_previous_word(),
KeyCode::Char('h') => self.clear_previous_grapheme(),
- _ => EventResult::NoRedraw,
+ _ => WidgetEventResult::NoRedraw,
}
} else if let KeyModifiers::ALT = event.modifiers {
match event.code {
KeyCode::Char('b') => self.move_word_forward(),
KeyCode::Char('f') => self.move_word_back(),
- _ => EventResult::NoRedraw,
+ _ => WidgetEventResult::NoRedraw,
}
} else {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
}
- fn handle_mouse_event(&mut self, event: MouseEvent) -> EventResult {
+ fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult {
// We are assuming this is within bounds...
let x = event.column;
@@ -133,6 +133,6 @@ impl Component for TextInput {
self.cursor_index = new_cursor_index;
}
- EventResult::Redraw
+ WidgetEventResult::Redraw
}
}
diff --git a/src/app/widgets/base/text_table.rs b/src/app/widgets/base/text_table.rs
index 2eaf444c..20d78b8e 100644
--- a/src/app/widgets/base/text_table.rs
+++ b/src/app/widgets/base/text_table.rs
@@ -15,7 +15,7 @@ use tui::{
use unicode_segmentation::UnicodeSegmentation;
use crate::{
- app::{event::EventResult, Component, Scrollable},
+ app::{event::WidgetEventResult, Component, Scrollable},
canvas::Painter,
constants::TABLE_GAP_HEIGHT_LIMIT,
};
@@ -186,7 +186,7 @@ where
}
}
- pub fn current_index(&self) -> usize {
+ pub fn current_scroll_index(&self) -> usize {
self.scrollable.current_index()
}
@@ -342,7 +342,7 @@ where
}
}
- /// Draws a [`Table`] given the [`TextTable`] and the given data.
+ /// Draws a [`Table`] on screen..
///
/// Note if the number of columns don't match in the [`TextTable`] and data,
/// it will only create as many columns as it can grab data from both sources from.
@@ -443,19 +443,19 @@ impl<C> Component for TextTable<C>
where
C: TableColumn,
{
- fn handle_key_event(&mut self, event: KeyEvent) -> EventResult {
+ fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult {
if self.selectable {
self.scrollable.handle_key_event(event)
} else {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
}
- fn handle_mouse_event(&mut self, event: MouseEvent) -> EventResult {
+ fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult {
if self.selectable {
self.scrollable.handle_mouse_event(event)
} else {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
}
diff --git a/src/app/widgets/base/time_graph.rs b/src/app/widgets/base/time_graph.rs
index 8863fa4b..1f8399ff 100644
--- a/src/app/widgets/base/time_graph.rs
+++ b/src/app/widgets/base/time_graph.rs
@@ -15,7 +15,7 @@ use tui::{
use crate::{
app::{
- event::EventResult,
+ event::WidgetEventResult,
widgets::tui_widgets::{
custom_legend_chart::{Axis, Dataset},
TimeChart,
@@ -155,58 +155,58 @@ impl TimeGraph {
}
/// Handles a char `c`.
- fn handle_char(&mut self, c: char) -> EventResult {
+ fn handle_char(&mut self, c: char) -> WidgetEventResult {
match c {
'-' => self.zoom_out(),
'+' => self.zoom_in(),
'=' => self.reset_zoom(),
- _ => EventResult::NoRedraw,
+ _ => WidgetEventResult::NoRedraw,
}
}
- fn zoom_in(&mut self) -> EventResult {
+ fn zoom_in(&mut self) -> WidgetEventResult {
let new_time = self.current_display_time.saturating_sub(self.time_interval);
if new_time >= self.min_duration {
self.current_display_time = new_time;
self.autohide_timer.start_display_timer();
- EventResult::Redraw
+ WidgetEventResult::Redraw
} else if new_time != self.min_duration {
self.current_display_time = self.min_duration;
self.autohide_timer.start_display_timer();
- EventResult::Redraw
+ WidgetEventResult::Redraw
} else {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
}
- fn zoom_out(&mut self) -> EventResult {
+ fn zoom_out(&mut self) -> WidgetEventResult {
let new_time = self.current_display_time + self.time_interval;
if new_time <= self.max_duration {
self.current_display_time = new_time;
self.autohide_timer.start_display_timer();
- EventResult::Redraw
+ WidgetEventResult::Redraw
} else if new_time != self.max_duration {
self.current_display_time = self.max_duration;
self.autohide_timer.start_display_timer();
- EventResult::Redraw
+ WidgetEventResult::Redraw
} else {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
}
- fn reset_zoom(&mut self) -> EventResult {
+ fn reset_zoom(&mut self) -> WidgetEventResult {
if self.current_display_time == self.default_time_value {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
} else {
self.current_display_time = self.default_time_value;
self.autohide_timer.start_display_timer();
- EventResult::Redraw
+ WidgetEventResult::Redraw
}
}
@@ -296,24 +296,24 @@ impl TimeGraph {
}
impl Component for TimeGraph {
- fn handle_key_event(&mut self, event: KeyEvent) -> EventResult {
+ fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult {
use crossterm::event::KeyCode::Char;
if event.modifiers == KeyModifiers::NONE || event.modifiers == KeyModifiers::SHIFT {
match event.code {
Char(c) => self.handle_char(c),
- _ => EventResult::NoRedraw,
+ _ => WidgetEventResult::NoRedraw,
}
} else {
- EventResult::NoRedraw
+ WidgetEventResult::NoRedraw
}
}
- fn handle_mouse_event(&mut self, event: MouseEvent) -> EventResult {
+ fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult {
match event.kind {
MouseEventKind::ScrollDown => self.zoom_out(),
MouseEventKind::ScrollUp => self.zoom_in(),
- _ => EventResult::NoRedraw,
+ _ => WidgetEventResult::NoRedraw,
}
}
diff --git a/src/app/widgets/cpu.rs b/src/app/widgets/cpu.rs
index 51c9d795..566ce4cc 100644
--- a/src/app/widgets/cpu.rs
+++ b/src/app/widgets/cpu.rs
@@ -9,7 +9,7 @@ use tui::{
use crate::{