chore/
color.rs

1use std::cell::Cell;
2
3thread_local! {
4    static CURRENT_FG: Cell<Fg> = Cell::new(Fg::Default);
5    static CURRENT_BG: Cell<Bg> = Cell::new(Bg::Default);
6}
7
8#[derive(Clone, Copy, PartialEq)]
9pub enum Bg {
10    Default,
11    Custom(u8),
12}
13
14#[derive(Clone, Copy, PartialEq)]
15pub enum Fg {
16    Black,
17    Blue,
18    Cyan,
19    Default,
20    Green,
21    LightGray,
22    Magenta,
23    Red,
24    White,
25    Yellow,
26}
27
28impl Bg {
29    pub fn get() -> Self {
30        CURRENT_BG.with(|current| current.get())
31    }
32
33    pub fn set(&self) {
34        CURRENT_BG.with(|current| current.set(*self))
35    }
36}
37
38impl Fg {
39    pub fn get() -> Self {
40        CURRENT_FG.with(|current| current.get())
41    }
42
43    pub fn set(&self) {
44        CURRENT_FG.with(|current| current.set(*self))
45    }
46}