1use std::sync::Arc;
2
3use gpui::Hsla;
4use refineable::Refineable;
5
6use crate::{PlayerColors, SyntaxTheme};
7
8#[derive(Clone)]
9pub struct SystemColors {
10 pub transparent: Hsla,
11 pub mac_os_traffic_light_red: Hsla,
12 pub mac_os_traffic_light_yellow: Hsla,
13 pub mac_os_traffic_light_green: Hsla,
14}
15
16#[derive(Refineable, Clone, Debug)]
17#[refineable(debug)]
18pub struct StatusColors {
19 pub conflict: Hsla,
20 pub created: Hsla,
21 pub deleted: Hsla,
22 pub error: Hsla,
23 pub hidden: Hsla,
24 pub ignored: Hsla,
25 pub info: Hsla,
26 pub modified: Hsla,
27 pub renamed: Hsla,
28 pub success: Hsla,
29 pub warning: Hsla,
30}
31
32#[derive(Refineable, Clone, Debug)]
33#[refineable(debug)]
34pub struct GitStatusColors {
35 pub conflict: Hsla,
36 pub created: Hsla,
37 pub deleted: Hsla,
38 pub ignored: Hsla,
39 pub modified: Hsla,
40 pub renamed: Hsla,
41}
42
43#[derive(Refineable, Clone, Debug)]
44#[refineable(debug, deserialize)]
45pub struct ThemeColors {
46 pub border: Hsla,
47 /// Border color. Used for deemphasized borders, like a visual divider between two sections
48 pub border_variant: Hsla,
49 /// Border color. Used for focused elements, like keyboard focused list item.
50 pub border_focused: Hsla,
51 /// Border color. Used for selected elements, like an active search filter or selected checkbox.
52 pub border_selected: Hsla,
53 /// Border color. Used for transparent borders. Used for placeholder borders when an element gains a border on state change.
54 pub border_transparent: Hsla,
55 /// Border color. Used for disabled elements, like a disabled input or button.
56 pub border_disabled: Hsla,
57 /// Border color. Used for elevated surfaces, like a context menu, popup, or dialog.
58 pub elevated_surface_background: Hsla,
59 /// Background Color. Used for grounded surfaces like a panel or tab.
60 pub surface_background: Hsla,
61 /// Background Color. Used for the app background and blank panels or windows.
62 pub background: Hsla,
63 /// Background Color. Used for the background of an element that should have a different background than the surface it's on.
64 ///
65 /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons...
66 ///
67 /// For an element that should have the same background as the surface it's on, use `ghost_element_background`.
68 pub element_background: Hsla,
69 /// Background Color. Used for the hover state of an element that should have a different background than the surface it's on.
70 ///
71 /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen.
72 pub element_hover: Hsla,
73 /// Background Color. Used for the active state of an element that should have a different background than the surface it's on.
74 ///
75 /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd.
76 pub element_active: Hsla,
77 /// Background Color. Used for the selected state of an element that should have a different background than the surface it's on.
78 ///
79 /// Selected states are triggered by the element being selected (or "activated") by the user.
80 ///
81 /// This could include a selected checkbox, a toggleable button that is toggled on, etc.
82 pub element_selected: Hsla,
83 /// Background Color. Used for the disabled state of an element that should have a different background than the surface it's on.
84 ///
85 /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input.
86 pub element_disabled: Hsla,
87 /// Background Color. Used for the area that shows where a dragged element will be dropped.
88 pub drop_target_background: Hsla,
89 /// Border Color. Used to show the area that shows where a dragged element will be dropped.
90 // pub drop_target_border: Hsla,
91 /// Used for the background of a ghost element that should have the same background as the surface it's on.
92 ///
93 /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons...
94 ///
95 /// For an element that should have a different background than the surface it's on, use `element_background`.
96 pub ghost_element_background: Hsla,
97 /// Background Color. Used for the hover state of a ghost element that should have the same background as the surface it's on.
98 ///
99 /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen.
100 pub ghost_element_hover: Hsla,
101 /// Background Color. Used for the active state of a ghost element that should have the same background as the surface it's on.
102 ///
103 /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd.
104 pub ghost_element_active: Hsla,
105 /// Background Color. Used for the selected state of a ghost element that should have the same background as the surface it's on.
106 ///
107 /// Selected states are triggered by the element being selected (or "activated") by the user.
108 ///
109 /// This could include a selected checkbox, a toggleable button that is toggled on, etc.
110 pub ghost_element_selected: Hsla,
111 /// Background Color. Used for the disabled state of a ghost element that should have the same background as the surface it's on.
112 ///
113 /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input.
114 pub ghost_element_disabled: Hsla,
115 /// Text Color. Default text color used for most text.
116 pub text: Hsla,
117 /// Text Color. Color of muted or deemphasized text. It is a subdued version of the standard text color.
118 pub text_muted: Hsla,
119 /// Text Color. Color of the placeholder text typically shown in input fields to guide the user to enter valid data.
120 pub text_placeholder: Hsla,
121 /// Text Color. Color used for text denoting disabled elements. Typically, the color is faded or grayed out to emphasize the disabled state.
122 pub text_disabled: Hsla,
123 /// Text Color. Color used for emphasis or highlighting certain text, like an active filter or a matched character in a search.
124 pub text_accent: Hsla,
125 /// Fill Color. Used for the default fill color of an icon.
126 pub icon: Hsla,
127 /// Fill Color. Used for the muted or deemphasized fill color of an icon.
128 ///
129 /// This might be used to show an icon in an inactive pane, or to demphasize a series of icons to give them less visual weight.
130 pub icon_muted: Hsla,
131 /// Fill Color. Used for the disabled fill color of an icon.
132 ///
133 /// Disabled states are shown when a user cannot interact with an element, like a icon button.
134 pub icon_disabled: Hsla,
135 /// Fill Color. Used for the placeholder fill color of an icon.
136 ///
137 /// This might be used to show an icon in an input that disappears when the user enters text.
138 pub icon_placeholder: Hsla,
139 /// Fill Color. Used for the accent fill color of an icon.
140 ///
141 /// This might be used to show when a toggleable icon button is selected.
142 pub icon_accent: Hsla,
143
144 // ===
145 // UI Elements
146 // ===
147 pub status_bar_background: Hsla,
148 pub title_bar_background: Hsla,
149 pub toolbar_background: Hsla,
150 pub tab_bar_background: Hsla,
151 pub tab_inactive_background: Hsla,
152 pub tab_active_background: Hsla,
153 // pub panel_background: Hsla,
154 // pub pane_focused_border: Hsla,
155 // /// The color of the scrollbar thumb.
156 // pub scrollbar_thumb_background: Hsla,
157 // /// The color of the scrollbar thumb when hovered over.
158 // pub scrollbar_thumb_hover_background: Hsla,
159 // /// The border color of the scrollbar thumb.
160 // pub scrollbar_thumb_border: Hsla,
161 // /// The background color of the scrollbar track.
162 // pub scrollbar_track_background: Hsla,
163 // /// The border color of the scrollbar track.
164 // pub scrollbar_track_border: Hsla,
165 // /// The opacity of the scrollbar status marks, like diagnostic states and git status..
166 // pub scrollbar_status_opacity: Hsla,
167
168 // ===
169 // Editor
170 // ===
171 pub editor_background: Hsla,
172 // pub editor_inactive_background: Hsla,
173 pub editor_gutter_background: Hsla,
174 pub editor_subheader_background: Hsla,
175 pub editor_active_line_background: Hsla,
176 pub editor_highlighted_line_background: Hsla,
177 /// Text Color. Used for the text of the line number in the editor gutter.
178 pub editor_line_number: Hsla,
179 /// Text Color. Used for the text of the line number in the editor gutter when the line is highlighted.
180 pub editor_active_line_number: Hsla,
181 /// Text Color. Used to mark invisible characters in the editor.
182 ///
183 /// Example: spaces, tabs, carriage returns, etc.
184 pub editor_invisible: Hsla,
185 pub editor_wrap_guide: Hsla,
186 pub editor_active_wrap_guide: Hsla,
187 pub editor_document_highlight_read_background: Hsla,
188 pub editor_document_highlight_write_background: Hsla,
189
190 // ===
191 // Terminal
192 // ===
193 /// Terminal Background Color
194 pub terminal_background: Hsla,
195 /// Bright Black Color for ANSI Terminal
196 pub terminal_ansi_bright_black: Hsla,
197 /// Bright Red Color for ANSI Terminal
198 pub terminal_ansi_bright_red: Hsla,
199 /// Bright Green Color for ANSI Terminal
200 pub terminal_ansi_bright_green: Hsla,
201 /// Bright Yellow Color for ANSI Terminal
202 pub terminal_ansi_bright_yellow: Hsla,
203 /// Bright Blue Color for ANSI Terminal
204 pub terminal_ansi_bright_blue: Hsla,
205 /// Bright Magenta Color for ANSI Terminal
206 pub terminal_ansi_bright_magenta: Hsla,
207 /// Bright Cyan Color for ANSI Terminal
208 pub terminal_ansi_bright_cyan: Hsla,
209 /// Bright White Color for ANSI Terminal
210 pub terminal_ansi_bright_white: Hsla,
211 /// Black Color for ANSI Terminal
212 pub terminal_ansi_black: Hsla,
213 /// Red Color for ANSI Terminal
214 pub terminal_ansi_red: Hsla,
215 /// Green Color for ANSI Terminal
216 pub terminal_ansi_green: Hsla,
217 /// Yellow Color for ANSI Terminal
218 pub terminal_ansi_yellow: Hsla,
219 /// Blue Color for ANSI Terminal
220 pub terminal_ansi_blue: Hsla,
221 /// Magenta Color for ANSI Terminal
222 pub terminal_ansi_magenta: Hsla,
223 /// Cyan Color for ANSI Terminal
224 pub terminal_ansi_cyan: Hsla,
225 /// White Color for ANSI Terminal
226 pub terminal_ansi_white: Hsla,
227 // new colors
228
229 // ===
230 // Elevation
231 // ===
232 // elevation_0_shadow
233 // elevation_0_shadow_color
234 // elevation_1_shadow
235 // elevation_1_shadow_color
236 // elevation_2_shadow
237 // elevation_2_shadow_color
238 // elevation_3_shadow
239 // elevation_3_shadow_color
240 // elevation_4_shadow
241 // elevation_4_shadow_color
242 // elevation_5_shadow
243 // elevation_5_shadow_color
244
245 // ===
246 // UI Text
247 // ===
248 // pub headline: Hsla,
249 // pub paragraph: Hsla,
250 // pub link: Hsla,
251 // pub link_hover: Hsla,
252 // pub code_block_background: Hsla,
253 // pub code_block_border: Hsla,
254}
255
256#[derive(Refineable, Clone)]
257pub struct ThemeStyles {
258 pub system: SystemColors,
259
260 #[refineable]
261 pub colors: ThemeColors,
262 pub status: StatusColors,
263 pub git: GitStatusColors,
264 pub player: PlayerColors,
265 pub syntax: Arc<SyntaxTheme>,
266}
267
268#[cfg(test)]
269mod tests {
270 use serde_json::json;
271
272 use super::*;
273
274 #[test]
275 fn override_a_single_theme_color() {
276 let mut colors = ThemeColors::default_light();
277
278 let magenta: Hsla = gpui::rgb(0xff00ff);
279
280 assert_ne!(colors.text, magenta);
281
282 let overrides = ThemeColorsRefinement {
283 text: Some(magenta),
284 ..Default::default()
285 };
286
287 colors.refine(&overrides);
288
289 assert_eq!(colors.text, magenta);
290 }
291
292 #[test]
293 fn override_multiple_theme_colors() {
294 let mut colors = ThemeColors::default_light();
295
296 let magenta: Hsla = gpui::rgb(0xff00ff);
297 let green: Hsla = gpui::rgb(0x00ff00);
298
299 assert_ne!(colors.text, magenta);
300 assert_ne!(colors.background, green);
301
302 let overrides = ThemeColorsRefinement {
303 text: Some(magenta),
304 background: Some(green),
305 ..Default::default()
306 };
307
308 colors.refine(&overrides);
309
310 assert_eq!(colors.text, magenta);
311 assert_eq!(colors.background, green);
312 }
313
314 #[test]
315 fn deserialize_theme_colors_refinement_from_json() {
316 let colors: ThemeColorsRefinement = serde_json::from_value(json!({
317 "background": "#ff00ff",
318 "text": "#ff0000"
319 }))
320 .unwrap();
321
322 assert_eq!(colors.background, Some(gpui::rgb(0xff00ff)));
323 assert_eq!(colors.text, Some(gpui::rgb(0xff0000)));
324 }
325}