mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-25 05:30:22 +00:00
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)
This commit is contained in:
parent
1920f4b2e1
commit
4272dd0c2d
5 changed files with 26 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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))]
|
||||
|
|
|
@ -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")]
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)> {
|
||||
|
|
Loading…
Reference in a new issue