use crate::color::SimpleColor;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BasicColor {
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
}
impl BasicColor {
#[must_use]
pub fn to_simple_color(self) -> SimpleColor {
self.into()
}
#[must_use]
pub fn bright(self) -> SimpleColor {
SimpleColor::new_bright(self)
}
#[must_use]
pub(crate) fn code_offset(self) -> u8 {
self as u8
}
}
#[cfg(test)]
mod tests {
use crate::{
AppliedTo as _, Style, ToStyle as _, ToStyleSet as _, color::BasicColor,
test_color_kind_methods, test_to_style_set_methods_with_foreground_assumed,
};
use super::*;
test_color_kind_methods!(
BasicColor::Red,
Color::Simple(SimpleColor::new(BasicColor::Red))
);
test_to_style_set_methods_with_foreground_assumed!(BasicColor::Red);
#[test]
fn bright() {
assert_eq!(
BasicColor::Red.bright(),
SimpleColor::new_bright(BasicColor::Red)
);
}
#[test]
fn applied_to() {
let stld = BasicColor::Red.applied_to("CONTENT");
assert_eq!(stld.get_content(), &"CONTENT");
assert_eq!(stld.get_style(), Style::new().fg(BasicColor::Red));
}
#[test]
fn to_simple_color() {
assert_eq!(
BasicColor::Red.to_simple_color(),
SimpleColor::new(BasicColor::Red)
);
}
#[test]
fn to_style() {
assert_eq!(BasicColor::Red.to_style(), Style::new().fg(BasicColor::Red));
}
}