use ratatui::prelude::*;
pub enum Severity {
Low,
Medium,
High,
Critical,
}
impl Severity {
const COLORS: [(u8, u8, u8); 4] = [
(244, 11, 104), (221, 244, 11), (11, 244, 151), (34, 11, 244), ];
pub fn style_for(&self) -> Style {
let styles = Self::COLORS
.iter()
.map(|(r, g, b)| {
Style::default()
.fg(Color::Rgb(*r, *g, *b))
.add_modifier(Modifier::BOLD | Modifier::ITALIC)
})
.collect::<Vec<Style>>();
*match self {
Severity::Low => &styles[0],
Severity::Medium => &styles[1],
Severity::High => &styles[2],
Severity::Critical => &styles[3],
}
}
}
pub fn calculate_severity<N>(n: N) -> Severity
where
N: PartialEq
+ PartialOrd
+ std::ops::Div<Output = N>
+ std::ops::Mul<Output = N>
+ From<f32>
+ std::fmt::Display,
{
match n {
_ if n < N::from(0.6) => Severity::Low,
_ if n < N::from(0.75) => Severity::Medium,
_ if n < N::from(0.85) => Severity::High,
_ => Severity::Critical,
}
}