Made it "easier" to change colors

This commit is contained in:
jpk 2022-12-12 17:39:41 +01:00
parent 770f9a04a2
commit c4353a4d03
1 changed files with 32 additions and 16 deletions

View File

@ -2,47 +2,57 @@ extern crate termion;
use termion::color; use termion::color;
const COLOR_SYMBOLS: color::Fg<color::LightGreen> = color::Fg(color::LightGreen);
const COLOR_TEXT: color::Fg<color::Cyan> = color::Fg(color::Cyan);
const COLOR_NUMBERS: color::Fg<color::LightBlue> = color::Fg(color::LightBlue);
pub fn map_u8_to_color(data: u8) -> String { pub fn map_u8_to_color(data: u8) -> String {
match data { match data {
32..=47 => format!( 32..=47 => format!(
"{}{:02x}{}", "{}{:02x}{}",
color::Fg(color::Yellow), COLOR_SYMBOLS,
data, data,
color::Fg(color::Reset) color::Fg(color::Reset)
), ),
48..=64 => format!( 48..=57 => format!(
"{}{:02x}{}", "{}{:02x}{}",
color::Fg(color::Green), COLOR_NUMBERS,
data,
color::Fg(color::Reset)
),
58..=64 => format!(
"{}{:02x}{}",
COLOR_SYMBOLS,
data, data,
color::Fg(color::Reset) color::Fg(color::Reset)
), ),
65..=90 => format!( 65..=90 => format!(
"{}{:02x}{}", "{}{:02x}{}",
color::Fg(color::Blue), COLOR_TEXT,
data, data,
color::Fg(color::Reset) color::Fg(color::Reset)
), ),
91..=96 => format!( 91..=96 => format!(
"{}{:02x}{}", "{}{:02x}{}",
color::Fg(color::Yellow), COLOR_SYMBOLS,
data, data,
color::Fg(color::Reset) color::Fg(color::Reset)
), ),
97..=122 => format!( 97..=122 => format!(
"{}{:02x}{}", "{}{:02x}{}",
color::Fg(color::Blue), COLOR_TEXT,
data, data,
color::Fg(color::Reset) color::Fg(color::Reset)
), ),
123..=126 => format!( 123..=126 => format!(
"{}{:02x}{}", "{}{:02x}{}",
color::Fg(color::Yellow), COLOR_SYMBOLS,
data, data,
color::Fg(color::Reset) color::Fg(color::Reset)
), ),
_ => format!( _ => format!(
"{}{:02x}{}", "{}{:02x}{}",
color::Fg(color::LightRed), color::Fg(color::LightBlack),
data, data,
color::Fg(color::Reset) color::Fg(color::Reset)
), ),
@ -53,40 +63,46 @@ pub fn map_char_to_color(data: u8) -> String {
match data { match data {
32..=47 => format!( 32..=47 => format!(
"{}{}{}", "{}{}{}",
color::Fg(color::Yellow), COLOR_SYMBOLS,
(data as char), (data as char),
color::Fg(color::Reset) color::Fg(color::Reset)
), ),
48..=64 => format!( 48..=57 => format!(
"{}{}{}", "{}{}{}",
color::Fg(color::Green), COLOR_NUMBERS,
(data as char),
color::Fg(color::Reset)
),
58..=64 => format!(
"{}{}{}",
COLOR_SYMBOLS,
(data as char), (data as char),
color::Fg(color::Reset) color::Fg(color::Reset)
), ),
65..=90 => format!( 65..=90 => format!(
"{}{}{}", "{}{}{}",
color::Fg(color::Blue), COLOR_TEXT,
(data as char), (data as char),
color::Fg(color::Reset) color::Fg(color::Reset)
), ),
91..=96 => format!( 91..=96 => format!(
"{}{}{}", "{}{}{}",
color::Fg(color::Yellow), COLOR_SYMBOLS,
(data as char), (data as char),
color::Fg(color::Reset) color::Fg(color::Reset)
), ),
97..=122 => format!( 97..=122 => format!(
"{}{}{}", "{}{}{}",
color::Fg(color::Blue), COLOR_TEXT,
(data as char), (data as char),
color::Fg(color::Reset) color::Fg(color::Reset)
), ),
123..=126 => format!( 123..=126 => format!(
"{}{}{}", "{}{}{}",
color::Fg(color::Yellow), COLOR_SYMBOLS,
(data as char), (data as char),
color::Fg(color::Reset) color::Fg(color::Reset)
), ),
_ => format!("{}.{}", color::Fg(color::LightRed), color::Fg(color::Reset)), _ => format!("{}.{}", color::Fg(color::LightBlack), color::Fg(color::Reset)),
} }
} }