radicle_term/
colors.rs

1use crate::ansi::Color;
2
3/// The faintest color; useful for borders and such.
4pub const FAINT: Color = fixed::FAINT;
5
6// RGB (24-bit) colors supported by modern terminals.
7pub mod rgb {
8    use super::*;
9
10    pub const NEGATIVE: Color = Color::RGB(60, 10, 20);
11    pub const POSITIVE: Color = Color::RGB(10, 60, 20);
12    pub const NEGATIVE_DARK: Color = Color::RGB(30, 10, 20);
13    pub const POSITIVE_DARK: Color = Color::RGB(10, 30, 20);
14    pub const NEGATIVE_LIGHT: Color = Color::RGB(170, 80, 120);
15    pub const POSITIVE_LIGHT: Color = Color::RGB(80, 170, 120);
16    pub const DIM: Color = Color::RGB(100, 100, 100);
17    pub const FAINT: Color = Color::RGB(20, 20, 20);
18
19    // Default syntax theme.
20    pub const PURPLE: Color = Color::RGB(0xd2, 0xa8, 0xff);
21    pub const RED: Color = Color::RGB(0xff, 0x7b, 0x72);
22    pub const GREEN: Color = Color::RGB(0x7e, 0xd7, 0x87);
23    pub const TEAL: Color = Color::RGB(0xa5, 0xd6, 0xff);
24    pub const ORANGE: Color = Color::RGB(0xff, 0xa6, 0x57);
25    pub const BLUE: Color = Color::RGB(0x79, 0xc0, 0xff);
26    pub const GREY: Color = Color::RGB(0x8b, 0x94, 0x9e);
27    pub const GREY_LIGHT: Color = Color::RGB(0xc9, 0xd1, 0xd9);
28
29    /// Get a color using the color name.
30    pub fn theme(name: &'static str) -> Option<Color> {
31        match name {
32            "negative" => Some(NEGATIVE),
33            "negative.dark" => Some(NEGATIVE_DARK),
34            "negative.light" => Some(NEGATIVE_LIGHT),
35            "positive" => Some(POSITIVE),
36            "positive.dark" => Some(POSITIVE_DARK),
37            "positive.light" => Some(POSITIVE_LIGHT),
38            "dim" => Some(DIM),
39            "faint" => Some(FAINT),
40            "purple" => Some(PURPLE),
41            "red" => Some(RED),
42            "green" => Some(GREEN),
43            "teal" => Some(TEAL),
44            "orange" => Some(ORANGE),
45            "blue" => Some(BLUE),
46            "grey" => Some(GREY),
47            "grey.light" => Some(GREY_LIGHT),
48
49            _ => None,
50        }
51    }
52}
53
54/// "Fixed" ANSI colors, supported by most terminals.
55pub mod fixed {
56    use super::*;
57
58    /// The faintest color; useful for borders and such.
59    pub const FAINT: Color = Color::Fixed(236);
60    /// Slightly brighter than faint.
61    pub const DIM: Color = Color::Fixed(239);
62
63    /// Get a color using the color name.
64    pub fn theme(name: &'static str) -> Option<Color> {
65        match name {
66            "negative" => Some(Color::Red),
67            "negative.dark" => None,
68            "positive" => Some(Color::Green),
69            "positive.dark" => None,
70            "dim" => None,
71            "faint" => None,
72            "blue" => Some(Color::Blue),
73            "green" => Some(Color::Green),
74            "red" => Some(Color::Red),
75            "teal" => Some(Color::Cyan),
76            "purple" => Some(Color::Magenta),
77
78            _ => None,
79        }
80    }
81}