diff options
Diffstat (limited to 'src/canvas/canvas_colours/colour_utils.rs')
-rw-r--r-- | src/canvas/canvas_colours/colour_utils.rs | 60 |
1 files changed, 10 insertions, 50 deletions
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<Style> { - fn gen_hsv(h: f32) -> f32 { - let new_val = h + GOLDEN_RATIO; - if new_val > 1.0 { - new_val.fract() - } else { - new_val - } - } - /// This takes in an h, s, and v value of range [0, 1] - /// For explanation of what this does, see - /// https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative - fn hsv_to_rgb(hue: f32, saturation: f32, value: f32) -> (u8, u8, u8) { - fn hsv_helper(num: u32, hu: f32, sat: f32, val: f32) -> f32 { - let k = (num as f32 + hu * 6.0) % 6.0; - val - val * sat * float_max(float_min(k, float_min(4.1 - k, 1.1)), 0.0) - } - - ( - (hsv_helper(5, hue, saturation, value) * 255.0) as u8, - (hsv_helper(3, hue, saturation, value) * 255.0) as u8, - (hsv_helper(1, hue, saturation, value) * 255.0) as u8, - ) - } - - // Generate colours - // Why do we need so many colours? Because macOS default terminal - // throws a tantrum if you don't give it supported colours, but so - // does PowerShell with some colours (Magenta and Yellow)! - let mut colour_vec: Vec<Style> = vec![ - Style::default().fg(STANDARD_FIRST_COLOUR), - Style::default().fg(STANDARD_SECOND_COLOUR), - Style::default().fg(STANDARD_THIRD_COLOUR), - Style::default().fg(STANDARD_FOURTH_COLOUR), +/// We take basically no chances with this. If the user wants prettier colours, they can +/// set it on their own - unfortunately, supported colour detection is kinda a PITA. +pub fn get_default_cpu_colours() -> Vec<Style> { + vec![ + Style::default().fg(Color::LightMagenta), + Style::default().fg(Color::LightYellow), + Style::default().fg(Color::LightCyan), + Style::default().fg(Color::LightGreen), Style::default().fg(Color::LightBlue), Style::default().fg(Color::LightRed), Style::default().fg(Color::Cyan), Style::default().fg(Color::Green), Style::default().fg(Color::Blue), Style::default().fg(Color::Red), - ]; - - let mut h: f32 = 0.4; // We don't need random colours... right? - if num_to_gen - 10 > 0 { - for _i in 0..(num_to_gen - 10) { - h = gen_hsv(h); - let result = hsv_to_rgb(h, 0.5, 0.95); - colour_vec.push(Style::default().fg(Color::Rgb(result.0, result.1, result.2))); - } - } - - colour_vec + ] } pub fn convert_hex_to_color(hex: &str) -> error::Result<Color> { |