use std::borrow::Cow;
use std::fmt;
const BLACK: &str = "black";
const RED: &str = "red";
const GREEN: &str = "green";
const YELLOW: &str = "yellow";
const BLUE: &str = "blue";
const MAGENTA: &str = "magenta";
const CYAN: &str = "cyan";
const WHITE: &str = "white";
const BRIGHTRED: &str = "brightred";
const BRIGHTGREEN: &str = "brightgreen";
const BRIGHTYELLOW: &str = "brightyellow";
const DEFAULT: &str = "default";
const TERMINAL: &str = "terminal";
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub enum Colour {
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
BrightRed,
BrightGreen,
BrightYellow,
ColourSet256(u8),
Default,
Terminal,
HEX(u32),
}
impl fmt::Display for Colour {
fn fmt<'a>(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s: Cow<'a, str> = match self {
Self::Black => BLACK.into(),
Self::Red => RED.into(),
Self::Green => GREEN.into(),
Self::Yellow => YELLOW.into(),
Self::Blue => BLUE.into(),
Self::Magenta => MAGENTA.into(),
Self::Cyan => CYAN.into(),
Self::White => WHITE.into(),
Self::BrightRed => BRIGHTRED.into(),
Self::BrightGreen => BRIGHTGREEN.into(),
Self::BrightYellow => BRIGHTYELLOW.into(),
Self::ColourSet256(n) => format!("colour{}", n).into(),
Self::Default => DEFAULT.into(),
Self::Terminal => TERMINAL.into(),
Self::HEX(n) => format!("#{:06x}", n).into(),
};
write!(f, "{}", s)
}
}