Skip to main content

pito_footer/
styles.rs

1use ratatui::style::{Modifier, Style};
2
3#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
4#[non_exhaustive]
5pub struct Styles {
6    pub accent: Style,
7    pub muted: Style,
8    pub alert: Style,
9    pub ink: Style,
10    pub rule: Style,
11    pub good: Option<Style>,
12}
13
14impl Styles {
15    pub const fn new() -> Self {
16        Styles {
17            accent: Style::new(),
18            muted: Style::new(),
19            alert: Style::new(),
20            ink: Style::new(),
21            rule: Style::new(),
22            good: None,
23        }
24    }
25
26    pub const fn accent(mut self, style: Style) -> Self {
27        self.accent = style;
28        self
29    }
30
31    pub const fn muted(mut self, style: Style) -> Self {
32        self.muted = style;
33        self
34    }
35
36    pub const fn alert(mut self, style: Style) -> Self {
37        self.alert = style;
38        self
39    }
40
41    pub const fn ink(mut self, style: Style) -> Self {
42        self.ink = style;
43        self
44    }
45
46    pub const fn rule(mut self, style: Style) -> Self {
47        self.rule = style;
48        self
49    }
50
51    pub const fn good(mut self, style: Style) -> Self {
52        self.good = Some(style);
53        self
54    }
55
56    pub(crate) fn lit(&self) -> Style {
57        self.accent.add_modifier(Modifier::BOLD)
58    }
59}
60
61#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
62#[non_exhaustive]
63pub enum Tone {
64    Ink,
65    #[default]
66    Muted,
67    Accent,
68    Alert,
69    Good,
70}
71
72impl Tone {
73    pub(crate) fn style(self, styles: &Styles) -> Style {
74        match self {
75            Tone::Ink => styles.ink,
76            Tone::Muted => styles.muted,
77            Tone::Accent => styles.lit(),
78            Tone::Alert => styles.alert,
79            Tone::Good => styles.good.unwrap_or(styles.ink),
80        }
81    }
82}