Add basic flag + option. Not functional yet.

This commit is contained in:
ClementTsang 2020-02-29 16:55:02 -05:00
parent 01977fffdd
commit bbd57400d9
2 changed files with 24 additions and 7 deletions

View File

@ -180,6 +180,7 @@ pub struct AppConfigFields {
pub show_average_cpu: bool, pub show_average_cpu: bool,
pub use_current_cpu_total: bool, pub use_current_cpu_total: bool,
pub show_disabled_data: bool, pub show_disabled_data: bool,
pub use_basic_mode: bool,
} }
/// Network specific /// Network specific
@ -270,7 +271,7 @@ impl App {
show_average_cpu: bool, temperature_type: temperature::TemperatureType, show_average_cpu: bool, temperature_type: temperature::TemperatureType,
update_rate_in_milliseconds: u64, use_dot: bool, left_legend: bool, update_rate_in_milliseconds: u64, use_dot: bool, left_legend: bool,
use_current_cpu_total: bool, current_widget_selected: WidgetPosition, use_current_cpu_total: bool, current_widget_selected: WidgetPosition,
show_disabled_data: bool, show_disabled_data: bool, use_basic_mode: bool,
) -> App { ) -> App {
App { App {
process_sorting_type: processes::ProcessSorting::CPU, process_sorting_type: processes::ProcessSorting::CPU,
@ -299,6 +300,7 @@ impl App {
left_legend, left_legend,
use_current_cpu_total, use_current_cpu_total,
show_disabled_data, show_disabled_data,
use_basic_mode
}, },
is_expanded: false, is_expanded: false,
is_resized: false, is_resized: false,

View File

@ -20,20 +20,20 @@ use std::{
use crossterm::{ use crossterm::{
event::{ event::{
DisableMouseCapture, EnableMouseCapture, Event as CEvent, KeyCode, KeyEvent, KeyModifiers, MouseEvent, poll, read, DisableMouseCapture, EnableMouseCapture, Event as CEvent, KeyCode, KeyEvent,
poll, read, KeyModifiers, MouseEvent,
}, },
execute, execute,
style::Print, style::Print,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen},
terminal::LeaveAlternateScreen, terminal::LeaveAlternateScreen,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen},
}; };
use serde::Deserialize; use serde::Deserialize;
use tui::{backend::CrosstermBackend, Terminal}; use tui::{backend::CrosstermBackend, Terminal};
use app::{ use app::{
App,
data_harvester::{self, processes::ProcessSorting}, data_harvester::{self, processes::ProcessSorting},
App,
}; };
use constants::*; use constants::*;
use data_conversion::*; use data_conversion::*;
@ -80,6 +80,7 @@ struct ConfigFlags {
regex: Option<bool>, regex: Option<bool>,
default_widget: Option<String>, default_widget: Option<String>,
show_disabled_data: Option<bool>, show_disabled_data: Option<bool>,
basic_mode: Option<bool>,
//disabled_cpu_cores: Option<Vec<u64>>, // TODO: [FEATURE] Enable disabling cores in config/flags //disabled_cpu_cores: Option<Vec<u64>>, // 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 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 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 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 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 CASE_SENSITIVE: -S --case_sensitive "Match case when searching by default.")
(@arg WHOLE_WORD: -W --whole_word "Match whole word 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 use_current_cpu_total = get_use_current_cpu_total_option(&matches, &config);
let current_widget_selected = get_default_widget(&matches, &config); let current_widget_selected = get_default_widget(&matches, &config);
let show_disabled_data = get_show_disabled_data_option(&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 // Create "app" struct, which will control most of the program and store settings/state
let mut app = App::new( let mut app = App::new(
@ -168,6 +170,7 @@ fn main() -> error::Result<()> {
use_current_cpu_total, use_current_cpu_total,
current_widget_selected, current_widget_selected,
show_disabled_data, show_disabled_data,
use_basic_mode,
); );
enable_app_grouping(&matches, &config, &mut app); 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 <kelvin|k|celsius|c|fahrenheit|f>".to_string() "Invalid temperature type. Please have the value be of the form <kelvin|k|celsius|c|fahrenheit|f>".to_string()
)) ))
} }
} };
} }
} }
Ok(data_harvester::temperature::TemperatureType::Celsius) Ok(data_harvester::temperature::TemperatureType::Celsius)
@ -574,6 +577,18 @@ fn get_show_disabled_data_option(matches: &clap::ArgMatches<'static>, config: &C
false 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) { fn enable_app_grouping(matches: &clap::ArgMatches<'static>, config: &Config, app: &mut App) {
if matches.is_present("GROUP_PROCESSES") { if matches.is_present("GROUP_PROCESSES") {
app.toggle_grouping(); app.toggle_grouping();