From 99fc5fc2c85b714c81ec6a7fca2615853e120caa Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Thu, 10 Nov 2022 01:22:19 -0500 Subject: [PATCH] refactor: run cargo +nightly fmt with group_imports (#885) * refactor: add some disabled unstable fmt options * run cargo +nightly fmt with group_imports * separate out the cfg-specific imports for clarity --- build.rs | 3 ++- rustfmt.toml | 5 +++++ src/app.rs | 11 ++++------- src/app/data_farmer.rs | 8 +++----- src/app/data_harvester.rs | 11 +++++------ src/app/data_harvester/cpu/heim.rs | 7 ++++--- src/app/data_harvester/cpu/heim/linux.rs | 3 ++- src/app/data_harvester/disks/freebsd.rs | 3 ++- .../data_harvester/memory/general/sysinfo.rs | 3 ++- src/app/data_harvester/network/heim.rs | 3 ++- src/app/data_harvester/network/sysinfo.rs | 3 ++- src/app/data_harvester/processes/freebsd.rs | 4 ++-- src/app/data_harvester/processes/linux.rs | 13 +++++-------- src/app/data_harvester/processes/macos.rs | 2 +- .../processes/macos/sysctl_bindings.rs | 3 ++- .../data_harvester/processes/macos_freebsd.rs | 2 +- src/app/data_harvester/processes/windows.rs | 3 ++- src/app/data_harvester/temperature/linux.rs | 6 ++++-- src/app/data_harvester/temperature/nvidia.rs | 6 ++---- src/app/data_harvester/temperature/sysinfo.rs | 3 ++- src/app/layout_manager.rs | 3 ++- src/app/query.rs | 8 ++++---- src/app/states.rs | 9 ++++----- src/app/widgets/cpu_graph.rs | 1 - src/app/widgets/process_table.rs | 6 +++--- .../process_table/proc_widget_column.rs | 7 +++---- .../widgets/process_table/proc_widget_data.rs | 3 +-- src/bin/main.rs | 15 +++++++-------- src/canvas.rs | 5 ++--- src/canvas/canvas_colours.rs | 10 +++++----- src/canvas/canvas_colours/colour_utils.rs | 2 +- src/canvas/dialogs/dd_dialog.rs | 1 + src/canvas/dialogs/help_dialog.rs | 6 +++--- src/canvas/drawing_utils.rs | 7 +++++-- src/canvas/widgets/basic_table_arrows.rs | 10 +++++----- src/canvas/widgets/battery_display.rs | 12 ++++++------ src/canvas/widgets/cpu_basic.rs | 14 +++++++------- src/canvas/widgets/cpu_graph.rs | 15 +++++++-------- src/canvas/widgets/mem_basic.rs | 8 ++++---- src/canvas/widgets/mem_graph.rs | 12 ++++++------ src/canvas/widgets/network_basic.rs | 4 ++-- src/canvas/widgets/network_graph.rs | 16 ++++++++-------- src/canvas/widgets/process_table.rs | 15 +++++++-------- src/components/data_table/data_type.rs | 3 +-- src/components/data_table/draw.rs | 9 ++++----- src/components/data_table/sortable.rs | 3 +-- src/components/time_graph.rs | 6 ++---- src/components/tui_widget/time_chart.rs | 1 + src/constants.rs | 3 ++- src/data_conversion.rs | 4 ++-- src/lib.rs | 18 ++++++++---------- src/options.rs | 11 +++++------ src/options/layout_options.rs | 3 ++- src/utils/error.rs | 1 + 54 files changed, 176 insertions(+), 177 deletions(-) diff --git a/build.rs b/build.rs index fd8ce637..4bf02504 100644 --- a/build.rs +++ b/build.rs @@ -1,10 +1,11 @@ -use clap_complete::{generate_to, shells::Shell}; use std::{ env, fs, io::Result, path::{Path, PathBuf}, }; +use clap_complete::{generate_to, shells::Shell}; + include!("src/clap.rs"); fn create_dir(dir: &Path) -> Result<()> { diff --git a/rustfmt.toml b/rustfmt.toml index 03574d14..e30350f9 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -5,3 +5,8 @@ fn_args_layout = "Compressed" use_field_init_shorthand = true tab_spaces = 4 max_width = 100 + +# Unstable options, disabled by default. +# group_imports = "StdExternalCrate" +# wrap_comments = true +# format_code_in_doc_comments = true diff --git a/src/app.rs b/src/app.rs index ea34f259..3669bfa9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,16 +5,15 @@ use std::{ }; use concat_string::concat_string; -use unicode_segmentation::{GraphemeCursor, UnicodeSegmentation}; -use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; - -use typed_builder::*; - use data_farmer::*; use data_harvester::temperature; use layout_manager::*; pub use states::*; +use typed_builder::*; +use unicode_segmentation::{GraphemeCursor, UnicodeSegmentation}; +use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; +use self::widgets::{ProcWidget, ProcWidgetMode}; use crate::{ constants, data_conversion::ConvertedData, @@ -23,8 +22,6 @@ use crate::{ Pid, }; -use self::widgets::{ProcWidget, ProcWidgetMode}; - pub mod data_farmer; pub mod data_harvester; pub mod frozen_state; diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs index f0427c5d..2749c9bc 100644 --- a/src/app/data_farmer.rs +++ b/src/app/data_farmer.rs @@ -13,22 +13,20 @@ //! memory usage and higher CPU usage - you will be trying to process more and //! more points as this is used! -use once_cell::sync::Lazy; +use std::{time::Instant, vec::Vec}; use fxhash::FxHashMap; use itertools::Itertools; - -use std::{time::Instant, vec::Vec}; +use once_cell::sync::Lazy; +use regex::Regex; #[cfg(feature = "battery")] use crate::data_harvester::batteries; - use crate::{ data_harvester::{cpu, disks, memory, network, processes::ProcessHarvest, temperature, Data}, utils::gen_util::{get_decimal_bytes, GIGA_LIMIT}, Pid, }; -use regex::Regex; pub type TimeOffset = f64; pub type Value = f64; diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs index f289f41f..f15c0fcb 100644 --- a/src/app/data_harvester.rs +++ b/src/app/data_harvester.rs @@ -2,20 +2,19 @@ use std::time::Instant; +use futures::join; + #[cfg(target_os = "linux")] use fxhash::FxHashMap; -#[cfg(not(target_os = "linux"))] -use sysinfo::{System, SystemExt}; - #[cfg(feature = "battery")] use starship_battery::{Battery, Manager}; -use crate::app::layout_manager::UsedWidgets; - -use futures::join; +#[cfg(not(target_os = "linux"))] +use sysinfo::{System, SystemExt}; use super::DataFilters; +use crate::app::layout_manager::UsedWidgets; #[cfg(feature = "nvidia")] pub mod nvidia; diff --git a/src/app/data_harvester/cpu/heim.rs b/src/app/data_harvester/cpu/heim.rs index de4fd033..f3aa92aa 100644 --- a/src/app/data_harvester/cpu/heim.rs +++ b/src/app/data_harvester/cpu/heim.rs @@ -18,14 +18,15 @@ cfg_if::cfg_if! { } } +use std::collections::VecDeque; + +use futures::StreamExt; + use crate::{ components::tui_widget::time_chart::Point, data_harvester::cpu::{CpuData, CpuDataType, CpuHarvest, PastCpuTotal, PastCpuWork}, }; -use futures::StreamExt; -use std::collections::VecDeque; - pub async fn get_cpu_data_list( show_average_cpu: bool, previous_cpu_times: &mut Vec<(PastCpuWork, PastCpuTotal)>, previous_average_cpu_time: &mut Option<(PastCpuWork, PastCpuTotal)>, diff --git a/src/app/data_harvester/cpu/heim/linux.rs b/src/app/data_harvester/cpu/heim/linux.rs index f7bf3ead..f1b040c4 100644 --- a/src/app/data_harvester/cpu/heim/linux.rs +++ b/src/app/data_harvester/cpu/heim/linux.rs @@ -1,8 +1,9 @@ //! Linux-specific functions regarding CPU usage. -use crate::components::tui_widget::time_chart::Point; use heim::cpu::os::linux::CpuTimeExt; +use crate::components::tui_widget::time_chart::Point; + pub fn convert_cpu_times(cpu_time: &heim::cpu::CpuTime) -> Point { let working_time: f64 = (cpu_time.user() + cpu_time.nice() diff --git a/src/app/data_harvester/disks/freebsd.rs b/src/app/data_harvester/disks/freebsd.rs index d14dd793..d657931b 100644 --- a/src/app/data_harvester/disks/freebsd.rs +++ b/src/app/data_harvester/disks/freebsd.rs @@ -1,8 +1,9 @@ //! Disk stats for FreeBSD. -use serde::Deserialize; use std::io; +use serde::Deserialize; + use super::{DiskHarvest, IoHarvest}; use crate::app::Filter; use crate::data_harvester::deserialize_xo; diff --git a/src/app/data_harvester/memory/general/sysinfo.rs b/src/app/data_harvester/memory/general/sysinfo.rs index 93130e96..ea0f9077 100644 --- a/src/app/data_harvester/memory/general/sysinfo.rs +++ b/src/app/data_harvester/memory/general/sysinfo.rs @@ -1,8 +1,9 @@ //! Data collection for memory via sysinfo. -use crate::data_harvester::memory::{MemCollect, MemHarvest}; use sysinfo::{System, SystemExt}; +use crate::data_harvester::memory::{MemCollect, MemHarvest}; + pub async fn get_mem_data(sys: &System, actually_get: bool, _get_gpu: bool) -> MemCollect { if !actually_get { MemCollect { diff --git a/src/app/data_harvester/network/heim.rs b/src/app/data_harvester/network/heim.rs index b7980ddb..28144a55 100644 --- a/src/app/data_harvester/network/heim.rs +++ b/src/app/data_harvester/network/heim.rs @@ -1,8 +1,9 @@ //! Gets network data via heim. -use super::NetworkHarvest; use std::time::Instant; +use super::NetworkHarvest; + // TODO: Eventually make it so that this thing also takes individual usage into account, so we can show per-interface! pub async fn get_network_data( prev_net_access_time: Instant, prev_net_rx: &mut u64, prev_net_tx: &mut u64, diff --git a/src/app/data_harvester/network/sysinfo.rs b/src/app/data_harvester/network/sysinfo.rs index 634cf779..e3aea9e7 100644 --- a/src/app/data_harvester/network/sysinfo.rs +++ b/src/app/data_harvester/network/sysinfo.rs @@ -1,8 +1,9 @@ //! Gets network data via sysinfo. -use super::NetworkHarvest; use std::time::Instant; +use super::NetworkHarvest; + pub async fn get_network_data( sys: &sysinfo::System, prev_net_access_time: Instant, prev_net_rx: &mut u64, prev_net_tx: &mut u64, curr_time: Instant, actually_get: bool, diff --git a/src/app/data_harvester/processes/freebsd.rs b/src/app/data_harvester/processes/freebsd.rs index 9250c308..49816bc2 100644 --- a/src/app/data_harvester/processes/freebsd.rs +++ b/src/app/data_harvester/processes/freebsd.rs @@ -1,11 +1,11 @@ //! Process data collection for FreeBSD. Uses sysinfo. -use serde::{Deserialize, Deserializer}; use std::io; -use super::ProcessHarvest; +use serde::{Deserialize, Deserializer}; use sysinfo::System; +use super::ProcessHarvest; use crate::data_harvester::deserialize_xo; use crate::data_harvester::processes::UserTable; diff --git a/src/app/data_harvester/processes/linux.rs b/src/app/data_harvester/processes/linux.rs index a2e5e253..6b2875f8 100644 --- a/src/app/data_harvester/processes/linux.rs +++ b/src/app/data_harvester/processes/linux.rs @@ -2,18 +2,15 @@ use std::collections::hash_map::Entry; +use fxhash::{FxHashMap, FxHashSet}; +use procfs::process::{Process, Stat}; +use sysinfo::ProcessStatus; + +use super::{ProcessHarvest, UserTable}; use crate::components::tui_widget::time_chart::Point; use crate::utils::error::{self, BottomError}; use crate::Pid; -use super::{ProcessHarvest, UserTable}; - -use sysinfo::ProcessStatus; - -use procfs::process::{Process, Stat}; - -use fxhash::{FxHashMap, FxHashSet}; - /// Maximum character length of a /proc//stat process name. /// If it's equal or greater, then we instead refer to the command for the name. const MAX_STAT_NAME_LEN: usize = 15; diff --git a/src/app/data_harvester/processes/macos.rs b/src/app/data_harvester/processes/macos.rs index 80ded85e..d0847a1b 100644 --- a/src/app/data_harvester/processes/macos.rs +++ b/src/app/data_harvester/processes/macos.rs @@ -1,8 +1,8 @@ //! Process data collection for macOS. Uses sysinfo and custom bindings. -use super::ProcessHarvest; use sysinfo::System; +use super::ProcessHarvest; use crate::{data_harvester::processes::UserTable, Pid}; mod sysctl_bindings; diff --git a/src/app/data_harvester/processes/macos/sysctl_bindings.rs b/src/app/data_harvester/processes/macos/sysctl_bindings.rs index 22bc07c6..e56d79b8 100644 --- a/src/app/data_harvester/processes/macos/sysctl_bindings.rs +++ b/src/app/data_harvester/processes/macos/sysctl_bindings.rs @@ -295,9 +295,10 @@ pub(crate) fn kinfo_process(pid: Pid) -> Result { #[cfg(test)] mod test { - use super::*; use std::mem; + use super::*; + /// A quick test to ensure that things are sized correctly. #[test] fn test_struct_sizes() { diff --git a/src/app/data_harvester/processes/macos_freebsd.rs b/src/app/data_harvester/processes/macos_freebsd.rs index 65725732..588d49dc 100644 --- a/src/app/data_harvester/processes/macos_freebsd.rs +++ b/src/app/data_harvester/processes/macos_freebsd.rs @@ -3,9 +3,9 @@ use std::collections::HashMap; use std::io; -use super::ProcessHarvest; use sysinfo::{CpuExt, PidExt, ProcessExt, ProcessStatus, System, SystemExt}; +use super::ProcessHarvest; use crate::{data_harvester::processes::UserTable, utils::error::Result, Pid}; pub fn get_process_data( diff --git a/src/app/data_harvester/processes/windows.rs b/src/app/data_harvester/processes/windows.rs index 4df40983..7eac0411 100644 --- a/src/app/data_harvester/processes/windows.rs +++ b/src/app/data_harvester/processes/windows.rs @@ -1,8 +1,9 @@ //! Process data collection for Windows. Uses sysinfo. -use super::ProcessHarvest; use sysinfo::{CpuExt, PidExt, ProcessExt, System, SystemExt}; +use super::ProcessHarvest; + pub fn get_process_data( sys: &System, use_current_cpu_total: bool, mem_total_kb: u64, ) -> crate::utils::error::Result> { diff --git a/src/app/data_harvester/temperature/linux.rs b/src/app/data_harvester/temperature/linux.rs index 5fec1059..0bca3649 100644 --- a/src/app/data_harvester/temperature/linux.rs +++ b/src/app/data_harvester/temperature/linux.rs @@ -1,12 +1,14 @@ //! Gets temperature sensor data for Linux platforms. +use std::{fs, path::Path}; + +use anyhow::{anyhow, Result}; + use super::{is_temp_filtered, temp_vec_sort, TempHarvest, TemperatureType}; use crate::app::{ data_harvester::temperature::{convert_celsius_to_fahrenheit, convert_celsius_to_kelvin}, Filter, }; -use anyhow::{anyhow, Result}; -use std::{fs, path::Path}; /// Get temperature sensors from the linux sysfs interface `/sys/class/hwmon`. /// See [here](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-hwmon) for diff --git a/src/app/data_harvester/temperature/nvidia.rs b/src/app/data_harvester/temperature/nvidia.rs index 049708b7..be51e45b 100644 --- a/src/app/data_harvester/temperature/nvidia.rs +++ b/src/app/data_harvester/temperature/nvidia.rs @@ -1,12 +1,10 @@ -use crate::app::Filter; +use nvml_wrapper::enum_wrappers::device::TemperatureSensor; use super::{ convert_celsius_to_fahrenheit, convert_celsius_to_kelvin, is_temp_filtered, TempHarvest, TemperatureType, }; - -use nvml_wrapper::enum_wrappers::device::TemperatureSensor; - +use crate::app::Filter; use crate::data_harvester::nvidia::NVML_DATA; pub fn add_nvidia_data( diff --git a/src/app/data_harvester/temperature/sysinfo.rs b/src/app/data_harvester/temperature/sysinfo.rs index 42ed1a68..83a15094 100644 --- a/src/app/data_harvester/temperature/sysinfo.rs +++ b/src/app/data_harvester/temperature/sysinfo.rs @@ -1,11 +1,12 @@ //! Gets temperature data via sysinfo. +use anyhow::Result; + use super::{ convert_celsius_to_fahrenheit, convert_celsius_to_kelvin, is_temp_filtered, temp_vec_sort, TempHarvest, TemperatureType, }; use crate::app::Filter; -use anyhow::Result; pub fn get_temperature_data( sys: &sysinfo::System, temp_type: &TemperatureType, filter: &Option, diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs index 916a3d5b..fab2d918 100644 --- a/src/app/layout_manager.rs +++ b/src/app/layout_manager.rs @@ -1,8 +1,9 @@ -use crate::error::{BottomError, Result}; use std::collections::BTreeMap; + use typed_builder::*; use crate::constants::DEFAULT_WIDGET_ID; +use crate::error::{BottomError, Result}; /// Represents a more usable representation of the layout, derived from the /// config. diff --git a/src/app/query.rs b/src/app/query.rs index 46c40022..0eca1b75 100644 --- a/src/app/query.rs +++ b/src/app/query.rs @@ -1,11 +1,11 @@ -use crate::utils::error::{ - BottomError::{self, QueryError}, - Result, -}; use std::fmt::Debug; use std::{borrow::Cow, collections::VecDeque}; use super::data_harvester::processes::ProcessHarvest; +use crate::utils::error::{ + BottomError::{self, QueryError}, + Result, +}; const DELIMITER_LIST: [char; 6] = ['=', '>', '<', '(', ')', '\"']; const COMPARISON_LIST: [&str; 3] = [">", "=", "<"]; diff --git a/src/app/states.rs b/src/app/states.rs index 63b9bae8..4c3e6e28 100644 --- a/src/app/states.rs +++ b/src/app/states.rs @@ -2,15 +2,14 @@ use std::{collections::HashMap, time::Instant}; use unicode_segmentation::GraphemeCursor; -use crate::{ - app::{layout_manager::BottomWidgetType, query::*}, - constants, -}; - use super::widgets::{ BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState, ProcWidget, TempWidgetState, }; +use crate::{ + app::{layout_manager::BottomWidgetType, query::*}, + constants, +}; #[derive(Debug)] pub enum CursorDirection { diff --git a/src/app/widgets/cpu_graph.rs b/src/app/widgets/cpu_graph.rs index 5e895edc..7f0c1495 100644 --- a/src/app/widgets/cpu_graph.rs +++ b/src/app/widgets/cpu_graph.rs @@ -1,7 +1,6 @@ use std::{borrow::Cow, time::Instant}; use concat_string::concat_string; - use tui::{style::Style, text::Text, widgets::Row}; use crate::{ diff --git a/src/app/widgets/process_table.rs b/src/app/widgets/process_table.rs index 970e1cc5..cb630aac 100644 --- a/src/app/widgets/process_table.rs +++ b/src/app/widgets/process_table.rs @@ -1,5 +1,8 @@ use std::borrow::Cow; +use fxhash::{FxHashMap, FxHashSet}; +use itertools::Itertools; + use crate::{ app::{ data_farmer::{DataCollection, ProcessData}, @@ -15,9 +18,6 @@ use crate::{ Pid, }; -use fxhash::{FxHashMap, FxHashSet}; -use itertools::Itertools; - pub mod proc_widget_column; pub use proc_widget_column::*; diff --git a/src/app/widgets/process_table/proc_widget_column.rs b/src/app/widgets/process_table/proc_widget_column.rs index 4830bc65..691aec02 100644 --- a/src/app/widgets/process_table/proc_widget_column.rs +++ b/src/app/widgets/process_table/proc_widget_column.rs @@ -1,12 +1,11 @@ +use std::{borrow::Cow, cmp::Reverse}; + +use super::ProcWidgetData; use crate::{ components::data_table::{ColumnHeader, SortsRow}, utils::gen_util::sort_partial_fn, }; -use std::{borrow::Cow, cmp::Reverse}; - -use super::ProcWidgetData; - #[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum ProcColumn { CpuPercent, diff --git a/src/app/widgets/process_table/proc_widget_data.rs b/src/app/widgets/process_table/proc_widget_data.rs index 4957c87f..acb33af4 100644 --- a/src/app/widgets/process_table/proc_widget_data.rs +++ b/src/app/widgets/process_table/proc_widget_data.rs @@ -6,6 +6,7 @@ use std::{ use concat_string::concat_string; use tui::{text::Text, widgets::Row}; +use super::proc_widget_column::ProcColumn; use crate::{ app::data_harvester::processes::ProcessHarvest, canvas::Painter, @@ -15,8 +16,6 @@ use crate::{ Pid, }; -use super::proc_widget_column::ProcColumn; - #[derive(Clone)] enum IdType { Name(String), diff --git a/src/bin/main.rs b/src/bin/main.rs index feef550a..a1fdcbc1 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -4,14 +4,6 @@ #[macro_use] extern crate log; -use bottom::{ - canvas::{self, canvas_colours::CanvasColours}, - constants::*, - data_conversion::*, - options::*, - *, -}; - use std::{ boxed::Box, io::stdout, @@ -25,6 +17,13 @@ use std::{ }; use anyhow::{Context, Result}; +use bottom::{ + canvas::{self, canvas_colours::CanvasColours}, + constants::*, + data_conversion::*, + options::*, + *, +}; use crossterm::{ event::{EnableBracketedPaste, EnableMouseCapture}, execute, diff --git a/src/canvas.rs b/src/canvas.rs index c9312700..c7508802 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -1,6 +1,7 @@ -use itertools::izip; use std::str::FromStr; +use canvas_colours::*; +use itertools::izip; use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, @@ -9,8 +10,6 @@ use tui::{ Frame, Terminal, }; -use canvas_colours::*; - use crate::{ app::{ self, diff --git a/src/canvas/canvas_colours.rs b/src/canvas/canvas_colours.rs index 1fa9ce3a..6a43a305 100644 --- a/src/canvas/canvas_colours.rs +++ b/src/canvas/canvas_colours.rs @@ -1,13 +1,13 @@ -use crate::{ - constants::*, - options::{Config, ConfigColours}, - utils::error, -}; use anyhow::Context; use colour_utils::*; use tui::style::{Color, Style}; use super::ColourScheme; +use crate::{ + constants::*, + options::{Config, ConfigColours}, + utils::error, +}; mod colour_utils; pub struct CanvasColours { diff --git a/src/canvas/canvas_colours/colour_utils.rs b/src/canvas/canvas_colours/colour_utils.rs index 47ab49f5..995bdb42 100644 --- a/src/canvas/canvas_colours/colour_utils.rs +++ b/src/canvas/canvas_colours/colour_utils.rs @@ -1,6 +1,6 @@ -use once_cell::sync::Lazy; use std::collections::HashMap; +use once_cell::sync::Lazy; use tui::style::{Color, Style}; use crate::utils::error; diff --git a/src/canvas/dialogs/dd_dialog.rs b/src/canvas/dialogs/dd_dialog.rs index 1914ddec..00383546 100644 --- a/src/canvas/dialogs/dd_dialog.rs +++ b/src/canvas/dialogs/dd_dialog.rs @@ -1,5 +1,6 @@ #[cfg(target_family = "unix")] use std::cmp::min; + use tui::{ backend::Backend, layout::{Alignment, Constraint, Direction, Layout, Rect}, diff --git a/src/canvas/dialogs/help_dialog.rs b/src/canvas/dialogs/help_dialog.rs index c315bc8c..cd61db74 100644 --- a/src/canvas/dialogs/help_dialog.rs +++ b/src/canvas/dialogs/help_dialog.rs @@ -1,8 +1,5 @@ use std::cmp::{max, min}; -use unicode_width::UnicodeWidthStr; - -use crate::{app::App, canvas::Painter, constants}; use tui::{ backend::Backend, layout::{Alignment, Rect}, @@ -11,6 +8,9 @@ use tui::{ text::Spans, widgets::{Block, Borders, Paragraph, Wrap}, }; +use unicode_width::UnicodeWidthStr; + +use crate::{app::App, canvas::Painter, constants}; const HELP_BASE: &str = " Help ── Esc to close "; diff --git a/src/canvas/drawing_utils.rs b/src/canvas/drawing_utils.rs index 7ef1b85d..8d29b9a5 100644 --- a/src/canvas/drawing_utils.rs +++ b/src/canvas/drawing_utils.rs @@ -1,7 +1,8 @@ +use std::{cmp::min, time::Instant}; + use tui::layout::Rect; use crate::app::CursorDirection; -use std::{cmp::min, time::Instant}; pub fn get_search_start_position( num_columns: usize, cursor_direction: &CursorDirection, cursor_bar: &mut usize, @@ -89,10 +90,12 @@ mod test { #[test] fn test_should_hide_x_label() { - use crate::constants::*; use std::time::{Duration, Instant}; + use tui::layout::Rect; + use crate::constants::*; + let rect = Rect::new(0, 0, 10, 10); let small_rect = Rect::new(0, 0, 10, 6); diff --git a/src/canvas/widgets/basic_table_arrows.rs b/src/canvas/widgets/basic_table_arrows.rs index ae87ff7f..b0202906 100644 --- a/src/canvas/widgets/basic_table_arrows.rs +++ b/src/canvas/widgets/basic_table_arrows.rs @@ -1,8 +1,3 @@ -use crate::{ - app::{layout_manager::BottomWidgetType, App}, - canvas::Painter, -}; - use tui::{ backend::Backend, layout::{Alignment, Constraint, Direction, Layout, Rect}, @@ -12,6 +7,11 @@ use tui::{ widgets::{Block, Paragraph}, }; +use crate::{ + app::{layout_manager::BottomWidgetType, App}, + canvas::Painter, +}; + impl Painter { pub fn draw_basic_table_arrows( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, diff --git a/src/canvas/widgets/battery_display.rs b/src/canvas/widgets/battery_display.rs index 48ed9c46..3479f13f 100644 --- a/src/canvas/widgets/battery_display.rs +++ b/src/canvas/widgets/battery_display.rs @@ -1,9 +1,3 @@ -use crate::{ - app::App, - canvas::{drawing_utils::calculate_basic_use_bars, Painter}, - constants::*, -}; - use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, @@ -13,6 +7,12 @@ use tui::{ }; use unicode_segmentation::UnicodeSegmentation; +use crate::{ + app::App, + canvas::{drawing_utils::calculate_basic_use_bars, Painter}, + constants::*, +}; + impl Painter { pub fn draw_battery_display( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, draw_border: bool, diff --git a/src/canvas/widgets/cpu_basic.rs b/src/canvas/widgets/cpu_basic.rs index 1ca75a90..749d6e15 100644 --- a/src/canvas/widgets/cpu_basic.rs +++ b/src/canvas/widgets/cpu_basic.rs @@ -1,5 +1,12 @@ use std::cmp::min; +use tui::{ + backend::Backend, + layout::{Constraint, Direction, Layout, Rect}, + terminal::Frame, + widgets::Block, +}; + use crate::{ app::{data_harvester::cpu::CpuDataType, App}, canvas::Painter, @@ -8,13 +15,6 @@ use crate::{ data_conversion::CpuWidgetData, }; -use tui::{ - backend::Backend, - layout::{Constraint, Direction, Layout, Rect}, - terminal::Frame, - widgets::Block, -}; - impl Painter { /// Inspired by htop. pub fn draw_basic_cpu( diff --git a/src/canvas/widgets/cpu_graph.rs b/src/canvas/widgets/cpu_graph.rs index c61d340a..6cf09ea1 100644 --- a/src/canvas/widgets/cpu_graph.rs +++ b/src/canvas/widgets/cpu_graph.rs @@ -1,5 +1,12 @@ use std::borrow::Cow; +use concat_string::concat_string; +use tui::{ + backend::Backend, + layout::{Constraint, Direction, Layout, Rect}, + terminal::Frame, +}; + use crate::{ app::{layout_manager::WidgetDirection, widgets::CpuWidgetState, App}, canvas::{drawing_utils::should_hide_x_label, Painter}, @@ -10,14 +17,6 @@ use crate::{ data_conversion::CpuWidgetData, }; -use concat_string::concat_string; - -use tui::{ - backend::Backend, - layout::{Constraint, Direction, Layout, Rect}, - terminal::Frame, -}; - const AVG_POSITION: usize = 1; const ALL_POSITION: usize = 0; diff --git a/src/canvas/widgets/mem_basic.rs b/src/canvas/widgets/mem_basic.rs index 5e3d3d91..4c0ea57e 100644 --- a/src/canvas/widgets/mem_basic.rs +++ b/src/canvas/widgets/mem_basic.rs @@ -1,7 +1,3 @@ -use crate::{ - app::App, canvas::Painter, components::tui_widget::pipe_gauge::PipeGauge, constants::*, -}; - use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, @@ -9,6 +5,10 @@ use tui::{ widgets::Block, }; +use crate::{ + app::App, canvas::Painter, components::tui_widget::pipe_gauge::PipeGauge, constants::*, +}; + impl Painter { pub fn draw_basic_memory( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, diff --git a/src/canvas/widgets/mem_graph.rs b/src/canvas/widgets/mem_graph.rs index c156fbaa..8ee5d96f 100644 --- a/src/canvas/widgets/mem_graph.rs +++ b/src/canvas/widgets/mem_graph.rs @@ -1,17 +1,17 @@ use std::borrow::Cow; -use crate::{ - app::App, - canvas::{drawing_utils::should_hide_x_label, Painter}, - components::time_graph::{GraphData, TimeGraph}, -}; - use tui::{ backend::Backend, layout::{Constraint, Rect}, terminal::Frame, }; +use crate::{ + app::App, + canvas::{drawing_utils::should_hide_x_label, Painter}, + components::time_graph::{GraphData, TimeGraph}, +}; + impl Painter { pub fn draw_memory_graph( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, diff --git a/src/canvas/widgets/network_basic.rs b/src/canvas/widgets/network_basic.rs index b58da96f..4dd98295 100644 --- a/src/canvas/widgets/network_basic.rs +++ b/src/canvas/widgets/network_basic.rs @@ -1,5 +1,3 @@ -use crate::{app::App, canvas::Painter, constants::*}; - use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, @@ -8,6 +6,8 @@ use tui::{ widgets::{Block, Paragraph}, }; +use crate::{app::App, canvas::Painter, constants::*}; + impl Painter { pub fn draw_basic_network( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, diff --git a/src/canvas/widgets/network_graph.rs b/src/canvas/widgets/network_graph.rs index ad8c9679..de21a6c2 100644 --- a/src/canvas/widgets/network_graph.rs +++ b/src/canvas/widgets/network_graph.rs @@ -1,3 +1,11 @@ +use tui::{ + backend::Backend, + layout::{Constraint, Direction, Layout, Rect}, + terminal::Frame, + text::Text, + widgets::{Block, Borders, Row, Table}, +}; + use crate::{ app::{App, AxisScaling}, canvas::{drawing_utils::should_hide_x_label, Painter}, @@ -9,14 +17,6 @@ use crate::{ utils::gen_util::*, }; -use tui::{ - backend::Backend, - layout::{Constraint, Direction, Layout, Rect}, - terminal::Frame, - text::Text, - widgets::{Block, Borders, Row, Table}, -}; - impl Painter { pub fn draw_network( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, diff --git a/src/canvas/widgets/process_table.rs b/src/canvas/widgets/process_table.rs index 6e29d39c..a2e66da1 100644 --- a/src/canvas/widgets/process_table.rs +++ b/src/canvas/widgets/process_table.rs @@ -1,10 +1,3 @@ -use crate::{ - app::App, - canvas::{drawing_utils::get_search_start_position, Painter}, - components::data_table::{DrawInfo, SelectionState}, - constants::*, -}; - use tui::{ backend::Backend, layout::{Alignment, Constraint, Direction, Layout, Rect}, @@ -12,10 +5,16 @@ use tui::{ text::{Span, Spans}, widgets::{Block, Borders, Paragraph}, }; - use unicode_segmentation::{GraphemeIndices, UnicodeSegmentation}; use unicode_width::UnicodeWidthStr; +use crate::{ + app::App, + canvas::{drawing_utils::get_search_start_position, Painter}, + components::data_table::{DrawInfo, SelectionState}, + constants::*, +}; + const SORT_MENU_WIDTH: u16 = 7; impl Painter { diff --git a/src/components/data_table/data_type.rs b/src/components/data_table/data_type.rs index 9c7c12c9..6fad3196 100644 --- a/src/components/data_table/data_type.rs +++ b/src/components/data_table/data_type.rs @@ -1,8 +1,7 @@ use tui::{text::Text, widgets::Row}; -use crate::canvas::Painter; - use super::{ColumnHeader, DataTableColumn}; +use crate::canvas::Painter; pub trait DataToCell where diff --git a/src/components/data_table/draw.rs b/src/components/data_table/draw.rs index 5459e51e..fa3958dd 100644 --- a/src/components/data_table/draw.rs +++ b/src/components/data_table/draw.rs @@ -13,17 +13,16 @@ use tui::{ }; use unicode_segmentation::UnicodeSegmentation; +use super::{ + CalculateColumnWidths, ColumnHeader, ColumnWidthBounds, DataTable, DataTableColumn, DataToCell, + SortType, +}; use crate::{ app::layout_manager::BottomWidget, canvas::Painter, constants::{SIDE_BORDERS, TABLE_GAP_HEIGHT_LIMIT}, }; -use super::{ - CalculateColumnWidths, ColumnHeader, ColumnWidthBounds, DataTable, DataTableColumn, DataToCell, - SortType, -}; - pub enum SelectionState { NotSelected, Selected, diff --git a/src/components/data_table/sortable.rs b/src/components/data_table/sortable.rs index 6980408c..f5343b85 100644 --- a/src/components/data_table/sortable.rs +++ b/src/components/data_table/sortable.rs @@ -4,12 +4,11 @@ use concat_string::concat_string; use itertools::Itertools; use tui::widgets::Row; -use crate::utils::gen_util::truncate_text; - use super::{ ColumnHeader, ColumnWidthBounds, DataTable, DataTableColumn, DataTableProps, DataTableState, DataTableStyling, DataToCell, }; +use crate::utils::gen_util::truncate_text; /// Denotes the sort order. #[derive(Clone, Copy, Debug, PartialEq, Eq)] diff --git a/src/components/time_graph.rs b/src/components/time_graph.rs index 6403eb45..d6f409e2 100644 --- a/src/components/time_graph.rs +++ b/src/components/time_graph.rs @@ -1,5 +1,6 @@ use std::borrow::Cow; +use concat_string::concat_string; use tui::{ backend::Backend, layout::{Constraint, Rect}, @@ -9,8 +10,6 @@ use tui::{ widgets::{Block, Borders, GraphType}, Frame, }; - -use concat_string::concat_string; use unicode_segmentation::UnicodeSegmentation; use super::tui_widget::time_chart::{Axis, Dataset, Point, TimeChart, DEFAULT_LEGEND_CONSTRAINTS}; @@ -194,9 +193,8 @@ mod test { text::{Span, Spans}, }; - use crate::components::tui_widget::time_chart::Axis; - use super::TimeGraph; + use crate::components::tui_widget::time_chart::Axis; const Y_LABELS: [Cow<'static, str>; 3] = [ Cow::Borrowed("0%"), diff --git a/src/components/tui_widget/time_chart.rs b/src/components/tui_widget/time_chart.rs index 249568f8..eb04763c 100644 --- a/src/components/tui_widget/time_chart.rs +++ b/src/components/tui_widget/time_chart.rs @@ -1,4 +1,5 @@ use std::{borrow::Cow, cmp::max}; + use tui::{ buffer::Buffer, layout::{Constraint, Rect}, diff --git a/src/constants.rs b/src/constants.rs index afa0b80f..6c8c9546 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,6 +1,7 @@ -use crate::options::ConfigColours; use once_cell::sync::Lazy; +use crate::options::ConfigColours; + // Default widget ID pub const DEFAULT_WIDGET_ID: u64 = 56709; diff --git a/src/data_conversion.rs b/src/data_conversion.rs index 57246fa9..12f2dccd 100644 --- a/src/data_conversion.rs +++ b/src/data_conversion.rs @@ -1,6 +1,8 @@ //! This mainly concerns converting collected data into things that the canvas //! can actually handle. +use kstring::KString; + use crate::app::data_farmer::DataCollection; use crate::app::data_harvester::cpu::CpuDataType; use crate::app::{ @@ -11,8 +13,6 @@ use crate::components::tui_widget::time_chart::Point; use crate::utils::gen_util::*; use crate::{app::AxisScaling, units::data_units::DataUnit}; -use kstring::KString; - #[derive(Default, Debug)] pub struct ConvertedBatteryData { pub battery_name: String, diff --git a/src/lib.rs b/src/lib.rs index 0d7ce656..a565ad93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,13 @@ use std::{ time::{Duration, Instant}, }; +use app::{ + data_harvester, + frozen_state::FrozenState, + layout_manager::{UsedWidgets, WidgetDirection}, + App, +}; +use constants::*; use crossterm::{ event::{ poll, read, DisableBracketedPaste, DisableMouseCapture, Event, KeyCode, KeyEvent, @@ -34,17 +41,8 @@ use crossterm::{ style::Print, terminal::{disable_raw_mode, LeaveAlternateScreen}, }; - -use flume::{Receiver, Sender}; - -use app::{ - data_harvester, - frozen_state::FrozenState, - layout_manager::{UsedWidgets, WidgetDirection}, - App, -}; -use constants::*; use data_conversion::*; +use flume::{Receiver, Sender}; use options::*; use utils::error; diff --git a/src/options.rs b/src/options.rs index ea94cc51..cc8b57f3 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,5 +1,3 @@ -use regex::Regex; -use serde::{Deserialize, Serialize}; use std::{ borrow::Cow, collections::{HashMap, HashSet}, @@ -8,6 +6,11 @@ use std::{ time::Instant, }; +use layout_options::*; +use regex::Regex; +use serde::{Deserialize, Serialize}; +use typed_builder::*; + use crate::{ app::{ layout_manager::*, @@ -23,10 +26,6 @@ use crate::{ utils::error::{self, BottomError}, }; -use typed_builder::*; - -use layout_options::*; - pub mod layout_options; use anyhow::{Context, Result}; diff --git a/src/options/layout_options.rs b/src/options/layout_options.rs index 025af157..93c2199a 100644 --- a/src/options/layout_options.rs +++ b/src/options/layout_options.rs @@ -1,6 +1,7 @@ +use serde::{Deserialize, Serialize}; + use crate::app::layout_manager::*; use crate::error::Result; -use serde::{Deserialize, Serialize}; /// Represents a row. This has a length of some sort (optional) and a vector /// of children. diff --git a/src/utils/error.rs b/src/utils/error.rs index 3c61d14b..603fabfc 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -1,4 +1,5 @@ use std::{borrow::Cow, result}; + use thiserror::Error; #[cfg(target_os = "linux")]