Nothing to see here, move along
1use crate::color::{BasicColor, Color};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4#[repr(u8)]
5pub enum Severity {
6 Error = 0,
7 Warn = 1,
8 Info = 2,
9 Debug = 3,
10}
11
12impl Severity {
13 pub const fn from_u8(val: u8) -> Option<Self> {
14 match val {
15 0 => Some(Self::Error),
16 1 => Some(Self::Warn),
17 2 => Some(Self::Info),
18 3 => Some(Self::Debug),
19 _ => None,
20 }
21 }
22
23 pub const fn as_u8(self) -> u8 {
24 self as u8
25 }
26
27 pub const fn passes_threshold(self, threshold: Severity) -> bool {
28 (self as u8) <= (threshold as u8)
29 }
30
31 pub const fn label(self) -> &'static str {
32 match self {
33 Self::Error => "error",
34 Self::Warn => "warn",
35 Self::Info => "info",
36 Self::Debug => "debug",
37 }
38 }
39
40 pub const fn message_color(self) -> Color {
41 match self {
42 Self::Error => crate::palette::ERROR_RED,
43 Self::Warn => crate::palette::WARN_AMBER,
44 Self::Info => crate::palette::ICE_WHITE,
45 Self::Debug => crate::palette::DEBUG_GRAY,
46 }
47 }
48
49 pub const fn message_color_basic(self) -> BasicColor {
50 match self {
51 Self::Error => BasicColor::Red,
52 Self::Warn => BasicColor::Yellow,
53 Self::Info => BasicColor::BrightWhite,
54 Self::Debug => BasicColor::BrightBlack,
55 }
56 }
57}