Skip to main content

tui/theme/
defaults.rs

1use super::{Color, Theme, darken_color, lighten_color};
2
3impl Theme {
4    /// Catppuccin Mocha theme (dark, high contrast).
5    ///
6    /// This is the default theme and is always available without any
7    /// additional dependencies.
8    pub fn catppuccin_mocha() -> Self {
9        // Catppuccin Mocha palette
10        const TEXT: Color = Color::Rgb {
11            r: 0xCD,
12            g: 0xD6,
13            b: 0xF4,
14        };
15        const BASE: Color = Color::Rgb {
16            r: 0x1E,
17            g: 0x1E,
18            b: 0x2E,
19        };
20        const ROSEWATER: Color = Color::Rgb {
21            r: 0xF5,
22            g: 0xE0,
23            b: 0xDC,
24        };
25        const YELLOW: Color = Color::Rgb {
26            r: 0xF9,
27            g: 0xE2,
28            b: 0xAF,
29        };
30        const BLUE: Color = Color::Rgb {
31            r: 0x89,
32            g: 0xB4,
33            b: 0xFA,
34        };
35        const PINK: Color = Color::Rgb {
36            r: 0xF5,
37            g: 0xC2,
38            b: 0xE7,
39        };
40        const TEAL: Color = Color::Rgb {
41            r: 0x94,
42            g: 0xE2,
43            b: 0xD5,
44        };
45        const GREEN: Color = Color::Rgb {
46            r: 0xA6,
47            g: 0xE3,
48            b: 0xA1,
49        };
50        const PEACH: Color = Color::Rgb {
51            r: 0xFA,
52            g: 0xB3,
53            b: 0x87,
54        };
55        const RED: Color = Color::Rgb {
56            r: 0xF3,
57            g: 0x8B,
58            b: 0xA8,
59        };
60        const MAUVE: Color = Color::Rgb {
61            r: 0xCB,
62            g: 0xA6,
63            b: 0xF7,
64        };
65        const SURFACE1: Color = Color::Rgb {
66            r: 0x45,
67            g: 0x45,
68            b: 0x45,
69        };
70        const OVERLAY0: Color = Color::Rgb {
71            r: 0x6C,
72            g: 0x70,
73            b: 0x85,
74        };
75
76        Theme::builder()
77            .fg(TEXT)
78            .bg(BASE)
79            .accent(ROSEWATER)
80            .highlight_bg(Color::Rgb {
81                r: 0x31,
82                g: 0x4A,
83                b: 0x56,
84            })
85            .highlight_fg(TEXT)
86            .text_secondary(OVERLAY0)
87            .code_fg(GREEN)
88            .code_bg(SURFACE1)
89            .heading(YELLOW)
90            .link(BLUE)
91            .blockquote(PINK)
92            .muted(TEAL)
93            .success(GREEN)
94            .warning(PEACH)
95            .error(RED)
96            .info(BLUE)
97            .secondary(MAUVE)
98            .sidebar_bg(Color::Rgb {
99                r: 0x24,
100                g: 0x24,
101                b: 0x36,
102            })
103            .diff_added_fg(GREEN)
104            .diff_removed_fg(RED)
105            .diff_added_bg(darken_color(GREEN))
106            .diff_removed_bg(darken_color(RED))
107            .build()
108            .expect("built-in catppuccin_mocha theme has all fields")
109    }
110
111    /// A minimal light theme.
112    #[allow(dead_code)]
113    pub fn light() -> Self {
114        const FG: Color = Color::Rgb {
115            r: 0x22,
116            g: 0x22,
117            b: 0x22,
118        };
119        const BG: Color = Color::Rgb {
120            r: 0xFA,
121            g: 0xFA,
122            b: 0xFA,
123        };
124        const ACCENT: Color = Color::Rgb {
125            r: 0x00,
126            g: 0x66,
127            b: 0xCC,
128        };
129        const GREEN: Color = Color::Rgb {
130            r: 0x22,
131            g: 0x88,
132            b: 0x22,
133        };
134        const RED: Color = Color::Rgb {
135            r: 0xCC,
136            g: 0x22,
137            b: 0x22,
138        };
139        const ORANGE: Color = Color::Rgb {
140            r: 0xCC,
141            g: 0x66,
142            b: 0x00,
143        };
144
145        Theme::builder()
146            .fg(FG)
147            .bg(BG)
148            .accent(ACCENT)
149            .highlight_bg(Color::Rgb {
150                r: 0xDD,
151                g: 0xDD,
152                b: 0xDD,
153            })
154            .highlight_fg(FG)
155            .text_secondary(Color::Rgb {
156                r: 0x66,
157                g: 0x66,
158                b: 0x66,
159            })
160            .code_fg(Color::Rgb {
161                r: 0x33,
162                g: 0x66,
163                b: 0x33,
164            })
165            .code_bg(Color::Rgb {
166                r: 0xF0,
167                g: 0xF0,
168                b: 0xF0,
169            })
170            .heading(ACCENT)
171            .link(Color::Rgb {
172                r: 0x00,
173                g: 0x44,
174                b: 0xAA,
175            })
176            .blockquote(Color::Rgb {
177                r: 0x66,
178                g: 0x44,
179                b: 0x88,
180            })
181            .muted(Color::Rgb {
182                r: 0x88,
183                g: 0x88,
184                b: 0x88,
185            })
186            .success(GREEN)
187            .warning(ORANGE)
188            .error(RED)
189            .info(ACCENT)
190            .secondary(Color::Rgb {
191                r: 0x66,
192                g: 0x33,
193                b: 0x99,
194            })
195            .sidebar_bg(Color::Rgb {
196                r: 0xF4,
197                g: 0xF4,
198                b: 0xF8,
199            })
200            .diff_added_fg(GREEN)
201            .diff_removed_fg(RED)
202            .diff_added_bg(lighten_color(GREEN))
203            .diff_removed_bg(lighten_color(RED))
204            .build()
205            .expect("built-in light theme has all fields")
206    }
207}
208
209impl Default for Theme {
210    fn default() -> Self {
211        Self::catppuccin_mocha()
212    }
213}