diff --git a/Cargo.toml b/Cargo.toml index 587c676f..596c91ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,17 +1,16 @@ [package] name = "bottom" version = "0.11.0" -authors = ["Clement Tsang "] -edition = "2021" repository = "https://github.com/ClementTsang/bottom" -keywords = ["cross-platform", "monitoring", "cli", "top", "tui"] license = "MIT" -categories = ["command-line-utilities", "visualization"] description = "A customizable cross-platform graphical process/system monitor for the terminal. Supports Linux, macOS, and Windows." documentation = "https://clementtsang.github.io/bottom/stable" readme = "README.md" default-run = "btm" build = "build.rs" +authors = ["Clement Tsang "] +keywords = ["cross-platform", "monitoring", "cli", "top", "tui"] +categories = ["command-line-utilities", "visualization"] exclude = [ ".cargo-husky/", ".github/", @@ -37,6 +36,7 @@ exclude = [ "rust-toolchain.toml", "rustfmt.toml", ] +edition = "2021" # The oldest version I've tested that should still build - note this is not an official MSRV! rust-version = "1.81" @@ -58,22 +58,6 @@ doctest = false doc = false required-features = ["generate_schema"] -# Compile dependencies with optimizations enabled, even in debug mode. -[profile.dev.package."*"] -opt-level = 3 - -[profile.release] -debug = 0 -strip = "symbols" -lto = true -opt-level = 3 -codegen-units = 1 - -[profile.profiling] -inherits = "release" -debug = true -strip = false - [features] # Used for general builds. battery = ["starship-battery"] @@ -166,6 +150,22 @@ clap_complete_fig = "4.5.2" clap_mangen = "0.2.24" indoc = "2.0.5" +# Compile dependencies with optimizations enabled, even in debug mode. +[profile.dev.package."*"] +opt-level = 3 + +[profile.release] +debug = 0 +strip = "symbols" +lto = true +opt-level = 3 +codegen-units = 1 + +[profile.profiling] +inherits = "release" +debug = true +strip = false + [package.metadata.deb] section = "utility" assets = [ diff --git a/build.rs b/build.rs index b13858b6..fa08efeb 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,5 @@ +//! General build script used by bottom to generate completion files and set binary version. + #[expect(dead_code)] #[path = "src/options/args.rs"] mod args; @@ -15,15 +17,13 @@ use clap_complete_nushell::Nushell; use crate::args::BottomArgs; fn create_dir(dir: &Path) -> io::Result<()> { - let res = fs::create_dir_all(dir); - match &res { - Ok(()) => {} - Err(err) => { - eprintln!("Failed to create a directory at location {dir:?}, encountered error {err:?}. Aborting...",); - } - } - - res + fs::create_dir_all(dir).inspect_err(|err| { + eprintln!( + "Couldn't create a directory at {} ({:?}). Aborting.", + dir.display(), + err + ) + }) } fn generate_completions(to_generate: G, cmd: &mut Command, out_dir: &Path) -> io::Result diff --git a/src/app.rs b/src/app.rs index 3b3b28a7..be27a673 100644 --- a/src/app.rs +++ b/src/app.rs @@ -27,7 +27,7 @@ use crate::{ data_conversion::ConvertedData, get_network_points, utils::data_units::DataUnit, - widgets::{query::ProcessQuery, ProcWidgetColumn, ProcWidgetMode}, + widgets::{ProcWidgetColumn, ProcWidgetMode}, }; #[derive(Debug, Clone, Eq, PartialEq, Default)] @@ -115,8 +115,6 @@ pub struct App { pub is_force_redraw: bool, pub is_determining_widget_boundary: bool, pub basic_mode_use_percent: bool, - #[cfg(target_family = "unix")] - pub user_table: crate::data_collection::processes::UserTable, pub states: AppWidgetStates, pub app_config_fields: AppConfigFields, pub widget_map: HashMap, @@ -147,8 +145,6 @@ impl App { is_force_redraw: false, is_determining_widget_boundary: false, basic_mode_use_percent: false, - #[cfg(target_family = "unix")] - user_table: crate::data_collection::processes::UserTable::default(), states, app_config_fields, widget_map, @@ -670,14 +666,6 @@ impl App { } } - pub fn get_process_filter(&self, widget_id: u64) -> &Option { - if let Some(process_widget_state) = self.states.proc_state.widget_states.get(&widget_id) { - &process_widget_state.proc_search.search_state.query - } else { - &None - } - } - #[cfg(target_family = "unix")] pub fn on_number(&mut self, number_char: char) { if self.delete_dialog_state.is_showing_dd { @@ -1990,7 +1978,7 @@ impl App { .proc_state .get_mut_widget_state(self.current_widget.widget_id) { - proc_widget_state.table.to_first(); + proc_widget_state.table.scroll_to_first(); } } BottomWidgetType::ProcSort => { @@ -1999,7 +1987,7 @@ impl App { .proc_state .get_mut_widget_state(self.current_widget.widget_id - 2) { - proc_widget_state.sort_table.to_first(); + proc_widget_state.sort_table.scroll_to_first(); } } BottomWidgetType::Temp => { @@ -2008,7 +1996,7 @@ impl App { .temp_state .get_mut_widget_state(self.current_widget.widget_id) { - temp_widget_state.table.to_first(); + temp_widget_state.table.scroll_to_first(); } } BottomWidgetType::Disk => { @@ -2017,7 +2005,7 @@ impl App { .disk_state .get_mut_widget_state(self.current_widget.widget_id) { - disk_widget_state.table.to_first(); + disk_widget_state.table.scroll_to_first(); } } BottomWidgetType::CpuLegend => { @@ -2026,7 +2014,7 @@ impl App { .cpu_state .get_mut_widget_state(self.current_widget.widget_id - 1) { - cpu_widget_state.table.to_first(); + cpu_widget_state.table.scroll_to_first(); } } @@ -2049,7 +2037,7 @@ impl App { .proc_state .get_mut_widget_state(self.current_widget.widget_id) { - proc_widget_state.table.to_last(); + proc_widget_state.table.scroll_to_last(); } } BottomWidgetType::ProcSort => { @@ -2058,7 +2046,7 @@ impl App { .proc_state .get_mut_widget_state(self.current_widget.widget_id - 2) { - proc_widget_state.sort_table.to_last(); + proc_widget_state.sort_table.scroll_to_last(); } } BottomWidgetType::Temp => { @@ -2067,7 +2055,7 @@ impl App { .temp_state .get_mut_widget_state(self.current_widget.widget_id) { - temp_widget_state.table.to_last(); + temp_widget_state.table.scroll_to_last(); } } BottomWidgetType::Disk => { @@ -2077,7 +2065,7 @@ impl App { .get_mut_widget_state(self.current_widget.widget_id) { if !self.converted_data.disk_data.is_empty() { - disk_widget_state.table.to_last(); + disk_widget_state.table.scroll_to_last(); } } } @@ -2087,7 +2075,7 @@ impl App { .cpu_state .get_mut_widget_state(self.current_widget.widget_id - 1) { - cpu_widget_state.table.to_last(); + cpu_widget_state.table.scroll_to_last(); } } _ => {} diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs index 0265aeb7..af75d1de 100644 --- a/src/app/data_farmer.rs +++ b/src/app/data_farmer.rs @@ -28,7 +28,6 @@ use crate::{ dec_bytes_per_second_string, }; -pub type TimeOffset = f64; pub type Value = f64; #[derive(Debug, Default, Clone)] diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs index 012bab40..6465b84e 100644 --- a/src/app/layout_manager.rs +++ b/src/app/layout_manager.rs @@ -745,11 +745,6 @@ impl BottomRow { self.constraint = IntermediaryConstraint::CanvasHandled { ratio: None }; self } - - pub fn grow(mut self, minimum: Option) -> Self { - self.constraint = IntermediaryConstraint::Grow { minimum }; - self - } } /// Represents a single column in the layout. We assume that even if the column @@ -785,11 +780,6 @@ impl BottomCol { self.constraint = IntermediaryConstraint::CanvasHandled { ratio: None }; self } - - pub fn grow(mut self, minimum: Option) -> Self { - self.constraint = IntermediaryConstraint::Grow { minimum }; - self - } } #[derive(Clone, Default, Debug)] diff --git a/src/app/states.rs b/src/app/states.rs index 433d3b0a..821bf472 100644 --- a/src/app/states.rs +++ b/src/app/states.rs @@ -296,14 +296,6 @@ impl NetState { 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) - } } pub struct CpuState { @@ -340,14 +332,6 @@ impl MemState { 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) - } } pub struct TempState { @@ -391,7 +375,6 @@ pub struct BasicTableWidgetState { // 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)>, @@ -410,10 +393,6 @@ impl BatteryState { 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) - } } #[derive(Default)] diff --git a/src/canvas/components/data_table.rs b/src/canvas/components/data_table.rs index f517de77..55590c65 100644 --- a/src/canvas/components/data_table.rs +++ b/src/canvas/components/data_table.rs @@ -69,13 +69,13 @@ impl, H: ColumnHeader, S: SortType, C: DataTableColumn>()); - table.to_last(); + table.scroll_to_last(); assert_eq!(table.current_index(), 4); assert_eq!(table.state.scroll_direction, ScrollDirection::Down); - table.to_first(); + table.scroll_to_first(); assert_eq!(table.current_index(), 0); assert_eq!(table.state.scroll_direction, ScrollDirection::Up); diff --git a/src/canvas/components/data_table/column.rs b/src/canvas/components/data_table/column.rs index 556fbbbd..8e547d80 100644 --- a/src/canvas/components/data_table/column.rs +++ b/src/canvas/components/data_table/column.rs @@ -62,8 +62,6 @@ pub trait DataTableColumn { fn is_hidden(&self) -> bool; - fn set_is_hidden(&mut self, is_hidden: bool); - /// The actually displayed "header". fn header(&self) -> Cow<'static, str>; @@ -114,25 +112,12 @@ impl DataTableColumn for Column { self.is_hidden } - #[inline] - fn set_is_hidden(&mut self, is_hidden: bool) { - self.is_hidden = is_hidden; - } - fn header(&self) -> Cow<'static, str> { self.inner.text() } } impl Column { - pub const fn new(inner: H) -> Self { - Self { - inner, - bounds: ColumnWidthBounds::FollowHeader, - is_hidden: false, - } - } - pub const fn hard(inner: H, width: u16) -> Self { Self { inner, diff --git a/src/canvas/components/data_table/sortable.rs b/src/canvas/components/data_table/sortable.rs index 67a07929..c3ef4f49 100644 --- a/src/canvas/components/data_table/sortable.rs +++ b/src/canvas/components/data_table/sortable.rs @@ -168,11 +168,6 @@ where self.is_hidden } - #[inline] - fn set_is_hidden(&mut self, is_hidden: bool) { - self.is_hidden = is_hidden; - } - fn header(&self) -> Cow<'static, str> { self.inner.header() } @@ -223,12 +218,6 @@ where } } - /// Sets the default sort order to [`SortOrder::Ascending`]. - pub fn default_ascending(mut self) -> Self { - self.default_order = SortOrder::Ascending; - self - } - /// Sets the default sort order to [`SortOrder::Descending`]. pub const fn default_descending(mut self) -> Self { self.default_order = SortOrder::Descending; diff --git a/src/canvas/components/tui_widget/pipe_gauge.rs b/src/canvas/components/tui_widget/pipe_gauge.rs index c8aca6f5..fb365c48 100644 --- a/src/canvas/components/tui_widget/pipe_gauge.rs +++ b/src/canvas/components/tui_widget/pipe_gauge.rs @@ -9,6 +9,7 @@ use tui::{ #[derive(Debug, Clone, Copy)] pub enum LabelLimit { None, + #[expect(dead_code)] Auto(u16), Bars, StartLabel, diff --git a/src/canvas/components/tui_widget/time_chart.rs b/src/canvas/components/tui_widget/time_chart.rs index a6b138d9..787d1393 100644 --- a/src/canvas/components/tui_widget/time_chart.rs +++ b/src/canvas/components/tui_widget/time_chart.rs @@ -51,6 +51,7 @@ impl<'a> Axis<'a> { /// This is a fluent setter method which must be chained or used as it /// consumes self #[must_use = "method moves the value of self and returns the modified value"] + #[cfg_attr(not(test), expect(dead_code))] pub fn title(mut self, title: T) -> Axis<'a> where T: Into>, @@ -96,6 +97,7 @@ impl<'a> Axis<'a> { /// /// On the X axis, this parameter only affects the first label. #[must_use = "method moves the value of self and returns the modified value"] + #[expect(dead_code)] pub fn labels_alignment(mut self, alignment: Alignment) -> Axis<'a> { self.labels_alignment = alignment; self @@ -299,6 +301,7 @@ impl<'a> Dataset<'a> { /// This is a fluent setter method which must be chained or used as it /// consumes self #[must_use = "method moves the value of self and returns the modified value"] + #[expect(dead_code)] pub fn marker(mut self, marker: symbols::Marker) -> Dataset<'a> { self.marker = marker; self diff --git a/src/constants.rs b/src/constants.rs index ad3c6ef8..fba9869f 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -9,7 +9,6 @@ pub const STALE_MIN_MILLISECONDS: u64 = 30 * 1000; // Lowest is 30 seconds pub const TIME_CHANGE_MILLISECONDS: u64 = 15 * 1000; // How much to increment each time pub const AUTOHIDE_TIMEOUT_MILLISECONDS: u64 = 5000; // 5 seconds to autohide -pub const TICK_RATE_IN_MILLISECONDS: u64 = 200; // How fast the screen refreshes pub const DEFAULT_REFRESH_RATE_IN_MILLISECONDS: u64 = 1000; pub const MAX_KEY_TIMEOUT_IN_MILLISECONDS: u64 = 1000; diff --git a/src/data_collection/cpu.rs b/src/data_collection/cpu.rs index 843df161..5aae7e46 100644 --- a/src/data_collection/cpu.rs +++ b/src/data_collection/cpu.rs @@ -18,6 +18,3 @@ pub struct CpuData { } pub type CpuHarvest = Vec; - -pub type PastCpuWork = f64; -pub type PastCpuTotal = f64; diff --git a/src/data_collection/cpu/sysinfo.rs b/src/data_collection/cpu/sysinfo.rs index 72a8a558..fd7ff8e1 100644 --- a/src/data_collection/cpu/sysinfo.rs +++ b/src/data_collection/cpu/sysinfo.rs @@ -3,10 +3,10 @@ use std::collections::VecDeque; -use sysinfo::{LoadAvg, System}; +use sysinfo::System; use super::{CpuData, CpuDataType, CpuHarvest}; -use crate::data_collection::{cpu::LoadAvgHarvest, error::CollectionResult}; +use crate::data_collection::error::CollectionResult; pub fn get_cpu_data_list(sys: &System, show_average_cpu: bool) -> CollectionResult { let mut cpu_deque: VecDeque<_> = sys @@ -31,10 +31,11 @@ pub fn get_cpu_data_list(sys: &System, show_average_cpu: bool) -> CollectionResu Ok(Vec::from(cpu_deque)) } -pub fn get_load_avg() -> LoadAvgHarvest { +#[cfg(target_family = "unix")] +pub(crate) fn get_load_avg() -> crate::data_collection::cpu::LoadAvgHarvest { // The API for sysinfo apparently wants you to call it like this, rather than // using a &System. - let LoadAvg { one, five, fifteen } = sysinfo::System::load_average(); + let sysinfo::LoadAvg { one, five, fifteen } = sysinfo::System::load_average(); [one as f32, five as f32, fifteen as f32] } diff --git a/src/data_collection/error.rs b/src/data_collection/error.rs index dc5dd7bd..11eac63d 100644 --- a/src/data_collection/error.rs +++ b/src/data_collection/error.rs @@ -7,6 +7,10 @@ pub enum CollectionError { General(anyhow::Error), /// The collection is unsupported. + #[allow( + dead_code, + reason = "this is not used if everything is supported for the platform" + )] Unsupported, } diff --git a/src/data_collection/processes.rs b/src/data_collection/processes.rs index 319c16e1..9b8cdc2d 100644 --- a/src/data_collection/processes.rs +++ b/src/data_collection/processes.rs @@ -89,6 +89,7 @@ pub struct ProcessHarvest { /// This is the *effective* user ID of the process. This is only used on /// Unix platforms. #[cfg(target_family = "unix")] + #[allow(dead_code)] pub uid: Option, /// This is the process' user. diff --git a/src/data_conversion.rs b/src/data_conversion.rs index acb65107..2d769220 100644 --- a/src/data_conversion.rs +++ b/src/data_conversion.rs @@ -484,18 +484,6 @@ pub fn binary_byte_string(value: u64) -> String { } } -/// Returns a string given a value that is converted to the closest SI-variant. -/// If the value is greater than a giga-X, then it will return a decimal place. -#[inline] -pub fn dec_bytes_per_string(value: u64) -> String { - let converted_values = get_decimal_bytes(value); - if value >= GIGA_LIMIT { - format!("{:.1}{}", converted_values.0, converted_values.1) - } else { - format!("{:.0}{}", converted_values.0, converted_values.1) - } -} - /// Returns a string given a value that is converted to the closest SI-variant, /// per second. If the value is greater than a giga-X, then it will return a /// decimal place. diff --git a/src/lib.rs b/src/lib.rs index d110361a..25d05c75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,20 +7,20 @@ //! application. If you are instead looking for documentation regarding the //! *usage* of bottom, refer to [here](https://clementtsang.github.io/bottom/stable/). -pub mod app; -pub mod utils { - pub mod cancellation_token; - pub mod data_prefixes; - pub mod data_units; - pub mod general; - pub mod logging; - pub mod strings; +pub(crate) mod app; +mod utils { + pub(crate) mod cancellation_token; + pub(crate) mod data_prefixes; + pub(crate) mod data_units; + pub(crate) mod general; + pub(crate) mod logging; + pub(crate) mod strings; } -pub mod canvas; -pub mod constants; -pub mod data_collection; -pub mod data_conversion; -pub mod event; +pub(crate) mod canvas; +pub(crate) mod constants; +pub(crate) mod data_collection; +pub(crate) mod data_conversion; +pub(crate) mod event; pub mod options; pub mod widgets; diff --git a/src/options.rs b/src/options.rs index 8e365a4d..df6dc5b5 100644 --- a/src/options.rs +++ b/src/options.rs @@ -433,7 +433,6 @@ pub(crate) fn init_app( Proc | Disk | Temp => BasicTableWidgetState { currently_displayed_widget_type: initial_widget_type, currently_displayed_widget_id: initial_widget_id, - widget_id: 100, left_tlc: None, left_brc: None, right_tlc: None, @@ -442,7 +441,6 @@ pub(crate) fn init_app( _ => BasicTableWidgetState { currently_displayed_widget_type: Proc, currently_displayed_widget_id: DEFAULT_WIDGET_ID, - widget_id: 100, left_tlc: None, left_brc: None, right_tlc: None, diff --git a/src/options/config/style/themes/default.rs b/src/options/config/style/themes/default.rs index cea51b04..4c4a20a7 100644 --- a/src/options/config/style/themes/default.rs +++ b/src/options/config/style/themes/default.rs @@ -14,9 +14,7 @@ impl ColourPalette { const HIGHLIGHT_COLOUR: Color = Color::LightBlue; const AVG_COLOUR: Color = Color::Red; const ALL_COLOUR: Color = Color::Green; - const DEFAULT_SELECTED_TEXT_STYLE: Style = color!(Color::Black).bg(HIGHLIGHT_COLOUR); - const TEXT_COLOUR: Color = Color::Gray; Self { diff --git a/src/utils/data_prefixes.rs b/src/utils/data_prefixes.rs index fb2892c4..d523eaa8 100644 --- a/src/utils/data_prefixes.rs +++ b/src/utils/data_prefixes.rs @@ -28,16 +28,6 @@ pub const LOG_GIBI_LIMIT: f64 = 30.0; pub const LOG_TEBI_LIMIT: f64 = 40.0; pub const LOG_PEBI_LIMIT: f64 = 50.0; -pub const LOG_KILO_LIMIT_U32: u32 = 3; -pub const LOG_MEGA_LIMIT_U32: u32 = 6; -pub const LOG_GIGA_LIMIT_U32: u32 = 9; -pub const LOG_TERA_LIMIT_U32: u32 = 12; - -pub const LOG_KIBI_LIMIT_U32: u32 = 10; -pub const LOG_MEBI_LIMIT_U32: u32 = 20; -pub const LOG_GIBI_LIMIT_U32: u32 = 30; -pub const LOG_TEBI_LIMIT_U32: u32 = 40; - /// Returns a tuple containing the value and the unit in bytes. In units of /// 1024. This only supports up to a tebi. Note the "single" unit will have a /// space appended to match the others if `spacing` is true. diff --git a/src/utils/general.rs b/src/utils/general.rs index 7191f3cc..15e9c13c 100644 --- a/src/utils/general.rs +++ b/src/utils/general.rs @@ -28,6 +28,7 @@ pub fn partial_ordering_desc(a: T, b: T) -> Ordering { pub trait ClampExt { /// Restrict a value by a lower bound. If the current value is _lower_ than /// `lower_bound`, it will be set to `_lower_bound`. + #[cfg_attr(not(test), expect(dead_code))] fn clamp_lower(&self, lower_bound: Self) -> Self; /// Restrict a value by an upper bound. If the current value is _greater_ diff --git a/src/widgets.rs b/src/widgets.rs index b4f82650..21cf0479 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -13,11 +13,3 @@ pub use mem_graph::*; pub use net_graph::*; pub use process_table::*; pub use temperature_table::*; -use tui::{layout::Rect, Frame}; - -/// A [`Widget`] converts raw data into something that a user can see and -/// interact with. -pub trait Widget { - /// How to actually draw the widget to the terminal. - fn draw(&self, f: &mut Frame<'_>, draw_location: Rect, widget_id: u64); -} diff --git a/src/widgets/cpu_graph.rs b/src/widgets/cpu_graph.rs index 93df6849..1f77284c 100644 --- a/src/widgets/cpu_graph.rs +++ b/src/widgets/cpu_graph.rs @@ -1,7 +1,7 @@ use std::{borrow::Cow, num::NonZeroU16, time::Instant}; use concat_string::concat_string; -use tui::{style::Style, widgets::Row}; +use tui::widgets::Row; use crate::{ app::AppConfigFields, @@ -17,38 +17,15 @@ use crate::{ options::config::{cpu::CpuDefault, style::ColourPalette}, }; -#[derive(Default)] -pub struct CpuWidgetStyling { - pub all: Style, - pub avg: Style, - pub entries: Vec