From f3897f0538f90c682b96bc340c3c05e80be10b2d Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Sat, 15 Aug 2020 17:35:49 -0700 Subject: feature: Allow sorting by any column This feature allows any column to be sortable. This also adds: - Inverting sort for current column with `I` - Invoking a sort widget with `s` or `F6`. Close with same key or esc. And: - A bugfix in regards the basic menu and battery widget - A lot of refactoring --- src/options.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/options.rs') diff --git a/src/options.rs b/src/options.rs index 634a478f..81ac4c99 100644 --- a/src/options.rs +++ b/src/options.rs @@ -180,8 +180,7 @@ pub fn build_app( battery_state_map .insert(widget.widget_id, BatteryWidgetState::default()); } - Empty | BasicCpu | BasicMem | BasicNet | BasicTables | ProcSearch - | CpuLegend => {} + _ => {} } } } @@ -262,7 +261,17 @@ pub fn get_widget_layout( let bottom_layout = if get_use_basic_mode(matches, config) { default_widget_id = DEFAULT_WIDGET_ID; BottomLayout::init_basic_default(get_use_battery(matches, config)) - } else if let Some(rows) = &config.row { + } else { + let ref_row: Vec; // Required to handle reference + let rows = match &config.row { + Some(r) => r, + None => { + // This cannot (like it really shouldn't) fail! + ref_row = toml::from_str::(DEFAULT_LAYOUT)?.row.unwrap(); + &ref_row + } + }; + let mut iter_id = 0; // A lazy way of forcing unique IDs *shrugs* let mut total_height_ratio = 0; @@ -286,15 +295,14 @@ pub fn get_widget_layout( // Confirm that we have at least ONE widget - if not, error out! if iter_id > 0 { ret_bottom_layout.get_movement_mappings(); + // debug!("Bottom layout: {:#?}", ret_bottom_layout); + ret_bottom_layout } else { return Err(error::BottomError::ConfigError( "invalid layout config: please have at least one widget.".to_string(), )); } - } else { - default_widget_id = DEFAULT_WIDGET_ID; - BottomLayout::init_default(left_legend, get_use_battery(matches, config)) }; Ok((bottom_layout, default_widget_id)) -- cgit v1.2.3