diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c25a651..9ddeff40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#296](https://github.com/ClementTsang/bottom/pull/296): Removes an accidental extra comma in one of the headers in the disk widget. +- [#308](https://github.com/ClementTsang/bottom/pull/308): Removes the automatically generated CPU colours method. + ## [0.4.7] - 2020-08-26 ### Bug Fixes diff --git a/src/canvas.rs b/src/canvas.rs index 7af29f33..9bd4f96d 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -197,7 +197,6 @@ impl Painter { } else { painter.generate_colour_scheme(colour_scheme)?; } - painter.colours.generate_remaining_cpu_colours(); painter.complete_painter_init(); Ok(painter) diff --git a/src/canvas/canvas_colours.rs b/src/canvas/canvas_colours.rs index a42eb88c..fd8d4eb0 100644 --- a/src/canvas/canvas_colours.rs +++ b/src/canvas/canvas_colours.rs @@ -1,4 +1,4 @@ -use crate::{constants::*, options::ConfigColours, utils::error}; +use crate::{options::ConfigColours, utils::error}; use anyhow::Context; use colour_utils::*; use tui::style::{Color, Style}; @@ -48,7 +48,7 @@ impl Default for CanvasColours { total_tx_style: Style::default().fg(STANDARD_FOURTH_COLOUR), all_colour_style: Style::default().fg(ALL_COLOUR), avg_colour_style: Style::default().fg(AVG_COLOUR), - cpu_colour_styles: Vec::new(), + cpu_colour_styles: colour_utils::get_default_cpu_colours(), border_style: Style::default().fg(text_colour), highlighted_border_style: Style::default().fg(STANDARD_HIGHLIGHT_COLOUR), text_style: Style::default().fg(text_colour), @@ -248,22 +248,13 @@ impl CanvasColours { } pub fn set_cpu_colours(&mut self, colours: &[String]) -> error::Result<()> { - let max_amount = std::cmp::min(colours.len(), NUM_COLOURS); - for (itx, colour) in colours.iter().enumerate() { - if itx >= max_amount { - break; - } - self.cpu_colour_styles.push(get_style_from_config(colour)?); - } + self.cpu_colour_styles = colours + .iter() + .map(|colour| get_style_from_config(colour)) + .collect::>>()?; Ok(()) } - pub fn generate_remaining_cpu_colours(&mut self) { - let remaining_num_colours = NUM_COLOURS.saturating_sub(self.cpu_colour_styles.len()); - self.cpu_colour_styles - .extend(gen_n_styles(remaining_num_colours)); - } - pub fn set_scroll_entry_text_color(&mut self, colour: &str) -> error::Result<()> { self.currently_selected_text_colour = get_colour_from_config(colour)?; self.currently_selected_text_style = Style::default() diff --git a/src/canvas/canvas_colours/colour_utils.rs b/src/canvas/canvas_colours/colour_utils.rs index d104d483..048f9317 100644 --- a/src/canvas/canvas_colours/colour_utils.rs +++ b/src/canvas/canvas_colours/colour_utils.rs @@ -3,9 +3,8 @@ use std::collections::HashMap; use tui::style::{Color, Style}; -use crate::utils::{error, gen_util::*}; +use crate::utils::error; -const GOLDEN_RATIO: f32 = 0.618_034; // Approx, good enough for use (also Clippy gets mad if it's too long) pub const STANDARD_FIRST_COLOUR: Color = Color::LightMagenta; pub const STANDARD_SECOND_COLOUR: Color = Color::LightYellow; @@ -41,60 +40,21 @@ lazy_static! { .collect(); } -/// Generates random colours. Strategy found from -/// https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/ -pub fn gen_n_styles(num_to_gen: usize) -> Vec