diff --git a/sample_configs/default_config.toml b/sample_configs/default_config.toml index bab1833d..3df841e5 100644 --- a/sample_configs/default_config.toml +++ b/sample_configs/default_config.toml @@ -43,6 +43,8 @@ # Override layout default widget #default_widget_type = "proc" #default_widget_count = 1 +# Expand selected widget upon starting the app +#expanded_on_startup = true # Use basic mode #basic = false # Use the old network legend style diff --git a/src/app.rs b/src/app.rs index 5c41249a..a2bffe95 100644 --- a/src/app.rs +++ b/src/app.rs @@ -123,7 +123,7 @@ pub struct App { #[builder(default, setter(skip))] pub help_dialog_state: AppHelpDialogState, - #[builder(default = false, setter(skip))] + #[builder(default = false)] pub is_expanded: bool, #[builder(default = false, setter(skip))] diff --git a/src/clap.rs b/src/clap.rs index 19922458..1d11096d 100644 --- a/src/clap.rs +++ b/src/clap.rs @@ -316,6 +316,12 @@ use CPU (3) as the default instead. .help("Sets the default widget type, use --help for info.") .long_help(DEFAULT_WIDGET_TYPE_STR); + let expanded_on_startup = Arg::new("expanded_on_startup") + .long("expanded") + .short('e') + .help("Expand selected widget upon starting the app.") + .long_help("Expand selected widget upon starting the app. Same as pressing \"e\" inside the app. Use with \"default_widget_type\" and \"default_widget_count\" to select desired expanded widget. This flag has no effect in basic mode (--basic)"); + let rate = Arg::new("rate") .short('r') .long("rate") @@ -407,7 +413,8 @@ use CPU (3) as the default instead. .arg(unnormalized_cpu) .arg(use_old_network_legend) .arg(whole_word) - .arg(retention); + .arg(retention) + .arg(expanded_on_startup); #[cfg(feature = "battery")] { diff --git a/src/constants.rs b/src/constants.rs index b42bbfab..4c5fac59 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -518,6 +518,8 @@ pub const CONFIG_TEXT: &str = r##"# This is a default config file for bottom. A # Override layout default widget #default_widget_type = "proc" #default_widget_count = 1 +# Expand selected widget upon starting the app +#expanded_on_startup = true # Use basic mode #basic = false # Use the old network legend style diff --git a/src/options.rs b/src/options.rs index 8a07d6b1..c5010976 100644 --- a/src/options.rs +++ b/src/options.rs @@ -71,6 +71,7 @@ pub struct ConfigFlags { pub hide_time: Option, pub default_widget_type: Option, pub default_widget_count: Option, + pub expanded_on_startup: Option, pub use_old_network_legend: Option, pub hide_table_gap: Option, pub battery: Option, @@ -406,6 +407,8 @@ pub fn build_app( let net_filter = get_ignore_list(&config.net_filter).context("Update 'net_filter' in your config file")?; + let expanded_upon_startup = get_expanded_on_startup(matches, config); + Ok(App::builder() .app_config_fields(app_config_fields) .cpu_state(CpuState::init(cpu_state_map)) @@ -419,6 +422,7 @@ pub fn build_app( .current_widget(widget_map.get(&initial_widget_id).unwrap().clone()) // TODO: [UNWRAP] - many of the unwraps are fine (like this one) but do a once-over and/or switch to expect? .widget_map(widget_map) .used_widgets(used_widgets) + .is_expanded(expanded_upon_startup && !use_basic_mode) .filters(DataFilters { disk_filter, mount_filter, @@ -751,6 +755,15 @@ fn get_autohide_time(matches: &ArgMatches, config: &Config) -> bool { false } +fn get_expanded_on_startup(matches: &ArgMatches, config: &Config) -> bool { + matches.is_present("expanded_on_startup") + || config + .flags + .as_ref() + .and_then(|x| x.expanded_on_startup) + .unwrap_or(false) +} + fn get_default_widget_and_count( matches: &ArgMatches, config: &Config, ) -> error::Result<(Option, u64)> {