Skip to content

Commit

Permalink
feature: Adding default expanded option to commandline and config (#919)
Browse files Browse the repository at this point in the history
* [#822] adding default expanded option to commandline and config

* refactoring (#919)

* nullifying default expanded when in basic mode (#919)
  • Loading branch information
sou-chon committed Dec 7, 2022
1 parent 1920f4b commit 4272dd0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions sample_configs/default_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
9 changes: 8 additions & 1 deletion src/clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")]
{
Expand Down
2 changes: 2 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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))
Expand All @@ -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,
Expand Down Expand Up @@ -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)> {
Expand Down

0 comments on commit 4272dd0

Please sign in to comment.