diff options
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | src/app/data_harvester.rs | 17 | ||||
-rw-r--r-- | src/app/data_harvester/disks.rs | 4 | ||||
-rw-r--r-- | src/app/data_harvester/disks/freebsd.rs | 9 | ||||
-rw-r--r-- | src/app/data_harvester/disks/other.rs | 53 | ||||
-rw-r--r-- | src/app/data_harvester/disks/unix.rs | 8 | ||||
-rw-r--r-- | src/app/data_harvester/disks/windows.rs | 19 | ||||
-rw-r--r-- | src/canvas/dialogs/dd_dialog.rs | 300 |
8 files changed, 228 insertions, 186 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bd69ba8..c481da45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#1172](https://github.com/ClementTsang/bottom/pull/1172): Support human times for `time_delta` and `default_time_value`. - [#1187](https://github.com/ClementTsang/bottom/pull/1187): Use better names for duplicate temp sensors found by `/sys/class/thermal`. +## Other + +- [#1199](https://github.com/ClementTsang/bottom/pull/1199): bottom should build on `aarch64-linux-android` with features disabled. + ## [0.9.1] - 2023-05-14 ## Bug Fixes diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs index 0ea6e3e9..17ca95e4 100644 --- a/src/app/data_harvester.rs +++ b/src/app/data_harvester.rs @@ -407,22 +407,7 @@ impl DataCollector { #[inline] fn update_disks(&mut self) { if self.widgets_to_harvest.use_disk { - #[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "macos"))] - { - let disk_filter = &self.filters.disk_filter; - let mount_filter = &self.filters.mount_filter; - self.data.disks = disks::get_disk_usage(disk_filter, mount_filter).ok(); - } - - #[cfg(target_os = "windows")] - { - self.data.disks = Some(disks::get_disk_usage( - &self.sys, - &self.filters.disk_filter, - &self.filters.mount_filter, - )); - } - + self.data.disks = disks::get_disk_usage(self).ok(); self.data.io = disks::get_io_usage().ok(); } } diff --git a/src/app/data_harvester/disks.rs b/src/app/data_harvester/disks.rs index 6f98d3f2..ddb07073 100644 --- a/src/app/data_harvester/disks.rs +++ b/src/app/data_harvester/disks.rs @@ -18,8 +18,10 @@ cfg_if! { } else if #[cfg(target_os = "macos")] { mod unix; pub(crate) use self::unix::*; + } else { + mod other; + pub(crate) use self::other::*; } - // TODO: Add dummy impls here for other OSes? } #[derive(Debug, Clone, Default)] diff --git a/src/app/data_harvester/disks/freebsd.rs b/src/app/data_harvester/disks/freebsd.rs index 5755fc75..aa127ef6 100644 --- a/src/app/data_harvester/disks/freebsd.rs +++ b/src/app/data_harvester/disks/freebsd.rs @@ -5,7 +5,8 @@ use std::io; use serde::Deserialize; use super::{keep_disk_entry, DiskHarvest, IoHarvest}; -use crate::{app::Filter, data_harvester::deserialize_xo, utils::error}; + +use crate::{app::data_harvester::DataCollector, data_harvester::deserialize_xo, utils::error}; #[derive(Deserialize, Debug, Default)] #[serde(rename_all = "kebab-case")] @@ -35,9 +36,9 @@ pub fn get_io_usage() -> error::Result<IoHarvest> { Ok(io_harvest) } -pub fn get_disk_usage( - disk_filter: &Option<Filter>, mount_filter: &Option<Filter>, -) -> error::Result<Vec<DiskHarvest>> { +pub fn get_disk_usage(collector: &DataCollector) -> error::Result<Vec<DiskHarvest>> { + let disk_filter = &collector.filters.disk_filter; + let mount_filter = &collector.filters.mount_filter; let vec_disks: Vec<DiskHarvest> = get_disk_info().map(|storage_system_information| { storage_system_information .filesystem diff --git a/src/app/data_harvester/disks/other.rs b/src/app/data_harvester/disks/other.rs new file mode 100644 index 00000000..2cd1e2e3 --- /dev/null +++ b/src/app/data_harvester/disks/other.rs @@ -0,0 +1,53 @@ +//! Fallback disk info using sysinfo. + +use sysinfo::{DiskExt, System, SystemExt}; + +use crate::app::data_harvester::DataCollector; + +use super::{keep_disk_entry, DiskHarvest}; + +pub(crate) fn get_disk_usage(collector: &DataCollector) -> anyhow::Result<Vec<DiskHarvest>> { + let disks = collector.sys.disks(); + let disk_filter = &collector.filters.disk_filter; + let mount_filter = &collector.filters.mount_filter; + + Ok(disks + .iter() + .filter_map(|disk| { + let name = { + let name = disk.name(); + + if name.is_empty() { + "No Name".to_string() + } else { + name.to_os_string() + .into_string() + .unwrap_or_else(|_| "Name Unavailable".to_string()) + } + }; + + let mount_point = disk + .mount_point() + .as_os_str() + .to_os_string() + .into_string() + .unwrap_or_else(|_| "Mount Unavailable".to_string()); + + if keep_disk_entry(&name, &mount_point, disk_filter, mount_filter) { + let free_space = disk.available_space(); + let total_space = disk.total_space(); + let used_space = total_space - free_space; + + Some(DiskHarvest { + name, + mount_point, + free_space: Some(free_space), + used_space: Some(used_space), + total_space: Some(total_space), + }) + } else { + None + } + }) + .collect()) +} diff --git a/src/app/data_harvester/disks/unix.rs b/src/app/data_harvester/disks/unix.rs index 93668b7c..e8ebaeeb 100644 --- a/src/app/data_harvester/disks/unix.rs +++ b/src/app/data_harvester/disks/unix.rs @@ -25,12 +25,12 @@ cfg_if::cfg_if! { } use super::{keep_disk_entry, DiskHarvest}; -use crate::app::Filter; +use crate::app::data_harvester::DataCollector; /// Returns the disk usage of the mounted (and for now, physical) disks. -pub fn get_disk_usage( - disk_filter: &Option<Filter>, mount_filter: &Option<Filter>, -) -> anyhow::Result<Vec<DiskHarvest>> { +pub fn get_disk_usage(collector: &DataCollector) -> anyhow::Result<Vec<DiskHarvest>> { + let disk_filter = &collector.filters.disk_filter; + let mount_filter = &collector.filters.mount_filter; let mut vec_disks: Vec<DiskHarvest> = Vec::new(); for partition in physical_partitions()? { diff --git a/src/app/data_harvester/disks/windows.rs b/src/app/data_harvester/disks/windows.rs index b5708494..2dfd59dc 100644 --- a/src/app/data_harvester/disks/windows.rs +++ b/src/app/data_harvester/disks/windows.rs @@ -1,11 +1,11 @@ //! Disk stats via sysinfo. use itertools::Itertools; -use sysinfo::{DiskExt, System, SystemExt}; +use sysinfo::{DiskExt, SystemExt}; use super::{keep_disk_entry, DiskHarvest}; -use crate::app::data_harvester::disks::IoCounters; -use crate::app::filter::Filter; + +use crate::app::data_harvester::{disks::IoCounters, DataCollector}; mod bindings; use bindings::*; @@ -26,11 +26,12 @@ pub(crate) fn io_stats() -> anyhow::Result<Vec<anyhow::Result<IoCounters>>> { .collect::<Vec<_>>()) } -pub(crate) fn get_disk_usage( - sys: &System, disk_filter: &Option<Filter>, mount_filter: &Option<Filter>, -) -> Vec<DiskHarvest> { - let disks = sys.disks(); - disks +pub(crate) fn get_disk_usage(collector: &DataCollector) -> anyhow::Result<Vec<DiskHarvest>> { + let disks = collector.sys.disks(); + let disk_filter = &collector.filters.disk_filter; + let mount_filter = &collector.filters.mount_filter; + + Ok(disks .iter() .filter_map(|disk| { let name = { @@ -71,5 +72,5 @@ pub(crate) fn get_disk_usage( None } }) - .collect() + .collect()) } diff --git a/src/canvas/dialogs/dd_dialog.rs b/src/canvas/dialogs/dd_dialog.rs index 2ad5cf3e..e67faae7 100644 --- a/src/canvas/dialogs/dd_dialog.rs +++ b/src/canvas/dialogs/dd_dialog.rs @@ -1,4 +1,4 @@ -#[cfg(target_family = "unix")] +#[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "macos"))] use std::cmp::min; use tui::{ @@ -18,6 +18,148 @@ use crate::{ const DD_BASE: &str = " Confirm Kill Process ── Esc to close "; const DD_ERROR_BASE: &str = " Error ── Esc to close "; +cfg_if::cfg_if! { + if #[cfg(target_os = "linux")] { + const SIGNAL_TEXT: [&str; 63] = [ + "0: Cancel", + "1: HUP", + "2: INT", + "3: QUIT", + "4: ILL", + "5: TRAP", + "6: ABRT", + "7: BUS", + "8: FPE", + "9: KILL", + "10: USR1", + "11: SEGV", + "12: USR2", + "13: PIPE", + "14: ALRM", + "15: TERM", + "16: STKFLT", + "17: CHLD", + "18: CONT", + "19: STOP", + "20: TSTP", + "21: TTIN", + "22: TTOU", + "23: URG", + "24: XCPU", + "25: XFSZ", + "26: VTALRM", + "27: PROF", + "28: WINCH", + "29: IO", + "30: PWR", + "31: SYS", + "34: RTMIN", + "35: RTMIN+1", + "36: RTMIN+2", + "37: RTMIN+3", + "38: RTMIN+4", + "39: RTMIN+5", + "40: RTMIN+6", + "41: RTMIN+7", + "42: RTMIN+8", + "43: RTMIN+9", + "44: RTMIN+10", + "45: RTMIN+11", + "46: RTMIN+12", + "47: RTMIN+13", + "48: RTMIN+14", + "49: RTMIN+15", + "50: RTMAX-14", + "51: RTMAX-13", + "52: RTMAX-12", + "53: RTMAX-11", + "54: RTMAX-10", + "55: RTMAX-9", + "56: RTMAX-8", + "57: RTMAX-7", + "58: RTMAX-6", + "59: RTMAX-5", + "60: RTMAX-4", + "61: RTMAX-3", + "62: RTMAX-2", + "63: RTMAX-1", + "64: RTMAX", + ]; + } else if #[cfg(target_os = "macos")] { + const SIGNAL_TEXT: [&str; 32] = [ + "0: Cancel", + "1: HUP", + "2: INT", + "3: QUIT", + "4: ILL", + "5: TRAP", + "6: ABRT", + "7: EMT", + "8: FPE", + "9: KILL", + "10: BUS", + "11: SEGV", + "12: SYS", + "13: PIPE", + "14: ALRM", + "15: TERM", + "16: URG", + "17: STOP", + "18: TSTP", + "19: CONT", + "20: CHLD", + "21: TTIN", + "22: TTOU", + "23: IO", + "24: XCPU", + "25: XFSZ", + "26: VTALRM", + "27: PROF", + "28: WINCH", + "29: INFO", + "30: USR1", + "31: USR2", + ]; + } else if #[cfg(target_os = "freebsd")] { + const SIGNAL_TEXT: [&str; 34] = [ + "0: Cancel", + "1: HUP", + "2: INT", + "3: QUIT", + "4: ILL", + "5: TRAP", + "6: ABRT", + "7: EMT", + "8: FPE", + "9: KILL", + "10: BUS", + "11: SEGV", + "12: SYS", + "13: PIPE", + "14: ALRM", + "15: TERM", + "16: URG", + "17: STOP", + "18: TSTP", + "19: CONT", + "20: CHLD", + "21: TTIN", + "22: TTOU", + "23: IO", + "24: XCPU", + "25: XFSZ", + "26: VTALRM", + "27: PROF", + "28: WINCH", + "29: INFO", + "30: USR1", + "31: USR2", + "32: THR", + "33: LIBRT", + ]; + } +} + impl Painter { pub fn get_dd_spans(&self, app_state: &App) -> Option<Text<'_>> { if let Some(dd_err) = &app_state.dd_err { @@ -134,154 +276,8 @@ impl Painter { ]; } } else { - #[cfg(target_family = "unix")] + #[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "macos"))] { - let signal_text: Vec<&str>; - #[cfg(target_os = "linux")] - { - signal_text = vec![ - "0: Cancel", - "1: HUP", - "2: INT", - "3: QUIT", - "4: ILL", - "5: TRAP", - "6: ABRT", - "7: BUS", - "8: FPE", - "9: KILL", - "10: USR1", - "11: SEGV", - "12: USR2", - "13: PIPE", - "14: ALRM", - "15: TERM", - "16: STKFLT", - "17: CHLD", - "18: CONT", - "19: STOP", - "20: TSTP", - "21: TTIN", - "22: TTOU", - "23: URG", - "24: XCPU", - "25: XFSZ", - "26: VTALRM", - "27: PROF", - "28: WINCH", - "29: IO", - "30: PWR", - "31: SYS", - "34: RTMIN", - "35: RTMIN+1", - "36: RTMIN+2", - "37: RTMIN+3", - "38: RTMIN+4", - "39: RTMIN+5", - "40: RTMIN+6", - "41: RTMIN+7", - "42: RTMIN+8", - "43: RTMIN+9", - "44: RTMIN+10", - "45: RTMIN+11", - "46: RTMIN+12", - "47: RTMIN+13", - "48: RTMIN+14", - "49: RTMIN+15", - "50: RTMAX-14", - "51: RTMAX-13", - "52: RTMAX-12", - "53: RTMAX-11", - "54: RTMAX-10", - "55: RTMAX-9", - "56: RTMAX-8", - "57: RTMAX-7", - "58: RTMAX-6", - "59: RTMAX-5", - "60: RTMAX-4", - "61: RTMAX-3", - "62: RTMAX-2", - "63: RTMAX-1", - "64: RTMAX", - ]; - } - #[cfg(target_os = "macos")] - { - signal_text = vec![ - "0: Cancel", - "1: HUP", - "2: INT", - "3: QUIT", - "4: ILL", - "5: TRAP", - "6: ABRT", - "7: EMT", - "8: FPE", - "9: KILL", - "10: BUS", - "11: SEGV", - "12: SYS", - "13: PIPE", - "14: ALRM", - "15: TERM", - "16: URG", - "17: STOP", - "18: TSTP", - "19: CONT", - "20: CHLD", - "21: TTIN", - "22: TTOU", - "23: IO", - "24: XCPU", - "25: XFSZ", - "26: VTALRM", - "27: PROF", - "28: WINCH", - "29: INFO", - "30: USR1", - "31: USR2", - ]; - } - #[cfg(target_os = "freebsd")] - { - signal_text = vec![ - "0: Cancel", - "1: HUP", - "2: INT", - "3: QUIT", - "4: ILL", - "5: TRAP", - "6: ABRT", - "7: EMT", - "8: FPE", - "9: KILL", - "10: BUS", - "11: SEGV", - "12: SYS", - "13: PIPE", - "14: ALRM", - "15: TERM", - "16: URG", - "17: STOP", - "18: TSTP", - "19: CONT", - "20: CHLD", - "21: TTIN", - "22: TTOU", - "23: IO", - "24: XCPU", - "25: XFSZ", - "26: VTALRM", - "27: PROF", - "28: WINCH", - "29: INFO", - "30: USR1", - "31: USR2", - "32: THR", - "33: LIBRT", - ]; - } - let button_rect = Layout::default() .direction(Direction::Horizontal) .margin(1) @@ -321,14 +317,14 @@ impl Painter { }; let scroll_offset: usize = app_state.delete_dialog_state.scroll_pos; - let mut buttons = signal_text - [scroll_offset + 1..min((layout.len()) + scroll_offset, signal_text.len())] + let mut buttons = SIGNAL_TEXT + [scroll_offset + 1..min((layout.len()) + scroll_offset, SIGNAL_TEXT.len())] .iter() .map(|text| Span::styled(*text, self.colours.text_style)) .collect::<Vec<Span<'_>>>(); - buttons.insert(0, Span::styled(signal_text[0], self.colours.text_style)); + buttons.insert(0, Span::styled(SIGNAL_TEXT[0], self.colours.text_style)); buttons[selected - scroll_offset] = Span::styled( - signal_text[selected], + SIGNAL_TEXT[selected], self.colours.currently_selected_text_style, ); |