use crate::color::{BasicColor, Color}; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(u8)] pub enum Severity { Error = 0, Warn = 1, Info = 2, Debug = 3, } impl Severity { pub const fn from_u8(val: u8) -> Option { match val { 0 => Some(Self::Error), 1 => Some(Self::Warn), 2 => Some(Self::Info), 3 => Some(Self::Debug), _ => None, } } pub const fn as_u8(self) -> u8 { self as u8 } pub const fn passes_threshold(self, threshold: Severity) -> bool { (self as u8) <= (threshold as u8) } pub const fn label(self) -> &'static str { match self { Self::Error => "error", Self::Warn => "warn", Self::Info => "info", Self::Debug => "debug", } } pub const fn message_color(self) -> Color { match self { Self::Error => crate::palette::ERROR_RED, Self::Warn => crate::palette::WARN_AMBER, Self::Info => crate::palette::ICE_WHITE, Self::Debug => crate::palette::DEBUG_GRAY, } } pub const fn message_color_basic(self) -> BasicColor { match self { Self::Error => BasicColor::Red, Self::Warn => BasicColor::Yellow, Self::Info => BasicColor::BrightWhite, Self::Debug => BasicColor::BrightBlack, } } }