refactor: move around configuration-related files (#1370)

* rename general utils file

* refactor: move around some configuration files

* more shuffling around

* fix some ugly formatting
This commit is contained in:
Clement Tsang 2024-01-01 22:20:40 +00:00 committed by GitHub
parent e71048e394
commit 228da99489
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 1284 additions and 1298 deletions

View File

@ -7,7 +7,7 @@ use clap_complete::{generate_to, shells::Shell, Generator};
use clap_complete_fig::Fig; use clap_complete_fig::Fig;
use clap_complete_nushell::Nushell; use clap_complete_nushell::Nushell;
include!("src/args.rs"); include!("src/options/args.rs");
fn create_dir(dir: &Path) -> io::Result<()> { fn create_dir(dir: &Path) -> io::Result<()> {
let res = fs::create_dir_all(dir); let res = fs::create_dir_all(dir);

View File

@ -1,3 +1,11 @@
pub mod data_farmer;
pub mod filter;
pub mod frozen_state;
pub mod layout_manager;
mod process_killer;
pub mod query;
pub mod states;
use std::{ use std::{
cmp::{max, min}, cmp::{max, min},
time::Instant, time::Instant,
@ -6,6 +14,7 @@ use std::{
use concat_string::concat_string; use concat_string::concat_string;
use data_farmer::*; use data_farmer::*;
use filter::*; use filter::*;
use frozen_state::FrozenState;
use hashbrown::HashMap; use hashbrown::HashMap;
use layout_manager::*; use layout_manager::*;
pub use states::*; pub use states::*;
@ -23,16 +32,6 @@ use crate::{
Pid, Pid,
}; };
pub mod data_farmer;
pub mod filter;
pub mod frozen_state;
pub mod layout_manager;
mod process_killer;
pub mod query;
pub mod states;
use frozen_state::FrozenState;
#[derive(Debug, Clone, Eq, PartialEq, Default)] #[derive(Debug, Clone, Eq, PartialEq, Default)]
pub enum AxisScaling { pub enum AxisScaling {
#[default] #[default]

View File

@ -21,7 +21,7 @@ use hashbrown::HashMap;
use crate::data_collection::batteries; use crate::data_collection::batteries;
use crate::{ use crate::{
data_collection::{cpu, disks, memory, network, processes::ProcessHarvest, temperature, Data}, data_collection::{cpu, disks, memory, network, processes::ProcessHarvest, temperature, Data},
utils::{data_prefixes::*, gen_util::get_decimal_bytes}, utils::{data_prefixes::*, general::get_decimal_bytes},
Pid, Pid,
}; };

View File

@ -7,7 +7,7 @@ use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete, UnicodeSegmentati
use crate::{ use crate::{
app::{layout_manager::BottomWidgetType, query::*}, app::{layout_manager::BottomWidgetType, query::*},
constants, constants,
utils::gen_util::str_width, utils::general::str_width,
widgets::{ widgets::{
BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState, BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState,
ProcWidgetState, TempWidgetState, ProcWidgetState, TempWidgetState,

View File

@ -15,15 +15,12 @@ use std::{
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use bottom::{ use bottom::{
args, args,
canvas::{ canvas::{self, styling::CanvasStyling},
styling::CanvasStyling,
{self},
},
check_if_terminal, cleanup_terminal, create_collection_thread, create_input_thread, check_if_terminal, cleanup_terminal, create_collection_thread, create_input_thread,
create_or_get_config, create_or_get_config,
data_conversion::*, data_conversion::*,
handle_key_event_or_break, handle_mouse_event, handle_key_event_or_break, handle_mouse_event,
options::*, options::config::{get_color_scheme, get_widget_layout, init_app},
panic_hook, read_config, try_drawing, update_data, BottomEvent, panic_hook, read_config, try_drawing, update_data, BottomEvent,
}; };
use crossterm::{ use crossterm::{
@ -73,7 +70,7 @@ fn main() -> Result<()> {
}; };
// Create an "app" struct, which will control most of the program and store settings/state // Create an "app" struct, which will control most of the program and store settings/state
let mut app = build_app( let mut app = init_app(
matches, matches,
config, config,
&widget_layout, &widget_layout,

View File

@ -1,3 +1,9 @@
mod dialogs;
mod drawing_utils;
pub mod styling;
pub mod tui_widgets;
mod widgets;
use std::str::FromStr; use std::str::FromStr;
use itertools::izip; use itertools::izip;
@ -19,12 +25,6 @@ use crate::{
utils::{error, error::BottomError}, utils::{error, error::BottomError},
}; };
mod dialogs;
mod drawing_utils;
pub mod styling;
pub mod tui_widgets;
mod widgets;
#[derive(Debug)] #[derive(Debug)]
pub enum ColourScheme { pub enum ColourScheme {
Default, Default,

View File

@ -5,7 +5,7 @@ use tui::style::{Color, Style};
use super::ColourScheme; use super::ColourScheme;
use crate::{ use crate::{
constants::*, constants::*,
options::{Config, ConfigColours}, options::config::{Config, ConfigColours},
utils::error, utils::error,
}; };
mod colour_utils; mod colour_utils;

View File

@ -1,27 +1,22 @@
pub mod column;
pub mod data_type;
pub mod draw;
pub mod props;
pub mod sortable;
pub mod state;
pub mod styling;
use std::{convert::TryInto, marker::PhantomData}; use std::{convert::TryInto, marker::PhantomData};
pub mod column;
pub use column::*; pub use column::*;
pub use data_type::*;
pub mod styling; pub use draw::*;
pub use props::DataTableProps;
pub use sortable::*;
pub use state::{DataTableState, ScrollDirection};
pub use styling::*; pub use styling::*;
pub mod props; use crate::utils::general::ClampExt;
pub use props::DataTableProps;
pub mod state;
pub use state::{DataTableState, ScrollDirection};
pub mod draw;
pub use draw::*;
pub mod data_type;
pub use data_type::*;
pub mod sortable;
pub use sortable::*;
use crate::utils::gen_util::ClampExt;
/// A [`DataTable`] is a component that displays data in a tabular form. /// A [`DataTable`] is a component that displays data in a tabular form.
/// ///

View File

@ -8,7 +8,7 @@ use super::{
ColumnHeader, ColumnWidthBounds, DataTable, DataTableColumn, DataTableProps, DataTableState, ColumnHeader, ColumnWidthBounds, DataTable, DataTableColumn, DataTableProps, DataTableState,
DataTableStyling, DataToCell, DataTableStyling, DataToCell,
}; };
use crate::utils::gen_util::truncate_to_text; use crate::utils::general::truncate_to_text;
/// Denotes the sort order. /// Denotes the sort order.
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]

View File

@ -16,7 +16,7 @@ use tui::{
}; };
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
use crate::utils::gen_util::partial_ordering; use crate::utils::general::partial_ordering;
/// A single graph point. /// A single graph point.
pub type Point = (f64, f64); pub type Point = (f64, f64);

View File

@ -1,7 +1,7 @@
use tui::{layout::Rect, terminal::Frame}; use tui::{layout::Rect, terminal::Frame};
use crate::{ use crate::{
app::{self}, app,
canvas::{ canvas::{
tui_widgets::data_table::{DrawInfo, SelectionState}, tui_widgets::data_table::{DrawInfo, SelectionState},
Painter, Painter,

View File

@ -16,7 +16,7 @@ use crate::{
}, },
Painter, Painter,
}, },
utils::{data_prefixes::*, data_units::DataUnit, gen_util::partial_ordering}, utils::{data_prefixes::*, data_units::DataUnit, general::partial_ordering},
}; };
impl Painter { impl Painter {

View File

@ -1,6 +1,6 @@
use tui::widgets::Borders; use tui::widgets::Borders;
use crate::options::ConfigColours; use crate::options::config::ConfigColours;
// Default widget ID // Default widget ID
pub const DEFAULT_WIDGET_ID: u64 = 56709; pub const DEFAULT_WIDGET_ID: u64 = 56709;

View File

@ -1,17 +1,5 @@
//! This is the main file to house data collection functions. //! This is the main file to house data collection functions.
use std::time::{Duration, Instant};
#[cfg(any(target_os = "linux", feature = "gpu"))]
use hashbrown::HashMap;
#[cfg(feature = "battery")]
use starship_battery::{Battery, Manager};
use sysinfo::{System, SystemExt};
use self::temperature::TemperatureType;
use super::DataFilters;
use crate::app::layout_manager::UsedWidgets;
#[cfg(feature = "nvidia")] #[cfg(feature = "nvidia")]
pub mod nvidia; pub mod nvidia;
@ -25,6 +13,18 @@ pub mod network;
pub mod processes; pub mod processes;
pub mod temperature; pub mod temperature;
use std::time::{Duration, Instant};
#[cfg(any(target_os = "linux", feature = "gpu"))]
use hashbrown::HashMap;
#[cfg(feature = "battery")]
use starship_battery::{Battery, Manager};
use sysinfo::{System, SystemExt};
use self::temperature::TemperatureType;
use super::DataFilters;
use crate::app::layout_manager::UsedWidgets;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Data { pub struct Data {
pub collection_time: Instant, pub collection_time: Instant,

View File

@ -1,10 +1,5 @@
//! Data collection about disks (e.g. I/O, usage, space). //! Data collection about disks (e.g. I/O, usage, space).
use cfg_if::cfg_if;
use hashbrown::HashMap;
use crate::app::filter::Filter;
cfg_if! { cfg_if! {
if #[cfg(target_os = "freebsd")] { if #[cfg(target_os = "freebsd")] {
mod freebsd; mod freebsd;
@ -32,6 +27,11 @@ cfg_if! {
} }
} }
use cfg_if::cfg_if;
use hashbrown::HashMap;
use crate::app::filter::Filter;
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct DiskHarvest { pub struct DiskHarvest {
pub name: String, pub name: String,

View File

@ -3,10 +3,7 @@
mod file_systems; mod file_systems;
use file_systems::*;
mod usage; mod usage;
use usage::*;
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] { if #[cfg(target_os = "linux")] {
@ -24,6 +21,9 @@ cfg_if::cfg_if! {
} }
} }
use file_systems::*;
use usage::*;
use super::{keep_disk_entry, DiskHarvest}; use super::{keep_disk_entry, DiskHarvest};
use crate::data_collection::DataCollector; use crate::data_collection::DataCollector;

View File

@ -1,5 +1,5 @@
mod partition;
pub(crate) use partition::*;
mod counters; mod counters;
mod partition;
pub use counters::*; pub use counters::*;
pub(crate) use partition::*;

View File

@ -1,10 +1,8 @@
mod bindings; mod bindings;
mod io_iterator;
pub use io_iterator::*;
mod io_object;
pub use io_object::*;
mod io_disks; mod io_disks;
mod io_iterator;
mod io_object;
pub use io_disks::get_disks; pub use io_disks::get_disks;
pub use io_iterator::*;
pub use io_object::*;

View File

@ -1,4 +1,4 @@
mod counters; mod counters;
pub use counters::*;
mod io_kit; mod io_kit;
pub use counters::*;

View File

@ -1,14 +1,14 @@
//! Disk stats via sysinfo. //! Disk stats via sysinfo.
mod bindings;
use bindings::*;
use itertools::Itertools; use itertools::Itertools;
use sysinfo::{DiskExt, SystemExt}; use sysinfo::{DiskExt, SystemExt};
use super::{keep_disk_entry, DiskHarvest}; use super::{keep_disk_entry, DiskHarvest};
use crate::data_collection::{disks::IoCounters, DataCollector}; use crate::data_collection::{disks::IoCounters, DataCollector};
mod bindings;
use bindings::*;
/// Returns I/O stats. /// Returns I/O stats.
pub(crate) fn io_stats() -> anyhow::Result<Vec<IoCounters>> { pub(crate) fn io_stats() -> anyhow::Result<Vec<IoCounters>> {
let volume_io = all_volume_io()?; let volume_io = all_volume_io()?;

View File

@ -3,13 +3,8 @@
//! For Linux, this is handled by a custom set of functions. //! For Linux, this is handled by a custom set of functions.
//! For Windows, macOS, FreeBSD, Android, and Linux, this is handled by sysinfo. //! For Windows, macOS, FreeBSD, Android, and Linux, this is handled by sysinfo.
use std::{borrow::Cow, time::Duration};
use cfg_if::cfg_if; use cfg_if::cfg_if;
use super::DataCollector;
use crate::{utils::error, Pid};
cfg_if! { cfg_if! {
if #[cfg(target_os = "linux")] { if #[cfg(target_os = "linux")] {
pub mod linux; pub mod linux;
@ -36,6 +31,11 @@ cfg_if! {
} }
} }
use std::{borrow::Cow, time::Duration};
use super::DataCollector;
use crate::{utils::error, Pid};
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct ProcessHarvest { pub struct ProcessHarvest {
/// The pid of the process. /// The pid of the process.

View File

@ -1,6 +1,7 @@
//! Process data collection for Linux. //! Process data collection for Linux.
mod process; mod process;
use std::{ use std::{
fs::{self, File}, fs::{self, File},
io::{BufRead, BufReader}, io::{BufRead, BufReader},

View File

@ -1,5 +1,7 @@
//! Process data collection for macOS. Uses sysinfo and custom bindings. //! Process data collection for macOS. Uses sysinfo and custom bindings.
mod sysctl_bindings;
use std::{io, process::Command}; use std::{io, process::Command};
use hashbrown::HashMap; use hashbrown::HashMap;
@ -8,7 +10,6 @@ use sysinfo::{PidExt, ProcessExt};
use super::UnixProcessExt; use super::UnixProcessExt;
use crate::Pid; use crate::Pid;
mod sysctl_bindings;
pub(crate) struct MacOSProcessExt; pub(crate) struct MacOSProcessExt;

View File

@ -1,6 +1,7 @@
//! Unix-specific parts of process collection. //! Unix-specific parts of process collection.
mod user_table; mod user_table;
use cfg_if::cfg_if; use cfg_if::cfg_if;
pub use user_table::*; pub use user_table::*;

View File

@ -1,13 +1,15 @@
//! This mainly concerns converting collected data into things that the canvas //! This mainly concerns converting collected data into things that the canvas
//! can actually handle. //! can actually handle.
// TODO: Split this up!
use kstring::KString; use kstring::KString;
use crate::{ use crate::{
app::{data_farmer::DataCollection, AxisScaling}, app::{data_farmer::DataCollection, AxisScaling},
canvas::tui_widgets::time_chart::Point, canvas::tui_widgets::time_chart::Point,
data_collection::{cpu::CpuDataType, memory::MemHarvest, temperature::TemperatureType}, data_collection::{cpu::CpuDataType, memory::MemHarvest, temperature::TemperatureType},
utils::{data_prefixes::*, data_units::DataUnit, gen_util::*}, utils::{data_prefixes::*, data_units::DataUnit, general::*},
widgets::{DiskWidgetData, TempWidgetData}, widgets::{DiskWidgetData, TempWidgetData},
}; };

View File

@ -14,6 +14,21 @@
#![deny(clippy::unimplemented)] #![deny(clippy::unimplemented)]
#![deny(clippy::missing_safety_doc)] #![deny(clippy::missing_safety_doc)]
pub mod app;
pub mod utils {
pub mod data_prefixes;
pub mod data_units;
pub mod error;
pub mod general;
pub mod logging;
}
pub mod canvas;
pub mod constants;
pub mod data_collection;
pub mod data_conversion;
pub mod options;
pub mod widgets;
use std::{ use std::{
boxed::Box, boxed::Box,
fs, fs,
@ -44,25 +59,9 @@ use crossterm::{
terminal::{disable_raw_mode, LeaveAlternateScreen}, terminal::{disable_raw_mode, LeaveAlternateScreen},
}; };
use data_conversion::*; use data_conversion::*;
use options::*; pub use options::args;
use options::config::Config;
use utils::error; use utils::error;
pub mod app;
pub mod utils {
pub mod data_prefixes;
pub mod data_units;
pub mod error;
pub mod gen_util;
pub mod logging;
}
pub mod args;
pub mod canvas;
pub mod constants;
pub mod data_collection;
pub mod data_conversion;
pub mod options;
pub mod widgets;
#[allow(unused_imports)] #[allow(unused_imports)]
pub use utils::logging::*; pub use utils::logging::*;

File diff suppressed because it is too large Load Diff

1147
src/options/config.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +1,15 @@
pub mod process_table;
pub use process_table::*;
pub mod temperature_table;
pub use temperature_table::*;
pub mod disk_table;
pub use disk_table::*;
pub mod cpu_graph;
pub use cpu_graph::*;
pub mod net_graph;
pub use net_graph::*;
pub mod mem_graph;
pub use mem_graph::*;
pub mod battery_widget; pub mod battery_widget;
pub mod cpu_graph;
pub mod disk_table;
pub mod mem_graph;
pub mod net_graph;
pub mod process_table;
pub mod temperature_table;
pub use battery_widget::*; pub use battery_widget::*;
pub use cpu_graph::*;
pub use disk_table::*;
pub use mem_graph::*;
pub use net_graph::*;
pub use process_table::*;
pub use temperature_table::*;

View File

@ -15,8 +15,8 @@ use crate::{
}, },
data_collection::cpu::CpuDataType, data_collection::cpu::CpuDataType,
data_conversion::CpuWidgetData, data_conversion::CpuWidgetData,
options::CpuDefault, options::config::CpuDefault,
utils::gen_util::truncate_to_text, utils::general::truncate_to_text,
}; };
#[derive(Default)] #[derive(Default)]

View File

@ -12,7 +12,7 @@ use crate::{
SortColumn, SortDataTable, SortDataTableProps, SortOrder, SortsRow, SortColumn, SortDataTable, SortDataTableProps, SortOrder, SortsRow,
}, },
}, },
utils::gen_util::{get_decimal_bytes, sort_partial_fn, truncate_to_text}, utils::general::{get_decimal_bytes, sort_partial_fn, truncate_to_text},
}; };
#[derive(Clone, Debug)] #[derive(Clone, Debug)]

View File

@ -1,9 +1,16 @@
pub mod proc_widget_column;
pub mod proc_widget_data;
mod sort_table;
use std::{borrow::Cow, collections::BTreeMap}; use std::{borrow::Cow, collections::BTreeMap};
use hashbrown::{HashMap, HashSet}; use hashbrown::{HashMap, HashSet};
use indexmap::IndexSet; use indexmap::IndexSet;
use itertools::Itertools; use itertools::Itertools;
pub use proc_widget_column::*;
pub use proc_widget_data::*;
use serde::{de::Error, Deserialize}; use serde::{de::Error, Deserialize};
use sort_table::SortTableColumn;
use crate::{ use crate::{
app::{ app::{
@ -22,15 +29,6 @@ use crate::{
Pid, Pid,
}; };
pub mod proc_widget_column;
pub use proc_widget_column::*;
pub mod proc_widget_data;
pub use proc_widget_data::*;
mod sort_table;
use sort_table::SortTableColumn;
/// ProcessSearchState only deals with process' search's current settings and state. /// ProcessSearchState only deals with process' search's current settings and state.
pub struct ProcessSearchState { pub struct ProcessSearchState {
pub search_state: AppSearchState, pub search_state: AppSearchState,

View File

@ -5,7 +5,7 @@ use serde::{de::Error, Deserialize, Serialize};
use super::ProcWidgetData; use super::ProcWidgetData;
use crate::{ use crate::{
canvas::tui_widgets::data_table::{ColumnHeader, SortsRow}, canvas::tui_widgets::data_table::{ColumnHeader, SortsRow},
utils::gen_util::sort_partial_fn, utils::general::sort_partial_fn,
}; };
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]

View File

@ -15,7 +15,7 @@ use crate::{
}, },
data_collection::processes::ProcessHarvest, data_collection::processes::ProcessHarvest,
data_conversion::{binary_byte_string, dec_bytes_per_second_string, dec_bytes_string}, data_conversion::{binary_byte_string, dec_bytes_per_second_string, dec_bytes_string},
utils::gen_util::truncate_to_text, utils::general::truncate_to_text,
Pid, Pid,
}; };

View File

@ -4,7 +4,7 @@ use tui::text::Text;
use crate::{ use crate::{
canvas::tui_widgets::data_table::{ColumnHeader, DataTableColumn, DataToCell}, canvas::tui_widgets::data_table::{ColumnHeader, DataTableColumn, DataToCell},
utils::gen_util::truncate_to_text, utils::general::truncate_to_text,
}; };
pub struct SortTableColumn; pub struct SortTableColumn;

View File

@ -14,7 +14,7 @@ use crate::{
}, },
}, },
data_collection::temperature::TemperatureType, data_collection::temperature::TemperatureType,
utils::gen_util::{sort_partial_fn, truncate_to_text}, utils::general::{sort_partial_fn, truncate_to_text},
}; };
#[derive(Clone, Debug)] #[derive(Clone, Debug)]

View File

@ -1,8 +1,8 @@
//! These tests are mostly here just to ensure that invalid results will be caught when passing arguments. //! These tests are mostly here just to ensure that invalid results will be caught when passing arguments.
mod util;
use assert_cmd::prelude::*; use assert_cmd::prelude::*;
use predicates::prelude::*; use predicates::prelude::*;
mod util;
use util::*; use util::*;
#[test] #[test]

View File

@ -1,7 +1,7 @@
mod util;
use assert_cmd::prelude::*; use assert_cmd::prelude::*;
use predicates::prelude::*; use predicates::prelude::*;
mod util;
use util::*; use util::*;
// These tests are for testing some config file-specific options. // These tests are for testing some config file-specific options.

View File

@ -5,7 +5,7 @@ use bottom::constants::DEFAULT_BATTERY_LAYOUT;
use bottom::{ use bottom::{
app::layout_manager::{BottomLayout, BottomWidgetType}, app::layout_manager::{BottomLayout, BottomWidgetType},
constants::{DEFAULT_LAYOUT, DEFAULT_WIDGET_ID}, constants::{DEFAULT_LAYOUT, DEFAULT_WIDGET_ID},
options::{layout_options::Row, Config}, options::config::{layout::Row, Config},
utils::error, utils::error,
}; };
use toml_edit::de::from_str; use toml_edit::de::from_str;