Update highlight to light blue; new network legend

This commit is contained in:
ClementTsang 2020-04-18 19:50:31 -04:00
parent 92315ea1d7
commit 7248298995
9 changed files with 56 additions and 23 deletions

View file

@ -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:

View file

@ -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).

View file

@ -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),

View file

@ -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! {

View file

@ -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,
);
}

View file

@ -42,20 +42,24 @@ impl NetworkGraphWidget for Painter {
fn draw_network<B: Backend>(
&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<B: Backend>(
@ -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,
);
}

View file

@ -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"

View file

@ -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()

View file

@ -40,6 +40,7 @@ pub struct ConfigFlags {
pub hide_time: Option<bool>,
pub default_widget_type: Option<String>,
pub default_widget_count: Option<u64>,
pub use_old_network_legend: Option<bool>,
//disabled_cpu_cores: Option<Vec<u64>>, // 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
}