use core::fmt::Result;
use crate::{
CodeWriter, ColorTarget, color::WriteColorCodes, impl_macros::color_type::impl_color_type,
};
use super::Color;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct IndexedColor(pub u8);
impl IndexedColor {
#[must_use]
pub const fn new(index: u8) -> Self {
IndexedColor(index)
}
#[must_use]
pub const fn get_index(self) -> u8 {
self.0
}
}
impl_color_type!(IndexedColor {
args: [self];
to_color: { Color::Indexed(self) }
});
impl WriteColorCodes for IndexedColor {
fn write_color_codes(self, target: ColorTarget, writer: &mut CodeWriter) -> Result {
let target_code = match target {
ColorTarget::Foreground => 38,
ColorTarget::Background => 48,
ColorTarget::Underline => 58,
};
writer.write_code(target_code)?;
writer.write_code(5)?;
writer.write_code(self.0)?;
Ok(())
}
}