From bbd57400d91dfb1812f8e09b029ccabce258f6b9 Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Sat, 29 Feb 2020 16:55:02 -0500 Subject: [PATCH] Add basic flag + option. Not functional yet. --- src/app.rs | 4 +++- src/main.rs | 27 +++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/app.rs b/src/app.rs index e23938ac..26824670 100644 --- a/src/app.rs +++ b/src/app.rs @@ -180,6 +180,7 @@ pub struct AppConfigFields { pub show_average_cpu: bool, pub use_current_cpu_total: bool, pub show_disabled_data: bool, + pub use_basic_mode: bool, } /// Network specific @@ -270,7 +271,7 @@ impl App { show_average_cpu: bool, temperature_type: temperature::TemperatureType, update_rate_in_milliseconds: u64, use_dot: bool, left_legend: bool, use_current_cpu_total: bool, current_widget_selected: WidgetPosition, - show_disabled_data: bool, + show_disabled_data: bool, use_basic_mode: bool, ) -> App { App { process_sorting_type: processes::ProcessSorting::CPU, @@ -299,6 +300,7 @@ impl App { left_legend, use_current_cpu_total, show_disabled_data, + use_basic_mode }, is_expanded: false, is_resized: false, diff --git a/src/main.rs b/src/main.rs index 4cf9ab25..e281f666 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,20 +20,20 @@ use std::{ use crossterm::{ event::{ - DisableMouseCapture, EnableMouseCapture, Event as CEvent, KeyCode, KeyEvent, KeyModifiers, MouseEvent, - poll, read, + poll, read, DisableMouseCapture, EnableMouseCapture, Event as CEvent, KeyCode, KeyEvent, + KeyModifiers, MouseEvent, }, execute, style::Print, - terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen}, terminal::LeaveAlternateScreen, + terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen}, }; use serde::Deserialize; use tui::{backend::CrosstermBackend, Terminal}; use app::{ - App, data_harvester::{self, processes::ProcessSorting}, + App, }; use constants::*; use data_conversion::*; @@ -80,6 +80,7 @@ struct ConfigFlags { regex: Option, default_widget: Option, show_disabled_data: Option, + basic_mode: Option, //disabled_cpu_cores: Option>, // TODO: [FEATURE] Enable disabling cores in config/flags } @@ -120,7 +121,7 @@ fn get_matches() -> clap::ArgMatches<'static> { (@arg LEFT_LEGEND: -l --left_legend "Puts external chart legends on the left side rather than the default right side.") (@arg USE_CURR_USAGE: -u --current_usage "Within Linux, sets a process' CPU usage to be based on the total current CPU usage, rather than assuming 100% usage.") (@arg CONFIG_LOCATION: -C --config +takes_value "Sets the location of the config file. Expects a config file in the TOML format.") - //(@arg BASIC_MODE: -b --basic "Sets bottom to basic mode, not showing graphs and only showing basic tables.") // TODO: [FEATURE] Min mode + (@arg BASIC_MODE: -b --basic "Sets bottom to basic mode, not showing graphs and only showing basic tables.") (@arg GROUP_PROCESSES: -g --group "Groups processes with the same name together on launch.") (@arg CASE_SENSITIVE: -S --case_sensitive "Match case when searching by default.") (@arg WHOLE_WORD: -W --whole_word "Match whole word when searching by default.") @@ -157,6 +158,7 @@ fn main() -> error::Result<()> { let use_current_cpu_total = get_use_current_cpu_total_option(&matches, &config); let current_widget_selected = get_default_widget(&matches, &config); let show_disabled_data = get_show_disabled_data_option(&matches, &config); + let use_basic_mode = get_use_basic_mode_option(&matches, &config); // Create "app" struct, which will control most of the program and store settings/state let mut app = App::new( @@ -168,6 +170,7 @@ fn main() -> error::Result<()> { use_current_cpu_total, current_widget_selected, show_disabled_data, + use_basic_mode, ); enable_app_grouping(&matches, &config, &mut app); @@ -509,7 +512,7 @@ fn get_temperature_option( "Invalid temperature type. Please have the value be of the form ".to_string() )) } - } + }; } } Ok(data_harvester::temperature::TemperatureType::Celsius) @@ -574,6 +577,18 @@ fn get_show_disabled_data_option(matches: &clap::ArgMatches<'static>, config: &C false } +fn get_use_basic_mode_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { + if matches.is_present("BASIC_MODE") { + return true; + } else if let Some(flags) = &config.flags { + if let Some(basic_mode) = flags.basic_mode { + return basic_mode; + } + } + + false +} + fn enable_app_grouping(matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App) { if matches.is_present("GROUP_PROCESSES") { app.toggle_grouping();