summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClementTsang <cjhtsang@uwaterloo.ca>2021-09-27 16:28:48 -0400
committerClementTsang <cjhtsang@uwaterloo.ca>2021-10-02 00:04:41 -0400
commitf02daa0a2b2b38934bcb2189373afec85862048d (patch)
tree8f341e6decc0d38096a33d4e2bc32b27f2c38930
parent9089231bc46e9732aac522be89877dcd53a06c6d (diff)
refactor: various bug fixes and code removal
-rw-r--r--Cargo.lock12
-rw-r--r--Cargo.toml1
-rw-r--r--src/app.rs16
-rw-r--r--src/app/data_farmer.rs13
-rw-r--r--src/app/data_harvester/processes.rs6
-rw-r--r--src/app/data_harvester/processes/linux.rs1
-rw-r--r--src/app/data_harvester/processes/macos.rs1
-rw-r--r--src/app/data_harvester/processes/windows.rs1
-rw-r--r--src/app/layout_manager.rs135
-rw-r--r--src/app/process_killer.rs77
-rw-r--r--src/app/process_killer/unix.rs31
-rw-r--r--src/app/process_killer/windows.rs40
-rw-r--r--src/app/widgets.rs5
-rw-r--r--src/app/widgets/base/sort_menu.rs5
-rw-r--r--src/app/widgets/base/sort_text_table.rs4
-rw-r--r--src/app/widgets/base/text_table.rs5
-rw-r--r--src/app/widgets/bottom_widgets/battery.rs1
-rw-r--r--src/app/widgets/bottom_widgets/cpu.rs3
-rw-r--r--src/app/widgets/bottom_widgets/disk.rs14
-rw-r--r--src/app/widgets/bottom_widgets/net.rs8
-rw-r--r--src/app/widgets/bottom_widgets/process.rs19
-rw-r--r--src/app/widgets/bottom_widgets/temp.rs12
-rw-r--r--src/canvas.rs50
-rw-r--r--src/constants.rs10
-rw-r--r--src/data_conversion.rs307
-rw-r--r--src/lib.rs2
-rw-r--r--src/options.rs18
-rw-r--r--src/utils/error.rs3
-rw-r--r--src/utils/gen_util.rs11
29 files changed, 152 insertions, 659 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2dbda550..5973baf8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -266,7 +266,6 @@ dependencies = [
"thiserror",
"toml",
"tui",
- "typed-builder",
"unicode-segmentation",
"unicode-width",
"winapi",
@@ -1530,17 +1529,6 @@ dependencies = [
]
[[package]]
-name = "typed-builder"
-version = "0.9.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a46ee5bd706ff79131be9c94e7edcb82b703c487766a114434e5790361cf08c5"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
name = "typenum"
version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index e1612171..d44d54f6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -59,7 +59,6 @@ thiserror = "1.0.24"
textwrap = "0.14.2"
toml = "0.5.8"
tui = { version = "0.16.0", features = ["crossterm"], default-features = false }
-typed-builder = "0.9.0"
unicode-segmentation = "1.8.0"
unicode-width = "0.1"
diff --git a/src/app.rs b/src/app.rs
index 4b58b014..d81b88fa 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -19,9 +19,7 @@ pub use filter::*;
use layout_manager::*;
pub use widgets::*;
-use crate::{
- canvas, constants, units::data_units::DataUnit, utils::error::Result, BottomEvent, Pid,
-};
+use crate::{constants, units::data_units::DataUnit, utils::error::Result, BottomEvent, Pid};
use self::event::{ComponentEventResult, EventResult, ReturnSignal};
@@ -87,7 +85,7 @@ pub struct AppConfigFields {
pub hide_time: bool,
pub autohide_time: bool,
pub use_old_network_legend: bool,
- pub table_gap: u16, // TODO: [Config, Refactor] Just make this a bool...
+ pub table_gap: bool,
pub disable_click: bool,
pub no_write: bool,
pub show_table_scroll_position: bool,
@@ -101,7 +99,7 @@ pub struct AppConfigFields {
/// the data collected at that instant.
pub enum FrozenState {
NotFrozen,
- Frozen(DataCollection),
+ Frozen(Box<DataCollection>),
}
impl Default for FrozenState {
@@ -115,8 +113,6 @@ pub struct AppState {
to_delete_process_list: Option<(String, Vec<Pid>)>,
- pub canvas_data: canvas::DisplayableData,
-
pub data_collection: DataCollection,
pub is_expanded: bool,
@@ -167,7 +163,6 @@ impl AppState {
// Use defaults.
dd_err: Default::default(),
to_delete_process_list: Default::default(),
- canvas_data: Default::default(),
data_collection: Default::default(),
is_expanded: Default::default(),
delete_dialog_state: Default::default(),
@@ -186,7 +181,7 @@ impl AppState {
if matches!(self.frozen_state, FrozenState::Frozen(_)) {
self.frozen_state = FrozenState::NotFrozen;
} else {
- self.frozen_state = FrozenState::Frozen(self.data_collection.clone());
+ self.frozen_state = FrozenState::Frozen(Box::new(self.data_collection.clone()));
}
}
@@ -418,7 +413,6 @@ impl AppState {
if was_id_already_selected {
returned_result = self.convert_widget_event_result(result);
- break;
} else {
// If the weren't equal, *force* a redraw, and correct the layout tree.
correct_layout_last_selections(
@@ -427,8 +421,8 @@ impl AppState {
);
let _ = self.convert_widget_event_result(result);
returned_result = EventResult::Redraw;
- break;
}
+ break;
}
SelectableType::Unselectable => {
let result = widget.handle_mouse_event(event);
diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs
index 6b850f8b..83b53d29 100644
--- a/src/app/data_farmer.rs
+++ b/src/app/data_farmer.rs
@@ -26,17 +26,14 @@ use crate::{
};
use regex::Regex;
-pub type TimeOffset = f64;
-pub type Value = f64;
-
#[derive(Clone, Debug, Default)]
pub struct TimedData {
- pub rx_data: Value,
- pub tx_data: Value,
- pub cpu_data: Vec<Value>,
+ pub rx_data: f64,
+ pub tx_data: f64,
+ pub cpu_data: Vec<f64>,
pub load_avg_data: [f32; 3],
- pub mem_data: Option<Value>,
- pub swap_data: Option<Value>,
+ pub mem_data: Option<f64>,
+ pub swap_data: Option<f64>,
}
/// AppCollection represents the pooled data stored within the main app
diff --git a/src/app/data_harvester/processes.rs b/src/app/data_harvester/processes.rs
index 4b09a078..1ee60123 100644
--- a/src/app/data_harvester/processes.rs
+++ b/src/app/data_harvester/processes.rs
@@ -78,7 +78,8 @@ impl Default for ProcessSorting {
#[derive(Debug, Clone, Default)]
pub struct ProcessHarvest {
pub pid: Pid,
- pub parent_pid: Option<Pid>, // Remember, parent_pid 0 is root...
+ pub parent_pid: Option<Pid>,
+ pub children_pids: Vec<Pid>,
pub cpu_usage_percent: f64,
pub mem_usage_percent: f64,
pub mem_usage_bytes: u64,
@@ -93,10 +94,11 @@ pub struct ProcessHarvest {
pub process_state: String,
pub process_state_char: char,
- /// This is the *effective* user ID.
+ /// This is the *effective* user ID. This is only used on Unix platforms.
#[cfg(target_family = "unix")]
pub uid: libc::uid_t,
+ /// This is the process' user. This is only used on Unix platforms.
#[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 aad67adf..2e9384f5 100644
--- a/src/app/data_harvester/processes/linux.rs
+++ b/src/app/data_harvester/processes/linux.rs
@@ -203,6 +203,7 @@ fn read_proc(
ProcessHarvest {
pid: process.pid,
parent_pid,
+ children_pids: vec![],
cpu_usage_percent,
mem_usage_percent,
mem_usage_bytes,
diff --git a/src/app/data_harvester/processes/macos.rs b/src/app/data_harvester/processes/macos.rs
index a65f2627..d5dffe85 100644
--- a/src/app/data_harvester/processes/macos.rs
+++ b/src/app/data_harvester/processes/macos.rs
@@ -89,6 +89,7 @@ pub fn get_process_data(
process_vector.push(ProcessHarvest {
pid: process_val.pid(),
parent_pid: process_val.parent(),
+ children_pids: vec![],
name,
command,
mem_usage_percent: if mem_total_kb > 0 {
diff --git a/src/app/data_harvester/processes/windows.rs b/src/app/data_harvester/processes/windows.rs
index 08cde500..763f9cf8 100644
--- a/src/app/data_harvester/processes/windows.rs
+++ b/src/app/data_harvester/processes/windows.rs
@@ -58,6 +58,7 @@ pub fn get_process_data(
process_vector.push(ProcessHarvest {
pid: process_val.pid(),
parent_pid: process_val.parent(),
+ children_pids: vec![],
name,
command,
mem_usage_percent: if mem_total_kb > 0 {
diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs
index bde3febb..7f0dd663 100644
--- a/src/app/layout_manager.rs
+++ b/src/app/layout_manager.rs
@@ -13,7 +13,6 @@ use fxhash::FxHashMap;
use indextree::{Arena, NodeId};
use std::cmp::min;
use tui::layout::Rect;
-use typed_builder::*;
use crate::app::widgets::Widget;
@@ -21,130 +20,6 @@ use super::{
event::SelectionAction, AppConfigFields, CpuGraph, TimeGraph, TmpBottomWidget, UsedWidgets,
};
-/// Represents a more usable representation of the layout, derived from the
-/// config.
-#[derive(Clone, Debug)]
-pub struct BottomLayout {
- pub rows: Vec<OldBottomRow>,
- pub total_row_height_ratio: u32,
-}
-
-/// Represents a single row in the layout.
-#[derive(Clone, Debug, TypedBuilder)]
-pub struct OldBottomRow {
- pub children: Vec<OldBottomCol>,
-
- #[builder(default = 1)]
- pub total_col_ratio: u32,
-
- #[builder(default = 1)]
- pub row_height_ratio: u32,
-
- #[builder(default = false)]
- pub canvas_handle_height: bool,
-
- #[builder(default = false)]
- pub flex_grow: bool,
-}
-
-/// Represents a single column in the layout. We assume that even if the column
-/// contains only ONE element, it is still a column (rather than either a col or
-/// a widget, as per the config, for simplicity's sake).
-#[derive(Clone, Debug, TypedBuilder)]
-pub struct OldBottomCol {
- pub children: Vec<BottomColRow>,
-
- #[builder(default = 1)]
- pub total_col_row_ratio: u32,
-
- #[builder(default = 1)]
- pub col_width_ratio: u32,
-
- #[builder(default = false)]
- pub canvas_handle_width: bool,
-
- #[builder(default = false)]
- pub flex_grow: bool,
-}
-
-#[derive(Clone, Default, Debug, TypedBuilder)]
-pub struct BottomColRow {
- pub children: Vec<BottomWidget>,
-
- #[builder(default = 1)]
- pub total_widget_ratio: u32,
-
- #[builder(default = 1)]
- pub col_row_height_ratio: u32,
-
- #[builder(default = false)]
- pub canvas_handle_height: bool,
-
- #[builder(default = false)]
- pub flex_grow: bool,
-}
-
-#[derive(Debug, Clone, Eq, PartialEq)]
-pub enum WidgetDirection {
- Left,
- Right,
- Up,
- Down,
-}
-
-impl WidgetDirection {
- pub fn is_opposite(&self, other_direction: &WidgetDirection) -> bool {
- match &self {
- WidgetDirection::Left => *other_direction == WidgetDirection::Right,
- WidgetDirection::Right => *other_direction == WidgetDirection::Left,
- WidgetDirection::Up => *other_direction == WidgetDirection::Down,
- WidgetDirection::Down => *other_direction == WidgetDirection::Up,
- }
- }
-}
-
-/// Represents a single widget.
-#[derive(Debug, Default, Clone, TypedBuilder)]
-pub struct BottomWidget {
- pub widget_type: BottomWidgetType,
- pub widget_id: u64,
-
- #[builder(default = 1)]
- pub width_ratio: u32,
-
- #[builder(default = None)]
- pub left_neighbour: Option<u64>,
-
- #[builder(default = None)]
- pub right_neighbour: Option<u64>,
-
- #[builder(default = None)]
- pub up_neighbour: Option<u64>,
-
- #[builder(default = None)]
- pub down_neighbour: Option<u64>,
-
- /// If set to true, the canvas will override any ratios.
- #[builder(default = false)]
- pub canvas_handle_width: bool,
-
- /// Whether we want this widget to take up all available room (and ignore any ratios).
- #[builder(default = false)]
- pub flex_grow: bool,
-
- /// The value is the direction to bounce, as well as the parent offset.
- #[builder(default = None)]
- pub parent_reflector: Option<(WidgetDirection, u64)>,
-
- /// Top left corner when drawn, for mouse click detection. (x, y)
- #[builder(default = None)]
- pub top_left_corner: Option<(u16, u16)>,
-
- /// Bottom right corner when drawn, for mouse click detection. (x, y)
- #[builder(default = None)]
- pub bottom_right_corner: Option<(u16, u16)>,
-}
-
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum BottomWidgetType {
Empty,
@@ -238,8 +113,6 @@ Supported widget names:
}
}
-// --- New stuff ---
-
/// Represents a row in the layout tree.
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct RowLayout {
@@ -380,7 +253,7 @@ pub fn create_layout_tree(
BottomWidgetType::Proc => {
widget_lookup_map.insert(
widget_id,
- ProcessManager::new(process_defaults)
+ ProcessManager::new(process_defaults, app_config_fields)
.width(width)
.height(height)
.basic_mode(app_config_fields.use_basic_mode)
@@ -391,7 +264,7 @@ pub fn create_layout_tree(
BottomWidgetType::Temp => {
widget_lookup_map.insert(
widget_id,
- TempTable::default()
+ TempTable::from_config(app_config_fields)
.set_temp_type(app_config_fields.temperature_type.clone())
.width(width)
.height(height)
@@ -403,7 +276,7 @@ pub fn create_layout_tree(
BottomWidgetType::Disk => {
widget_lookup_map.insert(
widget_id,
- DiskTable::default()
+ DiskTable::from_config(app_config_fields)
.width(width)
.height(height)
.basic_mode(app_config_fields.use_basic_mode)
@@ -620,7 +493,7 @@ pub fn create_layout_tree(
///
/// We can do this by just going through the ancestors, starting from the widget itself.
pub fn correct_layout_last_selections(arena: &mut Arena<LayoutNode>, selected: NodeId) {
- let mut selected_ancestors = selected.ancestors(&arena).collect::<Vec<_>>();
+ let mut selected_ancestors = selected.ancestors(arena).collect::<Vec<_>>();
let prev_node = selected_ancestors.pop();
if let Some(mut prev_node) = prev_node {
for node in selected_ancestors {
diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs
index 9f38bc5d..c1095850 100644
--- a/src/app/process_killer.rs
+++ b/src/app/process_killer.rs
@@ -1,78 +1,7 @@
-// Copied from SO: https://stackoverflow.com/a/55231715
-#[cfg(target_os = "windows")]
-use winapi::{
- shared::{minwindef::DWORD, ntdef::HANDLE},
- um::{
- processthreadsapi::{OpenProcess, TerminateProcess},
- winnt::{PROCESS_QUERY_INFORMATION, PROCESS_TERMINATE},
- },
-};
-
-/// This file is meant to house (OS specific) implementations on how to kill processes.
-#[cfg(target_family = "unix")]
-use crate::utils::error::BottomError;
-use crate::Pid;
+//! This file is meant to house (OS specific) implementations on how to kill processes.
#[cfg(target_os = "windows")]
-struct Process(HANDLE);
-
-#[cfg(target_os = "windows")]
-impl Process {
- fn open(pid: DWORD) -> Result<Process, String> {
- let pc = unsafe { OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_TERMINATE, 0, pid) };
- if pc.is_null() {
- return Err("OpenProcess".to_string());
- }
- Ok(Process(pc))
- }
-
- fn kill(self) -> Result<(), String> {
- let result = unsafe { TerminateProcess(self.0, 1) };
- if result == 0 {
- return Err("Failed to kill process".to_string());
- }
+pub(crate) mod windows;
- Ok(())
- }
-}
-
-/// Kills a process, given a PID, for unix.
#[cfg(target_family = "unix")]
-pub fn kill_process_given_pid(pid: Pid, signal: usize) -> crate::utils::error::Result<()> {
- let output = unsafe { libc::kill(pid as i32, signal as i32) };
- if output != 0 {
- // We had an error...
- let err_code = std::io::Error::last_os_error().raw_os_error();
- let err = match err_code {
- Some(libc::ESRCH) => "the target process did not exist.",
- Some(libc::EPERM) => "the calling process does not have the permissions to terminate the target process(es).",
- Some(libc::EINVAL) => "an invalid signal was specified.",
- _ => "Unknown error occurred."
- };
-
- return if let Some(err_code) = err_code {
- Err(BottomError::GenericError(format!(
- "Error code {} - {}",
- err_code, err,
- )))
- } else {
- Err(BottomError::GenericError(format!(
- "Error code ??? - {}",
- err,
- )))
- };
- }
-
- Ok(())
-}
-
-/// Kills a process, given a PID, for windows.
-#[cfg(target_os = "windows")]
-pub fn kill_process_given_pid(pid: Pid) -> crate::utils::error::Result<()> {
- {
- let process = Process::open(pid as DWORD)?;
- process.kill()?;
- }
-
- Ok(())
-}
+pub(crate) mod unix;
diff --git a/src/app/process_killer/unix.rs b/src/app/process_killer/unix.rs
new file mode 100644
index 00000000..46b4b42e
--- /dev/null
+++ b/src/app/process_killer/unix.rs
@@ -0,0 +1,31 @@
+use crate::utils::error::BottomError;
+use crate::Pid;
+
+/// Kills a process, given a PID, for unix.
+pub(crate) fn kill_process_given_pid(pid: Pid, signal: usize) -> crate::utils::error::Result<()> {
+ let output = unsafe { libc::kill(pid as i32, signal as i32) };
+ if output != 0 {
+ // We had an error...
+ let err_code = std::io::Error::last_os_error().raw_os_error();
+ let err = match err_code {
+ Some(libc::ESRCH) => "the target process did not exist.",
+ Some(libc::EPERM) => "the calling process does not have the permissions to terminate the target process(es).",
+ Some(libc::EINVAL) => "an invalid signal was specified.",
+ _ => "Unknown error occurred."
+ };
+
+ return if let Some(err_code) = err_code {
+ Err(BottomError::GenericError(format!(
+ "Error code {} - {}",
+ err_code, err,
+ )))
+ } else {
+ Err(BottomError::GenericError(format!(
+ "Error code ??? - {}",
+ err,
+ )))
+ };
+ }
+
+ Ok(())
+}
diff --git a/src/app/process_killer/windows.rs b/src/app/process_killer/windows.rs
new file mode 100644
index 00000000..84a25a72
--- /dev/null
+++ b/src/app/process_killer/windows.rs
@@ -0,0 +1,40 @@
+// Copied from SO: https://stackoverflow.com/a/55231715
+use winapi::{
+ shared::{minwindef::DWORD, ntdef::HANDLE},
+ um::{
+ processthreadsapi::{OpenProcess, TerminateProcess},
+ winnt::{PROCESS_QUERY_INFORMATION, PROCESS_TERMINATE},
+ },
+};
+
+pub(crate) struct Process(HANDLE);
+
+impl Process {
+ pub(crate) fn open(pid: DWORD) -> Result<Process, String> {
+ let pc = unsafe { OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_TERMINATE, 0, pid) };
+ if pc.is_null() {
+ return Err("OpenProcess".to_string());
+ }
+ Ok(Process(pc))
+ }
+
+ pub(crate) fn kill(self) -> Result<(), String> {
+ let result = unsafe { TerminateProcess(self.0, 1) };
+ if result == 0 {
+ return Err("Failed to kill process".to_string());
+ }
+
+ Ok(())
+ }
+}
+
+/// Kills a process, given a PID, for windows.
+#[cfg(target_os = "windows")]
+pub fn kill_process_given_pid(pid: Pid) -> crate::utils::error::Result<()> {
+ {
+ let process = Process::open(pid as DWORD)?;
+ process.kill()?;
+ }
+
+ Ok(())
+}
diff --git a/src/app/widgets.rs b/src/app/widgets.rs
index 7ef2f4dd..dd76f411 100644
--- a/src/app/widgets.rs
+++ b/src/app/widgets.rs
@@ -138,11 +138,6 @@ pub trait Widget {
/// Returns the desired height from the [`Widget`].
fn height(&self) -> LayoutRule;
- /// Returns whether this [`Widget`] can be expanded. The default implementation returns `true`.
- fn expandable(&self) -> bool {
- true
- }
-
/// Returns whether this [`Widget`] can be selected. The default implementation returns [`SelectableType::Selectable`].
fn selectable_type(&self) -> SelectableType {
SelectableType::Selectable
diff --git a/src/app/widgets/base/sort_menu.rs b/src/app/widgets/base/sort_menu.rs
index 548bbf77..1da9b697 100644
--- a/src/app/widgets/base/sort_menu.rs
+++ b/src/app/widgets/base/sort_menu.rs
@@ -33,6 +33,11 @@ impl SortMenu {
}
}
+ pub fn try_show_gap(mut self, show_gap: bool) -> Self {
+ self.table = self.table.try_show_gap(show_gap);
+ self
+ }
+
/// Updates the index of the [`SortMenu`].
pub fn set_index(&mut self, index: usize) {
self.table.scrollable.set_index(index);
diff --git a/src/app/widgets/base/sort_text_table.rs b/src/app/widgets/base/sort_text_table.rs
index c8ff4d41..2c2d9e21 100644
--- a/src/app/widgets/base/sort_text_table.rs
+++ b/src/app/widgets/base/sort_text_table.rs
@@ -274,8 +274,8 @@ where
st
}
- pub fn default_ltr(mut self, ltr: bool) -> Self {
- self.table = self.table.default_ltr(ltr);
+ pub fn try_show_gap(mut self, show_gap: bool) -> Self {
+ self.table = self.table.try_show_gap(show_gap);
self
}
diff --git a/src/app/widgets/base/text_table.rs b/src/app/widgets/base/text_table.rs
index e8281b78..d3c9c601 100644
--- a/src/app/widgets/base/text_table.rs
+++ b/src/app/widgets/base/text_table.rs
@@ -399,7 +399,10 @@ where
f.render_widget(block, block_area);
return;
}
- let table_gap = if !self.show_gap || inner_area.height < TABLE_GAP_HEIGHT_LIMIT {
+ let table_gap = if !self.show_gap
+ || (data.len() + 2 > inner_area.height.into()
+ && inner_area.height < TABLE_GAP_HEIGHT_LIMIT)
+ {
0
} else {
1
diff --git a/src/app/widgets/bottom_widgets/battery.rs b/src/app/widgets/bottom_widgets/battery.rs
index 1f9b1a88..3f76ddfc 100644
--- a/src/app/widgets/bottom_widgets/battery.rs
+++ b/src/app/widgets/bottom_widgets/battery.rs
@@ -185,6 +185,7 @@ impl Widget for BatteryTable {
split_area[0].width,
split_area[0].height,
);
+ // FIXME: [URGENT] See if this should be changed; TABLE_GAP_HEIGHT_LIMIT should be removed maybe. May also need to grab the table gap from the config?
let data_area =
if inner_area.height >= TABLE_GAP_HEIGHT_LIMIT && split_area[1].height > 0 {
Rect::new(
diff --git a/src/app/widgets/bottom_widgets/cpu.rs b/src/app/widgets/bottom_widgets/cpu.rs
index d82f8500..1a312aac 100644
--- a/src/app/widgets/bottom_widgets/cpu.rs
+++ b/src/app/widgets/bottom_widgets/cpu.rs
@@ -56,7 +56,8 @@ impl CpuGraph {
SimpleColumn::new_flex("CPU".into(), 0.5),
SimpleColumn::new_hard("Use".into(), None),
])
- .default_ltr(false);
+ .default_ltr(false)
+ .try_show_gap(app_config_fields.table_gap);
let legend_position = if app_config_fields.left_legend {
CpuGraphLegendPosition::Left
} else {
diff --git a/src/app/widgets/bottom_widgets/disk.rs b/src/app/widgets/bottom_widgets/disk.rs
index c3ec8bcd..e23b2f4b 100644
--- a/src/app/widgets/bottom_widgets/disk.rs
+++ b/src/app/widgets/bottom_widgets/disk.rs
@@ -4,8 +4,8 @@ use tui::{backend::Backend, layout::Rect, widgets::Borders, Frame};
use crate::{
app::{
data_farmer::DataCollection, event::ComponentEventResult,
- sort_text_table::SimpleSortableColumn, text_table::TextTableData, Component, TextTable,
- Widget,
+ sort_text_table::SimpleSortableColumn, text_table::TextTableData, AppConfigFields,
+ Component, TextTable, Widget,
},
canvas::Painter,
data_conversion::convert_disk_row,
@@ -25,8 +25,9 @@ pub struct DiskTable {
show_scroll_index: bool,
}
-impl Default for DiskTable {
- fn default() -> Self {
+impl DiskTable {
+ /// Creates a [`DiskTable`] from a config.
+ pub fn from_config(app_config_fields: &AppConfigFields) -> Self {
let table = TextTable::new(vec![
SimpleSortableColumn::new_flex("Disk".into(), None, false, 0.2),
SimpleSortableColumn::new_flex("Mount".into(), None, false, 0.2),
@@ -35,7 +36,8 @@ impl Default for DiskTable {
SimpleSortableColumn::new_hard("Total".into(), None, false, Some(6)),
SimpleSortableColumn::new_hard("R/s".into(), None, false, Some(7)),
SimpleSortableColumn::new_hard("W/s".into(), None, false, Some(7)),
- ]);
+ ])
+ .try_show_gap(app_config_fields.table_gap);
Self {
table,
@@ -47,9 +49,7 @@ impl Default for DiskTable {
show_scroll_index: false,
}
}
-}
-impl DiskTable {
/// Sets the width.
pub fn width(mut self, width: LayoutRule) -> Self {
self.width = width;
diff --git a/src/app/widgets/bottom_widgets/net.rs b/src/app/widgets/bottom_widgets/net.rs
index 4be88045..1f13380d 100644
--- a/src/app/widgets/bottom_widgets/net.rs
+++ b/src/app/widgets/bottom_widgets/net.rs
@@ -599,6 +599,7 @@ impl OldNetGraph {
SimpleColumn::new_flex("Total RX".into(), 0.25),
SimpleColumn::new_flex("Total TX".into(), 0.25),
])
+ .try_show_gap(config.table_gap)
.unselectable(),
bounds: Rect::default(),
width: LayoutRule::default(),
@@ -646,11 +647,14 @@ impl Widget for OldNetGraph {
&mut self, painter: &Painter, f: &mut Frame<'_, B>, area: Rect, selected: bool,
expanded: bool,
) {
- const CONSTRAINTS: [Constraint; 2] = [Constraint::Min(0), Constraint::Length(4)];
+ let constraints = [
+ Constraint::Min(0),
+ Constraint::Length(if self.table.show_gap { 5 } else { 4 }),
+ ];
let split_area = Layout::default()
.direction(Direction::Vertical)
- .constraints(CONSTRAINTS)
+ .constraints(constraints)
.split(area);
let graph_area = split_area[0];
diff --git a/src/app/widgets/bottom_widgets/process.rs b/src/app/widgets/bottom_widgets/process.rs
index 074370b3..8ca3a02e 100644
--- a/src/app/widgets/bottom_widgets/process.rs
+++ b/src/app/widgets/bottom_widgets/process.rs
@@ -20,7 +20,7 @@ use crate::{
query::*,
text_table::DesiredColumnWidth,
widgets::tui_stuff::BlockBuilder,
- DataCollection,
+ AppConfigFields, DataCollection,
},
canvas::Painter,
data_conversion::get_string_with_bytes,
@@ -273,7 +273,7 @@ pub struct ProcessManager {
impl ProcessManager {
/// Creates a new [`ProcessManager`].
- pub fn new(process_defaults: &ProcessDefaults) -> Self {
+ pub fn new(process_defaults: &ProcessDefaults, config: &AppConfigFields) -> Self {
let process_table_colum