Add ability to still show data entries in the legend even if line is disabled.

This commit is contained in:
ClementTsang 2020-02-17 12:07:43 -05:00
parent 531e6ed76e
commit c669b5337c
5 changed files with 27 additions and 1 deletions

View File

@ -100,6 +100,8 @@ Run using `btm`.
- `--cpu_default`, `--memory_default`, `--disk_default`, `--temperature_default`, `--network_default`, `--process_default` will select the corresponding widget on startup. By default the process widget is selected. - `--cpu_default`, `--memory_default`, `--disk_default`, `--temperature_default`, `--network_default`, `--process_default` will select the corresponding widget on startup. By default the process widget is selected.
- `-s`, `--show_disabled_data` will show data entries in the graph legends even if the lines for that entry are disabled.
- `-C`, `--config` takes in a file path leading to a TOML file. - `-C`, `--config` takes in a file path leading to a TOML file.
### Config Files ### Config Files

View File

@ -23,6 +23,8 @@ default_widget = "cpu_default"
#default_widget = "network_default" #default_widget = "network_default"
#default_widget = "process_default" #default_widget = "process_default"
show_disabled_data = true
[colors] [colors]
# Based on gruvbox: https://github.com/morhetz/gruvbox # Based on gruvbox: https://github.com/morhetz/gruvbox
table_header_color="#458588" table_header_color="#458588"

View File

@ -155,6 +155,7 @@ pub struct AppConfigFields {
pub left_legend: bool, pub left_legend: bool,
pub show_average_cpu: bool, pub show_average_cpu: bool,
pub use_current_cpu_total: bool, pub use_current_cpu_total: bool,
pub show_disabled_data: bool,
} }
/// Network specific /// Network specific
@ -239,10 +240,12 @@ pub struct App {
} }
impl App { impl App {
#[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
show_average_cpu: bool, temperature_type: temperature::TemperatureType, show_average_cpu: bool, temperature_type: temperature::TemperatureType,
update_rate_in_milliseconds: u64, use_dot: bool, left_legend: bool, update_rate_in_milliseconds: u64, use_dot: bool, left_legend: bool,
use_current_cpu_total: bool, current_widget_selected: WidgetPosition, use_current_cpu_total: bool, current_widget_selected: WidgetPosition,
show_disabled_data: bool,
) -> App { ) -> App {
App { App {
process_sorting_type: processes::ProcessSorting::CPU, process_sorting_type: processes::ProcessSorting::CPU,
@ -270,6 +273,7 @@ impl App {
update_rate_in_milliseconds, update_rate_in_milliseconds,
left_legend, left_legend,
use_current_cpu_total, use_current_cpu_total,
show_disabled_data,
}, },
is_expanded: false, is_expanded: false,
cpu_state: CpuState::default(), cpu_state: CpuState::default(),

View File

@ -647,7 +647,9 @@ impl Painter {
.iter() .iter()
.enumerate() .enumerate()
.filter(|(itx, _)| { .filter(|(itx, _)| {
if app_state.cpu_state.is_showing_tray { if app_state.cpu_state.is_showing_tray
|| app_state.app_config_fields.show_disabled_data
{
true true
} else { } else {
app_state.cpu_state.core_show_vec[*itx] app_state.cpu_state.core_show_vec[*itx]

View File

@ -74,6 +74,7 @@ struct ConfigFlags {
whole_word: Option<bool>, whole_word: Option<bool>,
regex: Option<bool>, regex: Option<bool>,
default_widget: Option<String>, default_widget: Option<String>,
show_disabled_data: Option<bool>,
} }
#[derive(Default, Deserialize)] #[derive(Default, Deserialize)]
@ -115,6 +116,7 @@ fn get_matches() -> clap::ArgMatches<'static> {
(@arg CASE_SENSITIVE: -S --case_sensitive "Match case when searching by default.") (@arg CASE_SENSITIVE: -S --case_sensitive "Match case when searching by default.")
(@arg WHOLE_WORD: -W --whole_word "Match whole word when searching by default.") (@arg WHOLE_WORD: -W --whole_word "Match whole word when searching by default.")
(@arg REGEX_DEFAULT: -R --regex "Use regex in searching by default.") (@arg REGEX_DEFAULT: -R --regex "Use regex in searching by default.")
(@arg SHOW_DISABLED_DATA: -s --show_disabled_data "Show disabled data entries.")
(@group DEFAULT_WIDGET => (@group DEFAULT_WIDGET =>
(@arg CPU_WIDGET: --cpu_default "Selects the CPU widget to be selected by default.") (@arg CPU_WIDGET: --cpu_default "Selects the CPU widget to be selected by default.")
(@arg MEM_WIDGET: --memory_default "Selects the memory widget to be selected by default.") (@arg MEM_WIDGET: --memory_default "Selects the memory widget to be selected by default.")
@ -144,6 +146,7 @@ fn main() -> error::Result<()> {
let left_legend = get_use_left_legend_option(&matches, &config); let left_legend = get_use_left_legend_option(&matches, &config);
let use_current_cpu_total = get_use_current_cpu_total_option(&matches, &config); let use_current_cpu_total = get_use_current_cpu_total_option(&matches, &config);
let current_widget_selected = get_default_widget(&matches, &config); let current_widget_selected = get_default_widget(&matches, &config);
let show_disabled_data = get_show_disabled_data_option(&matches, &config);
// Create "app" struct, which will control most of the program and store settings/state // Create "app" struct, which will control most of the program and store settings/state
let mut app = app::App::new( let mut app = app::App::new(
@ -154,6 +157,7 @@ fn main() -> error::Result<()> {
left_legend, left_legend,
use_current_cpu_total, use_current_cpu_total,
current_widget_selected, current_widget_selected,
show_disabled_data,
); );
enable_app_grouping(&matches, &config, &mut app); enable_app_grouping(&matches, &config, &mut app);
@ -518,6 +522,18 @@ fn get_use_current_cpu_total_option(matches: &clap::ArgMatches<'static>, config:
false false
} }
fn get_show_disabled_data_option(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
if matches.is_present("SHOW_DISABLED_DATA") {
return true;
} else if let Some(flags) = &config.flags {
if let Some(show_disabled_data) = flags.show_disabled_data {
return show_disabled_data;
}
}
false
}
fn enable_app_grouping(matches: &clap::ArgMatches<'static>, config: &Config, app: &mut app::App) { fn enable_app_grouping(matches: &clap::ArgMatches<'static>, config: &Config, app: &mut app::App) {
if matches.is_present("GROUP_PROCESSES") { if matches.is_present("GROUP_PROCESSES") {
app.toggle_grouping(); app.toggle_grouping();