summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChon Sou <35537528+sou-chon@users.noreply.github.com>2022-12-07 00:34:41 +0000
committerGitHub <noreply@github.com>2022-12-06 19:34:41 -0500
commit4272dd0c2d75ee67f6c273e3cee30ea35515e9b2 (patch)
tree37f517fc494959f37cdce94bb376933c0004ce8f /src
parent1920f4b2e11799bdef4c063a24e551ed5f2dc331 (diff)
feature: Adding default expanded option to commandline and config (#919)
* [#822] adding default expanded option to commandline and config * refactoring (#919) * nullifying default expanded when in basic mode (#919)
Diffstat (limited to 'src')
-rw-r--r--src/app.rs2
-rw-r--r--src/clap.rs9
-rw-r--r--src/constants.rs2
-rw-r--r--src/options.rs13
4 files changed, 24 insertions, 2 deletions
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<bool>,
pub default_widget_type: Option<String>,
pub default_widget_count: Option<u64>,
+ pub expanded_on_startup: Option<bool>,
pub use_old_network_legend: Option<bool>,
pub hide_table_gap: Option<bool>,
pub battery: Option<bool>,
@@ -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<BottomWidgetType>, u64)> {