diff --git a/CHANGELOG.md b/CHANGELOG.md index eccc4f20..e710bcf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changes -- Changed default colours for highlighted borders and table headers to cyan - this is mostly to deal with Powershell colour conflicts. +- Changed default colours for highlighted borders and table headers to light blue - this is mostly to deal with Powershell colour conflicts. - Updated the widget type keyword list to accept the following keywords as existing types: diff --git a/src/app.rs b/src/app.rs index d2aeb005..ad040fc6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -90,6 +90,7 @@ pub struct AppConfigFields { pub time_interval: u64, pub hide_time: bool, pub autohide_time: bool, + pub use_old_network_legend: bool, } /// AppSearchState deals with generic searching (I might do this in the future). diff --git a/src/canvas/canvas_colours.rs b/src/canvas/canvas_colours.rs index 169bde02..dbcc46c5 100644 --- a/src/canvas/canvas_colours.rs +++ b/src/canvas/canvas_colours.rs @@ -35,8 +35,8 @@ impl Default for CanvasColours { CanvasColours { currently_selected_text_colour: Color::Black, currently_selected_bg_colour: Color::Cyan, - currently_selected_text_style: Style::default().fg(Color::Black).bg(Color::Cyan), - table_header_style: Style::default().fg(Color::Cyan), + currently_selected_text_style: Style::default().fg(Color::Black).bg(STANDARD_HIGHLIGHT_COLOUR), + table_header_style: Style::default().fg(STANDARD_HIGHLIGHT_COLOUR), ram_style: Style::default().fg(STANDARD_FIRST_COLOUR), swap_style: Style::default().fg(STANDARD_SECOND_COLOUR), rx_style: Style::default().fg(STANDARD_FIRST_COLOUR), @@ -46,7 +46,7 @@ impl Default for CanvasColours { avg_colour_style: Style::default().fg(AVG_COLOUR), cpu_colour_styles: Vec::new(), border_style: Style::default().fg(text_colour), - highlighted_border_style: Style::default().fg(Color::Cyan), + highlighted_border_style: Style::default().fg(STANDARD_HIGHLIGHT_COLOUR), text_style: Style::default().fg(text_colour), widget_title_style: Style::default().fg(text_colour), graph_style: Style::default().fg(text_colour), diff --git a/src/canvas/canvas_colours/colour_utils.rs b/src/canvas/canvas_colours/colour_utils.rs index 83c3f18a..0d1af937 100644 --- a/src/canvas/canvas_colours/colour_utils.rs +++ b/src/canvas/canvas_colours/colour_utils.rs @@ -11,6 +11,7 @@ pub const STANDARD_FIRST_COLOUR: Color = Color::LightMagenta; pub const STANDARD_SECOND_COLOUR: Color = Color::LightYellow; pub const STANDARD_THIRD_COLOUR: Color = Color::LightCyan; pub const STANDARD_FOURTH_COLOUR: Color = Color::LightGreen; +pub const STANDARD_HIGHLIGHT_COLOUR: Color = Color::LightBlue; pub const AVG_COLOUR: Color = Color::Red; lazy_static! { diff --git a/src/canvas/widgets/mem_graph.rs b/src/canvas/widgets/mem_graph.rs index 10eba3d0..7b70d430 100644 --- a/src/canvas/widgets/mem_graph.rs +++ b/src/canvas/widgets/mem_graph.rs @@ -4,7 +4,7 @@ use crate::{app::App, canvas::Painter, constants::*}; use tui::{ backend::Backend, - layout::Rect, + layout::{Constraint, Rect}, symbols::Marker, terminal::Frame, widgets::{Axis, Block, Borders, Chart, Dataset}, @@ -117,7 +117,8 @@ impl MemGraphWidget for Painter { ) .x_axis(x_axis) .y_axis(y_axis) - .datasets(&mem_canvas_vec), + .datasets(&mem_canvas_vec) + .hidden_legend_constraints((Constraint::Ratio(3, 4), Constraint::Ratio(3, 4))), draw_loc, ); } diff --git a/src/canvas/widgets/network_graph.rs b/src/canvas/widgets/network_graph.rs index b40075f3..30b1634b 100644 --- a/src/canvas/widgets/network_graph.rs +++ b/src/canvas/widgets/network_graph.rs @@ -42,20 +42,24 @@ impl NetworkGraphWidget for Painter { fn draw_network( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, ) { - let network_chunk = Layout::default() - .direction(Direction::Vertical) - .margin(0) - .constraints( - [ - Constraint::Length(max(draw_loc.height as i64 - 5, 0) as u16), - Constraint::Length(5), - ] - .as_ref(), - ) - .split(draw_loc); + if app_state.app_config_fields.use_old_network_legend { + let network_chunk = Layout::default() + .direction(Direction::Vertical) + .margin(0) + .constraints( + [ + Constraint::Length(max(draw_loc.height as i64 - 5, 0) as u16), + Constraint::Length(5), + ] + .as_ref(), + ) + .split(draw_loc); - self.draw_network_graph(f, app_state, network_chunk[0], widget_id); - self.draw_network_labels(f, app_state, network_chunk[1], widget_id); + self.draw_network_graph(f, app_state, network_chunk[0], widget_id); + self.draw_network_labels(f, app_state, network_chunk[1], widget_id); + } else { + self.draw_network_graph(f, app_state, draw_loc, widget_id); + } } fn draw_network_graph( @@ -119,6 +123,12 @@ impl NetworkGraphWidget for Painter { " Network ".to_string() }; + let legend_constraints = if app_state.app_config_fields.use_old_network_legend { + (Constraint::Ratio(0, 1), Constraint::Ratio(0, 1)) + } else { + (Constraint::Ratio(3, 4), Constraint::Ratio(3, 4)) + }; + f.render_widget( Chart::default() .block( @@ -169,7 +179,8 @@ impl NetworkGraphWidget for Painter { app_state.canvas_data.total_tx_display )) .style(self.colours.total_tx_style), - ]), + ]) + .hidden_legend_constraints(legend_constraints), draw_loc, ); } diff --git a/src/constants.rs b/src/constants.rs index 1fc0e972..d5f165d7 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -150,6 +150,9 @@ pub const DEFAULT_CONFIG_CONTENT: &str = r##" # Use basic mode #basic = false +# Use the old network legend style +#use_old_network_legend = true + ########################################################## # These are all the components that support custom theming. Note that colour support @@ -158,7 +161,7 @@ pub const DEFAULT_CONFIG_CONTENT: &str = r##" [colors] # Represents the colour of table headers (processes, CPU, disks, temperature). -#table_header_color="Cyan" +#table_header_color="Light Blue" # Represents the colour of the label each widget has. #widget_title_color="Gray" @@ -185,7 +188,7 @@ pub const DEFAULT_CONFIG_CONTENT: &str = r##" #border_color="Gray" # Represents the colour of the border of selected widgets. -#highlighted_border_color="Cyan" +#highlighted_border_color="Light Blue" # Represents the colour of most text. #text_color="Gray" @@ -194,7 +197,7 @@ pub const DEFAULT_CONFIG_CONTENT: &str = r##" #selected_text_color="Black" # Represents the background colour of text that is selected. -#selected_bg_color="Cyan" +#selected_bg_color="Light Blue" # Represents the colour of the lines and text of the graph. #graph_color="Gray" diff --git a/src/main.rs b/src/main.rs index db2ca467..1e19faa3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,6 +89,7 @@ fn get_matches() -> clap::ArgMatches<'static> { (@arg AUTOHIDE_TIME: --autohide_time "Automatically hide the time scaling in graphs after being shown for a brief moment when zoomed in/out. If time is disabled via --hide_time then this will have no effect.") (@arg DEFAULT_WIDGET_TYPE: --default_widget_type +takes_value "The default widget type to select by default.") (@arg DEFAULT_WIDGET_COUNT: --default_widget_count +takes_value "Which number of the selected widget type to select, from left to right, top to bottom. Defaults to 1.") + (@arg USE_OLD_NETWORK_LEGEND: --use_old_network_legend "Use the old network widget legend.") //(@arg TURNED_OFF_CPUS: -t ... +takes_value "Hides CPU data points by default") // TODO: [FEATURE] Enable disabling cores in config/flags ) .get_matches() diff --git a/src/options.rs b/src/options.rs index 987d6f0e..86110a49 100644 --- a/src/options.rs +++ b/src/options.rs @@ -40,6 +40,7 @@ pub struct ConfigFlags { pub hide_time: Option, pub default_widget_type: Option, pub default_widget_count: Option, + pub use_old_network_legend: Option, //disabled_cpu_cores: Option>, // TODO: [FEATURE] Enable disabling cores in config/flags } @@ -216,6 +217,7 @@ pub fn build_app( time_interval: get_time_interval(matches, config)?, hide_time: get_hide_time(matches, config), autohide_time, + use_old_network_legend: get_use_old_network_legend(matches, config), }; let used_widgets = UsedWidgets { @@ -603,3 +605,16 @@ fn get_default_widget_and_count( Ok((None, 1)) } } + +pub fn get_use_old_network_legend(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { + if matches.is_present("USE_OLD_NETWORK_LEGEND") { + return true; + } else if let Some(flags) = &config.flags { + if let Some(use_old_network_legend) = flags.use_old_network_legend { + if use_old_network_legend { + return true; + } + } + } + false +}