Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding default expanded option to commandline and config (closes #822) #919

Merged
merged 3 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn main() -> Result<()> {
.context("Unable to properly parse or create the config file.")?;

// Get widget layout separately
let (widget_layout, default_widget_id, default_widget_type_option) =
let (widget_layout, default_widget_id, default_widget_type_option, expanded_on_startup) =
get_widget_layout(&matches, &config)
.context("Found an issue while trying to build the widget layout.")?;

Expand All @@ -65,6 +65,7 @@ fn main() -> Result<()> {
&widget_layout,
default_widget_id,
&default_widget_type_option,
expanded_on_startup,
&colours,
)?;

Expand Down
8 changes: 7 additions & 1 deletion src/clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ 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("Expanded 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.");
ClementTsang marked this conversation as resolved.
Show resolved Hide resolved

let rate = Arg::new("rate")
.short('r')
.long("rate")
Expand Down Expand Up @@ -407,7 +412,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
1 change: 1 addition & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ 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
#expanded_on_startup = false
ClementTsang marked this conversation as resolved.
Show resolved Hide resolved
# Use basic mode
#basic = false
# Use the old network legend style
Expand Down
24 changes: 21 additions & 3 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 @@ -172,7 +173,7 @@ pub struct IgnoreList {
pub fn build_app(
matches: &ArgMatches, config: &mut Config, widget_layout: &BottomLayout,
default_widget_id: u64, default_widget_type_option: &Option<BottomWidgetType>,
colours: &CanvasColours,
expanded_upon_startup: bool, colours: &CanvasColours,
ClementTsang marked this conversation as resolved.
Show resolved Hide resolved
) -> Result<App> {
use BottomWidgetType::*;

Expand Down Expand Up @@ -419,6 +420,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)
ClementTsang marked this conversation as resolved.
Show resolved Hide resolved
.filters(DataFilters {
disk_filter,
mount_filter,
Expand All @@ -430,7 +432,7 @@ pub fn build_app(

pub fn get_widget_layout(
matches: &ArgMatches, config: &Config,
) -> error::Result<(BottomLayout, u64, Option<BottomWidgetType>)> {
) -> error::Result<(BottomLayout, u64, Option<BottomWidgetType>, bool)> {
let left_legend = get_use_left_legend(matches, config);
let (default_widget_type, mut default_widget_count) =
get_default_widget_and_count(matches, config)?;
Expand Down Expand Up @@ -490,7 +492,14 @@ pub fn get_widget_layout(
}
};

Ok((bottom_layout, default_widget_id, default_widget_type))
let expanded_upon_startup = get_expanded_on_startup(matches, config);

Ok((
bottom_layout,
default_widget_id,
default_widget_type,
expanded_upon_startup,
))
}

fn get_update_rate_in_milliseconds(matches: &ArgMatches, config: &Config) -> error::Result<u64> {
Expand Down Expand Up @@ -751,6 +760,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