summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClementTsang <cjhtsang@uwaterloo.ca>2020-02-13 21:06:11 -0500
committerClementTsang <cjhtsang@uwaterloo.ca>2020-02-13 21:06:11 -0500
commitfe5f911ad3fd697eabebfc40d2958b5a3390ded2 (patch)
tree0841c923d3dd9221e64ccd2c7ceaf47b03fdf5be /src
parent5ad522be43f40888ca45ed732799d3d8f74c7a18 (diff)
Added ability to set default highlighted widget.
Diffstat (limited to 'src')
-rw-r--r--src/app.rs4
-rw-r--r--src/main.rs53
2 files changed, 55 insertions, 2 deletions
diff --git a/src/app.rs b/src/app.rs
index 99ea5ee7..d971a6a7 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -184,13 +184,13 @@ impl App {
pub fn new(
show_average_cpu: bool, temperature_type: temperature::TemperatureType,
update_rate_in_milliseconds: u64, use_dot: bool, left_legend: bool,
- use_current_cpu_total: bool,
+ use_current_cpu_total: bool, current_widget_selected: WidgetPosition,
) -> App {
App {
process_sorting_type: processes::ProcessSorting::CPU,
process_sorting_reverse: true,
update_process_gui: false,
- current_widget_selected: WidgetPosition::Process,
+ current_widget_selected,
app_scroll_positions: AppScrollState::default(),
data: data_harvester::Data::default(),
awaiting_second_char: false,
diff --git a/src/main.rs b/src/main.rs
index 1ff556c4..1841a3d3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -71,6 +71,7 @@ struct ConfigFlags {
case_sensitive: Option<bool>,
whole_word: Option<bool>,
regex: Option<bool>,
+ default_widget: Option<String>,
}
#[derive(Default, Deserialize)]
@@ -112,6 +113,14 @@ fn get_matches() -> clap::ArgMatches<'static> {
(@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 REGEX_DEFAULT: -R --regex "Use regex in searching by default.")
+ (@group DEFAULT_WIDGET =>
+ (@arg CPU_WIDGET: --cpu_default "Selects the CPU widget to be selected by default.")
+ (@arg MEM_WIDGET: --memory_default "Selects the memory widget to be selected by default.")
+ (@arg DISK_WIDGET: --disk_default "Selects the disk widget to be selected by default.")
+ (@arg TEMP_WIDGET: --temperature_default "Selects the temp widget to be selected by default.")
+ (@arg NET_WIDGET: --network_default "Selects the network widget to be selected by default.")
+ (@arg PROC_WIDGET: --process_default "Selects the process widget to be selected by default. This is the default if nothing is set.")
+ )
)
.get_matches()
}
@@ -132,6 +141,7 @@ fn main() -> error::Result<()> {
let use_dot = get_use_dot_option(&matches, &config);
let left_legend = get_use_left_legend_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);
// Create "app" struct, which will control most of the program and store settings/state
let mut app = app::App::new(
@@ -141,6 +151,7 @@ fn main() -> error::Result<()> {
use_dot,
left_legend,
use_current_cpu_total,
+ current_widget_selected,
);
enable_app_grouping(&matches, &config, &mut app);
@@ -559,6 +570,48 @@ fn enable_app_use_regex(matches: &clap::ArgMatches<'static>, config: &Config, ap
}
}
+fn get_default_widget(matches: &clap::ArgMatches<'static>, config: &Config) -> app::WidgetPosition {
+ if matches.is_present("CPU_WIDGET") {
+ return app::WidgetPosition::Cpu;
+ } else if matches.is_present("MEM_WIDGET") {
+ return app::WidgetPosition::Mem;
+ } else if matches.is_present("DISK_WIDGET") {
+ return app::WidgetPosition::Disk;
+ } else if matches.is_present("TEMP_WIDGET") {
+ return app::WidgetPosition::Temp;
+ } else if matches.is_present("NET_WIDGET") {
+ return app::WidgetPosition::Network;
+ } else if matches.is_present("PROC_WIDGET") {
+ return app::WidgetPosition::Process;
+ } else if let Some(flags) = &config.flags {
+ if let Some(default_widget) = &flags.default_widget {
+ match default_widget.to_lowercase().as_str() {
+ "cpu_default" => {
+ return app::WidgetPosition::Cpu;
+ }
+ "memory_default" => {
+ return app::WidgetPosition::Mem;
+ }
+ "processes_default" => {
+ return app::WidgetPosition::Process;
+ }
+ "network_default" => {
+ return app::WidgetPosition::Network;
+ }
+ "temperature_default" => {
+ return app::WidgetPosition::Temp;
+ }
+ "disk_default" => {
+ return app::WidgetPosition::Disk;
+ }
+ _ => {}
+ }
+ }
+ }
+
+ app::WidgetPosition::Process
+}
+
fn try_drawing(
terminal: &mut tui::terminal::Terminal<tui::backend::CrosstermBackend<std::io::Stdout>>,
app: &mut app::App, painter: &mut canvas::Painter,