os_terminal/
palette.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use crate::color::Rgb;
use spin::Lazy;

pub const DEFAULT_PALETTE_INDEX: usize = 0;

pub struct Palette {
    pub foreground: Rgb,
    pub background: Rgb,
    pub ansi_colors: [Rgb; 16],
}

impl Palette {
    fn build(pair: (&str, &str), ansi_colors: [&str; 16]) -> Self {
        Self {
            foreground: Self::hex_to_rgb(pair.0),
            background: Self::hex_to_rgb(pair.1),
            ansi_colors: ansi_colors.map(Self::hex_to_rgb),
        }
    }

    fn hex_to_rgb(hex: &str) -> Rgb {
        let hex = hex.trim_start_matches('#');
        let r = u8::from_str_radix(&hex[0..2], 16).unwrap_or(0);
        let g = u8::from_str_radix(&hex[2..4], 16).unwrap_or(0);
        let b = u8::from_str_radix(&hex[4..6], 16).unwrap_or(0);
        (r, g, b)
    }
}

pub static PALETTE_DATA: Lazy<[Palette; 8]> = Lazy::new(|| {
    [
        Palette::build(
            ("#f5f5f5", "#151515"),
            [
                "#151515", "#ac4142", "#90a959", "#f4bf75", "#6a9fb5", "#aa759f", "#75b5aa",
                "#d0d0d0", "#505050", "#ac4142", "#90a959", "#f4bf75", "#6a9fb5", "#aa759f",
                "#75b5aa", "#f5f5f5",
            ],
        ),
        Palette::build(
            ("#839496", "#002b36"),
            [
                "#002b36", "#dc322f", "#859900", "#b58900", "#268bd2", "#d33682", "#2aa198",
                "#eee8d5", "#073642", "#cb4b16", "#586e75", "#657b83", "#839496", "#6c71c4",
                "#93a1a1", "#fdf6e3",
            ],
        ),
        Palette::build(
            ("#ffffff", "#300924"),
            [
                "#2e3436", "#cc0000", "#4e9a06", "#c4a000", "#3465a4", "#75507b", "#06989a",
                "#d3d7cf", "#555753", "#ef2929", "#8ae234", "#fce94f", "#729fcf", "#ad7fa8",
                "#34e2e2", "#eeeeec",
            ],
        ),
        Palette::build(
            ("#f8f8f2", "#121212"),
            [
                "#181d1e", "#f92672", "#a6e22e", "#fd971f", "#66d9ef", "#9e6ffe", "#5e7175",
                "#cccccc", "#505354", "#ff669d", "#beed5f", "#e6db74", "#66d9ef", "#9e6ffe",
                "#a3babf", "#f8f8f2",
            ],
        ),
        Palette::build(
            ("#00bb00", "#001100"),
            [
                "#001100", "#007700", "#00bb00", "#007700", "#009900", "#00bb00", "#005500",
                "#00bb00", "#007700", "#007700", "#00bb00", "#007700", "#009900", "#00bb00",
                "#005500", "#00ff00",
            ],
        ),
        Palette::build(
            ("#979db4", "#202746"),
            [
                "#202746", "#c94922", "#ac9739", "#c08b30", "#3d8fd1", "#6679cc", "#22a2c9",
                "#979db4", "#6b7394", "#c94922", "#ac9739", "#c08b30", "#3d8fd1", "#6679cc",
                "#22a2c9", "#f5f7ff",
            ],
        ),
        Palette::build(
            ("#657b83", "#fdf6e3"),
            [
                "#002b36", "#dc322f", "#859900", "#b58900", "#268bd2", "#d33682", "#2aa198",
                "#eee8d5", "#073642", "#cb4b16", "#586e75", "#657b83", "#839496", "#6c71c4",
                "#93a1a1", "#fdf6e3",
            ],
        ),
        Palette::build(
            ("#26232a", "#efecf4"),
            [
                "#19171c", "#be4678", "#2a9292", "#a06e3b", "#576ddb", "#955ae7", "#398bc6",
                "#8b8792", "#585260", "#c9648e", "#34b2b2", "#bc8249", "#788ae2", "#ac7eed",
                "#599ecf", "#efecf4",
            ],
        ),
    ]
});