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_nushell::Nushell;
include!("src/args.rs");
include!("src/options/args.rs");
fn create_dir(dir: &Path) -> io::Result<()> {
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::{
cmp::{max, min},
time::Instant,
@ -6,6 +14,7 @@ use std::{
use concat_string::concat_string;
use data_farmer::*;
use filter::*;
use frozen_state::FrozenState;
use hashbrown::HashMap;
use layout_manager::*;
pub use states::*;
@ -23,16 +32,6 @@ use crate::{
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)]
pub enum AxisScaling {
#[default]

View file

@ -21,7 +21,7 @@ use hashbrown::HashMap;
use crate::data_collection::batteries;
use crate::{
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,
};

View file

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

View file

@ -15,15 +15,12 @@ use std::{
use anyhow::{Context, Result};
use bottom::{
args,
canvas::{
styling::CanvasStyling,
{self},
},
canvas::{self, styling::CanvasStyling},
check_if_terminal, cleanup_terminal, create_collection_thread, create_input_thread,
create_or_get_config,
data_conversion::*,
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,
};
use crossterm::{
@ -73,7 +70,7 @@ fn main() -> Result<()> {
};
// 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,
config,
&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 itertools::izip;
@ -19,12 +25,6 @@ use crate::{
utils::{error, error::BottomError},
};
mod dialogs;
mod drawing_utils;
pub mod styling;
pub mod tui_widgets;
mod widgets;
#[derive(Debug)]
pub enum ColourScheme {
Default,

View file

@ -5,7 +5,7 @@ use tui::style::{Color, Style};
use super::ColourScheme;
use crate::{
constants::*,
options::{Config, ConfigColours},
options::config::{Config, ConfigColours},
utils::error,
};
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};
pub mod column;
pub use column::*;
pub mod styling;
pub use data_type::*;
pub use draw::*;
pub use props::DataTableProps;
pub use sortable::*;
pub use state::{DataTableState, ScrollDirection};
pub use styling::*;
pub mod props;
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;
use crate::utils::general::ClampExt;
/// 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,
DataTableStyling, DataToCell,
};
use crate::utils::gen_util::truncate_to_text;
use crate::utils::general::truncate_to_text;
/// Denotes the sort order.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]

View file

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

View file

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

View file

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

View file

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

View file

@ -1,17 +1,5 @@
//! 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")]
pub mod nvidia;
@ -25,6 +13,18 @@ pub mod network;
pub mod processes;
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)]
pub struct Data {
pub collection_time: Instant,

View file

@ -1,10 +1,5 @@
//! 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! {
if #[cfg(target_os = "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)]
pub struct DiskHarvest {
pub name: String,

View file

@ -3,10 +3,7 @@
mod file_systems;
use file_systems::*;
mod usage;
use usage::*;
cfg_if::cfg_if! {
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 crate::data_collection::DataCollector;

View file

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

View file

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

View file

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

View file

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

View file

@ -3,13 +3,8 @@
//! For Linux, this is handled by a custom set of functions.
//! For Windows, macOS, FreeBSD, Android, and Linux, this is handled by sysinfo.
use std::{borrow::Cow, time::Duration};
use cfg_if::cfg_if;
use super::DataCollector;
use crate::{utils::error, Pid};
cfg_if! {
if #[cfg(target_os = "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)]
pub struct ProcessHarvest {
/// The pid of the process.

View file

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

View file

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

View file

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

View file

@ -1,13 +1,15 @@
//! This mainly concerns converting collected data into things that the canvas
//! can actually handle.
// TODO: Split this up!
use kstring::KString;
use crate::{
app::{data_farmer::DataCollection, AxisScaling},
canvas::tui_widgets::time_chart::Point,
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},
};

View file

@ -14,6 +14,21 @@
#![deny(clippy::unimplemented)]
#![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::{
boxed::Box,
fs,
@ -44,25 +59,9 @@ use crossterm::{
terminal::{disable_raw_mode, LeaveAlternateScreen},
};
use data_conversion::*;
use options::*;
pub use options::args;
use options::config::Config;
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)]
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 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 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_conversion::CpuWidgetData,
options::CpuDefault,
utils::gen_util::truncate_to_text,
options::config::CpuDefault,
utils::general::truncate_to_text,
};
#[derive(Default)]

View file

@ -12,7 +12,7 @@ use crate::{
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)]

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 hashbrown::{HashMap, HashSet};
use indexmap::IndexSet;
use itertools::Itertools;
pub use proc_widget_column::*;
pub use proc_widget_data::*;
use serde::{de::Error, Deserialize};
use sort_table::SortTableColumn;
use crate::{
app::{
@ -22,15 +29,6 @@ use crate::{
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.
pub struct ProcessSearchState {
pub search_state: AppSearchState,

View file

@ -5,7 +5,7 @@ use serde::{de::Error, Deserialize, Serialize};
use super::ProcWidgetData;
use crate::{
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)]

View file

@ -15,7 +15,7 @@ use crate::{
},
data_collection::processes::ProcessHarvest,
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,
};

View file

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

View file

@ -14,7 +14,7 @@ use crate::{
},
},
data_collection::temperature::TemperatureType,
utils::gen_util::{sort_partial_fn, truncate_to_text},
utils::general::{sort_partial_fn, truncate_to_text},
};
#[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.
mod util;
use assert_cmd::prelude::*;
use predicates::prelude::*;
mod util;
use util::*;
#[test]

View file

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

View file

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