1#![allow(missing_docs)]
2
3use gpui::{App, Hsla, SharedString, WindowBackgroundAppearance};
4use refineable::Refineable;
5use std::sync::Arc;
6use strum::{AsRefStr, EnumIter, IntoEnumIterator};
7
8use crate::{
9 AccentColors, ActiveTheme, PlayerColors, StatusColors, StatusColorsRefinement, SyntaxTheme,
10 SystemColors,
11};
12
13#[derive(Refineable, Clone, Debug, PartialEq)]
14#[refineable(Debug, serde::Deserialize)]
15pub struct ThemeColors {
16 /// Border color. Used for most borders, is usually a high contrast color.
17 pub border: Hsla,
18 /// Border color. Used for deemphasized borders, like a visual divider between two sections
19 pub border_variant: Hsla,
20 /// Border color. Used for focused elements, like keyboard focused list item.
21 pub border_focused: Hsla,
22 /// Border color. Used for selected elements, like an active search filter or selected checkbox.
23 pub border_selected: Hsla,
24 /// Border color. Used for transparent borders. Used for placeholder borders when an element gains a border on state change.
25 pub border_transparent: Hsla,
26 /// Border color. Used for disabled elements, like a disabled input or button.
27 pub border_disabled: Hsla,
28 /// Border color. Used for elevated surfaces, like a context menu, popup, or dialog.
29 pub elevated_surface_background: Hsla,
30 /// Background Color. Used for grounded surfaces like a panel or tab.
31 pub surface_background: Hsla,
32 /// Background Color. Used for the app background and blank panels or windows.
33 pub background: Hsla,
34 /// Background Color. Used for the background of an element that should have a different background than the surface it's on.
35 ///
36 /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons...
37 ///
38 /// For an element that should have the same background as the surface it's on, use `ghost_element_background`.
39 pub element_background: Hsla,
40 /// Background Color. Used for the hover state of an element that should have a different background than the surface it's on.
41 ///
42 /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen.
43 pub element_hover: Hsla,
44 /// Background Color. Used for the active state of an element that should have a different background than the surface it's on.
45 ///
46 /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd.
47 pub element_active: Hsla,
48 /// Background Color. Used for the selected state of an element that should have a different background than the surface it's on.
49 ///
50 /// Selected states are triggered by the element being selected (or "activated") by the user.
51 ///
52 /// This could include a selected checkbox, a toggleable button that is toggled on, etc.
53 pub element_selected: Hsla,
54 /// Background Color. Used for the disabled state of an element that should have a different background than the surface it's on.
55 ///
56 /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input.
57 pub element_disabled: Hsla,
58 /// Background Color. Used for the area that shows where a dragged element will be dropped.
59 pub drop_target_background: Hsla,
60 /// Used for the background of a ghost element that should have the same background as the surface it's on.
61 ///
62 /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons...
63 ///
64 /// For an element that should have a different background than the surface it's on, use `element_background`.
65 pub ghost_element_background: Hsla,
66 /// Background Color. Used for the hover state of a ghost element that should have the same background as the surface it's on.
67 ///
68 /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen.
69 pub ghost_element_hover: Hsla,
70 /// Background Color. Used for the active state of a ghost element that should have the same background as the surface it's on.
71 ///
72 /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd.
73 pub ghost_element_active: Hsla,
74 /// Background Color. Used for the selected state of a ghost element that should have the same background as the surface it's on.
75 ///
76 /// Selected states are triggered by the element being selected (or "activated") by the user.
77 ///
78 /// This could include a selected checkbox, a toggleable button that is toggled on, etc.
79 pub ghost_element_selected: Hsla,
80 /// Background Color. Used for the disabled state of a ghost element that should have the same background as the surface it's on.
81 ///
82 /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input.
83 pub ghost_element_disabled: Hsla,
84 /// Text Color. Default text color used for most text.
85 pub text: Hsla,
86 /// Text Color. Color of muted or deemphasized text. It is a subdued version of the standard text color.
87 pub text_muted: Hsla,
88 /// Text Color. Color of the placeholder text typically shown in input fields to guide the user to enter valid data.
89 pub text_placeholder: Hsla,
90 /// Text Color. Color used for text denoting disabled elements. Typically, the color is faded or grayed out to emphasize the disabled state.
91 pub text_disabled: Hsla,
92 /// Text Color. Color used for emphasis or highlighting certain text, like an active filter or a matched character in a search.
93 pub text_accent: Hsla,
94 /// Fill Color. Used for the default fill color of an icon.
95 pub icon: Hsla,
96 /// Fill Color. Used for the muted or deemphasized fill color of an icon.
97 ///
98 /// This might be used to show an icon in an inactive pane, or to deemphasize a series of icons to give them less visual weight.
99 pub icon_muted: Hsla,
100 /// Fill Color. Used for the disabled fill color of an icon.
101 ///
102 /// Disabled states are shown when a user cannot interact with an element, like a icon button.
103 pub icon_disabled: Hsla,
104 /// Fill Color. Used for the placeholder fill color of an icon.
105 ///
106 /// This might be used to show an icon in an input that disappears when the user enters text.
107 pub icon_placeholder: Hsla,
108 /// Fill Color. Used for the accent fill color of an icon.
109 ///
110 /// This might be used to show when a toggleable icon button is selected.
111 pub icon_accent: Hsla,
112
113 // ===
114 // UI Elements
115 // ===
116 pub status_bar_background: Hsla,
117 pub title_bar_background: Hsla,
118 pub title_bar_inactive_background: Hsla,
119 pub toolbar_background: Hsla,
120 pub tab_bar_background: Hsla,
121 pub tab_inactive_background: Hsla,
122 pub tab_active_background: Hsla,
123 pub search_match_background: Hsla,
124 pub panel_background: Hsla,
125 pub panel_focused_border: Hsla,
126 pub panel_indent_guide: Hsla,
127 pub panel_indent_guide_hover: Hsla,
128 pub panel_indent_guide_active: Hsla,
129 pub pane_focused_border: Hsla,
130 pub pane_group_border: Hsla,
131 /// The color of the scrollbar thumb.
132 pub scrollbar_thumb_background: Hsla,
133 /// The color of the scrollbar thumb when hovered over.
134 pub scrollbar_thumb_hover_background: Hsla,
135 /// The border color of the scrollbar thumb.
136 pub scrollbar_thumb_border: Hsla,
137 /// The background color of the scrollbar track.
138 pub scrollbar_track_background: Hsla,
139 /// The border color of the scrollbar track.
140 pub scrollbar_track_border: Hsla,
141
142 // ===
143 // Editor
144 // ===
145 pub editor_foreground: Hsla,
146 pub editor_background: Hsla,
147 pub editor_gutter_background: Hsla,
148 pub editor_subheader_background: Hsla,
149 pub editor_active_line_background: Hsla,
150 pub editor_highlighted_line_background: Hsla,
151 /// Text Color. Used for the text of the line number in the editor gutter.
152 pub editor_line_number: Hsla,
153 /// Text Color. Used for the text of the line number in the editor gutter when the line is highlighted.
154 pub editor_active_line_number: Hsla,
155 /// Text Color. Used for the text of the line number in the editor gutter when the line is hovered over.
156 pub editor_hover_line_number: Hsla,
157 /// Text Color. Used to mark invisible characters in the editor.
158 ///
159 /// Example: spaces, tabs, carriage returns, etc.
160 pub editor_invisible: Hsla,
161 pub editor_wrap_guide: Hsla,
162 pub editor_active_wrap_guide: Hsla,
163 pub editor_indent_guide: Hsla,
164 pub editor_indent_guide_active: Hsla,
165 /// Read-access of a symbol, like reading a variable.
166 ///
167 /// A document highlight is a range inside a text document which deserves
168 /// special attention. Usually a document highlight is visualized by changing
169 /// the background color of its range.
170 pub editor_document_highlight_read_background: Hsla,
171 /// Read-access of a symbol, like reading a variable.
172 ///
173 /// A document highlight is a range inside a text document which deserves
174 /// special attention. Usually a document highlight is visualized by changing
175 /// the background color of its range.
176 pub editor_document_highlight_write_background: Hsla,
177 /// Highlighted brackets background color.
178 ///
179 /// Matching brackets in the cursor scope are highlighted with this background color.
180 pub editor_document_highlight_bracket_background: Hsla,
181
182 // ===
183 // Terminal
184 // ===
185 /// Terminal layout background color.
186 pub terminal_background: Hsla,
187 /// Terminal foreground color.
188 pub terminal_foreground: Hsla,
189 /// Bright terminal foreground color.
190 pub terminal_bright_foreground: Hsla,
191 /// Dim terminal foreground color.
192 pub terminal_dim_foreground: Hsla,
193 /// Terminal ANSI background color.
194 pub terminal_ansi_background: Hsla,
195 /// Black ANSI terminal color.
196 pub terminal_ansi_black: Hsla,
197 /// Bright black ANSI terminal color.
198 pub terminal_ansi_bright_black: Hsla,
199 /// Dim black ANSI terminal color.
200 pub terminal_ansi_dim_black: Hsla,
201 /// Red ANSI terminal color.
202 pub terminal_ansi_red: Hsla,
203 /// Bright red ANSI terminal color.
204 pub terminal_ansi_bright_red: Hsla,
205 /// Dim red ANSI terminal color.
206 pub terminal_ansi_dim_red: Hsla,
207 /// Green ANSI terminal color.
208 pub terminal_ansi_green: Hsla,
209 /// Bright green ANSI terminal color.
210 pub terminal_ansi_bright_green: Hsla,
211 /// Dim green ANSI terminal color.
212 pub terminal_ansi_dim_green: Hsla,
213 /// Yellow ANSI terminal color.
214 pub terminal_ansi_yellow: Hsla,
215 /// Bright yellow ANSI terminal color.
216 pub terminal_ansi_bright_yellow: Hsla,
217 /// Dim yellow ANSI terminal color.
218 pub terminal_ansi_dim_yellow: Hsla,
219 /// Blue ANSI terminal color.
220 pub terminal_ansi_blue: Hsla,
221 /// Bright blue ANSI terminal color.
222 pub terminal_ansi_bright_blue: Hsla,
223 /// Dim blue ANSI terminal color.
224 pub terminal_ansi_dim_blue: Hsla,
225 /// Magenta ANSI terminal color.
226 pub terminal_ansi_magenta: Hsla,
227 /// Bright magenta ANSI terminal color.
228 pub terminal_ansi_bright_magenta: Hsla,
229 /// Dim magenta ANSI terminal color.
230 pub terminal_ansi_dim_magenta: Hsla,
231 /// Cyan ANSI terminal color.
232 pub terminal_ansi_cyan: Hsla,
233 /// Bright cyan ANSI terminal color.
234 pub terminal_ansi_bright_cyan: Hsla,
235 /// Dim cyan ANSI terminal color.
236 pub terminal_ansi_dim_cyan: Hsla,
237 /// White ANSI terminal color.
238 pub terminal_ansi_white: Hsla,
239 /// Bright white ANSI terminal color.
240 pub terminal_ansi_bright_white: Hsla,
241 /// Dim white ANSI terminal color.
242 pub terminal_ansi_dim_white: Hsla,
243
244 /// Represents a link text hover color.
245 pub link_text_hover: Hsla,
246
247 /// Represents an added entry or hunk in vcs, like git.
248 pub version_control_added: Hsla,
249 /// Represents a deleted entry in version control systems.
250 pub version_control_deleted: Hsla,
251 /// Represents a modified entry in version control systems.
252 pub version_control_modified: Hsla,
253 /// Represents a renamed entry in version control systems.
254 pub version_control_renamed: Hsla,
255 /// Represents a conflicting entry in version control systems.
256 pub version_control_conflict: Hsla,
257 /// Represents an ignored entry in version control systems.
258 pub version_control_ignored: Hsla,
259}
260
261#[derive(EnumIter, Debug, Clone, Copy, AsRefStr)]
262#[strum(serialize_all = "snake_case")]
263pub enum ThemeColorField {
264 Border,
265 BorderVariant,
266 BorderFocused,
267 BorderSelected,
268 BorderTransparent,
269 BorderDisabled,
270 ElevatedSurfaceBackground,
271 SurfaceBackground,
272 Background,
273 ElementBackground,
274 ElementHover,
275 ElementActive,
276 ElementSelected,
277 ElementDisabled,
278 DropTargetBackground,
279 GhostElementBackground,
280 GhostElementHover,
281 GhostElementActive,
282 GhostElementSelected,
283 GhostElementDisabled,
284 Text,
285 TextMuted,
286 TextPlaceholder,
287 TextDisabled,
288 TextAccent,
289 Icon,
290 IconMuted,
291 IconDisabled,
292 IconPlaceholder,
293 IconAccent,
294 StatusBarBackground,
295 TitleBarBackground,
296 TitleBarInactiveBackground,
297 ToolbarBackground,
298 TabBarBackground,
299 TabInactiveBackground,
300 TabActiveBackground,
301 SearchMatchBackground,
302 PanelBackground,
303 PanelFocusedBorder,
304 PanelIndentGuide,
305 PanelIndentGuideHover,
306 PanelIndentGuideActive,
307 PaneFocusedBorder,
308 PaneGroupBorder,
309 ScrollbarThumbBackground,
310 ScrollbarThumbHoverBackground,
311 ScrollbarThumbBorder,
312 ScrollbarTrackBackground,
313 ScrollbarTrackBorder,
314 EditorForeground,
315 EditorBackground,
316 EditorGutterBackground,
317 EditorSubheaderBackground,
318 EditorActiveLineBackground,
319 EditorHighlightedLineBackground,
320 EditorLineNumber,
321 EditorActiveLineNumber,
322 EditorInvisible,
323 EditorWrapGuide,
324 EditorActiveWrapGuide,
325 EditorIndentGuide,
326 EditorIndentGuideActive,
327 EditorDocumentHighlightReadBackground,
328 EditorDocumentHighlightWriteBackground,
329 EditorDocumentHighlightBracketBackground,
330 TerminalBackground,
331 TerminalForeground,
332 TerminalBrightForeground,
333 TerminalDimForeground,
334 TerminalAnsiBackground,
335 TerminalAnsiBlack,
336 TerminalAnsiBrightBlack,
337 TerminalAnsiDimBlack,
338 TerminalAnsiRed,
339 TerminalAnsiBrightRed,
340 TerminalAnsiDimRed,
341 TerminalAnsiGreen,
342 TerminalAnsiBrightGreen,
343 TerminalAnsiDimGreen,
344 TerminalAnsiYellow,
345 TerminalAnsiBrightYellow,
346 TerminalAnsiDimYellow,
347 TerminalAnsiBlue,
348 TerminalAnsiBrightBlue,
349 TerminalAnsiDimBlue,
350 TerminalAnsiMagenta,
351 TerminalAnsiBrightMagenta,
352 TerminalAnsiDimMagenta,
353 TerminalAnsiCyan,
354 TerminalAnsiBrightCyan,
355 TerminalAnsiDimCyan,
356 TerminalAnsiWhite,
357 TerminalAnsiBrightWhite,
358 TerminalAnsiDimWhite,
359 LinkTextHover,
360 VersionControlAdded,
361 VersionControlDeleted,
362 VersionControlModified,
363 VersionControlRenamed,
364 VersionControlConflict,
365 VersionControlIgnored,
366}
367
368impl ThemeColors {
369 pub fn color(&self, field: ThemeColorField) -> Hsla {
370 match field {
371 ThemeColorField::Border => self.border,
372 ThemeColorField::BorderVariant => self.border_variant,
373 ThemeColorField::BorderFocused => self.border_focused,
374 ThemeColorField::BorderSelected => self.border_selected,
375 ThemeColorField::BorderTransparent => self.border_transparent,
376 ThemeColorField::BorderDisabled => self.border_disabled,
377 ThemeColorField::ElevatedSurfaceBackground => self.elevated_surface_background,
378 ThemeColorField::SurfaceBackground => self.surface_background,
379 ThemeColorField::Background => self.background,
380 ThemeColorField::ElementBackground => self.element_background,
381 ThemeColorField::ElementHover => self.element_hover,
382 ThemeColorField::ElementActive => self.element_active,
383 ThemeColorField::ElementSelected => self.element_selected,
384 ThemeColorField::ElementDisabled => self.element_disabled,
385 ThemeColorField::DropTargetBackground => self.drop_target_background,
386 ThemeColorField::GhostElementBackground => self.ghost_element_background,
387 ThemeColorField::GhostElementHover => self.ghost_element_hover,
388 ThemeColorField::GhostElementActive => self.ghost_element_active,
389 ThemeColorField::GhostElementSelected => self.ghost_element_selected,
390 ThemeColorField::GhostElementDisabled => self.ghost_element_disabled,
391 ThemeColorField::Text => self.text,
392 ThemeColorField::TextMuted => self.text_muted,
393 ThemeColorField::TextPlaceholder => self.text_placeholder,
394 ThemeColorField::TextDisabled => self.text_disabled,
395 ThemeColorField::TextAccent => self.text_accent,
396 ThemeColorField::Icon => self.icon,
397 ThemeColorField::IconMuted => self.icon_muted,
398 ThemeColorField::IconDisabled => self.icon_disabled,
399 ThemeColorField::IconPlaceholder => self.icon_placeholder,
400 ThemeColorField::IconAccent => self.icon_accent,
401 ThemeColorField::StatusBarBackground => self.status_bar_background,
402 ThemeColorField::TitleBarBackground => self.title_bar_background,
403 ThemeColorField::TitleBarInactiveBackground => self.title_bar_inactive_background,
404 ThemeColorField::ToolbarBackground => self.toolbar_background,
405 ThemeColorField::TabBarBackground => self.tab_bar_background,
406 ThemeColorField::TabInactiveBackground => self.tab_inactive_background,
407 ThemeColorField::TabActiveBackground => self.tab_active_background,
408 ThemeColorField::SearchMatchBackground => self.search_match_background,
409 ThemeColorField::PanelBackground => self.panel_background,
410 ThemeColorField::PanelFocusedBorder => self.panel_focused_border,
411 ThemeColorField::PanelIndentGuide => self.panel_indent_guide,
412 ThemeColorField::PanelIndentGuideHover => self.panel_indent_guide_hover,
413 ThemeColorField::PanelIndentGuideActive => self.panel_indent_guide_active,
414 ThemeColorField::PaneFocusedBorder => self.pane_focused_border,
415 ThemeColorField::PaneGroupBorder => self.pane_group_border,
416 ThemeColorField::ScrollbarThumbBackground => self.scrollbar_thumb_background,
417 ThemeColorField::ScrollbarThumbHoverBackground => self.scrollbar_thumb_hover_background,
418 ThemeColorField::ScrollbarThumbBorder => self.scrollbar_thumb_border,
419 ThemeColorField::ScrollbarTrackBackground => self.scrollbar_track_background,
420 ThemeColorField::ScrollbarTrackBorder => self.scrollbar_track_border,
421 ThemeColorField::EditorForeground => self.editor_foreground,
422 ThemeColorField::EditorBackground => self.editor_background,
423 ThemeColorField::EditorGutterBackground => self.editor_gutter_background,
424 ThemeColorField::EditorSubheaderBackground => self.editor_subheader_background,
425 ThemeColorField::EditorActiveLineBackground => self.editor_active_line_background,
426 ThemeColorField::EditorHighlightedLineBackground => {
427 self.editor_highlighted_line_background
428 }
429 ThemeColorField::EditorLineNumber => self.editor_line_number,
430 ThemeColorField::EditorActiveLineNumber => self.editor_active_line_number,
431 ThemeColorField::EditorInvisible => self.editor_invisible,
432 ThemeColorField::EditorWrapGuide => self.editor_wrap_guide,
433 ThemeColorField::EditorActiveWrapGuide => self.editor_active_wrap_guide,
434 ThemeColorField::EditorIndentGuide => self.editor_indent_guide,
435 ThemeColorField::EditorIndentGuideActive => self.editor_indent_guide_active,
436 ThemeColorField::EditorDocumentHighlightReadBackground => {
437 self.editor_document_highlight_read_background
438 }
439 ThemeColorField::EditorDocumentHighlightWriteBackground => {
440 self.editor_document_highlight_write_background
441 }
442 ThemeColorField::EditorDocumentHighlightBracketBackground => {
443 self.editor_document_highlight_bracket_background
444 }
445 ThemeColorField::TerminalBackground => self.terminal_background,
446 ThemeColorField::TerminalForeground => self.terminal_foreground,
447 ThemeColorField::TerminalBrightForeground => self.terminal_bright_foreground,
448 ThemeColorField::TerminalDimForeground => self.terminal_dim_foreground,
449 ThemeColorField::TerminalAnsiBackground => self.terminal_ansi_background,
450 ThemeColorField::TerminalAnsiBlack => self.terminal_ansi_black,
451 ThemeColorField::TerminalAnsiBrightBlack => self.terminal_ansi_bright_black,
452 ThemeColorField::TerminalAnsiDimBlack => self.terminal_ansi_dim_black,
453 ThemeColorField::TerminalAnsiRed => self.terminal_ansi_red,
454 ThemeColorField::TerminalAnsiBrightRed => self.terminal_ansi_bright_red,
455 ThemeColorField::TerminalAnsiDimRed => self.terminal_ansi_dim_red,
456 ThemeColorField::TerminalAnsiGreen => self.terminal_ansi_green,
457 ThemeColorField::TerminalAnsiBrightGreen => self.terminal_ansi_bright_green,
458 ThemeColorField::TerminalAnsiDimGreen => self.terminal_ansi_dim_green,
459 ThemeColorField::TerminalAnsiYellow => self.terminal_ansi_yellow,
460 ThemeColorField::TerminalAnsiBrightYellow => self.terminal_ansi_bright_yellow,
461 ThemeColorField::TerminalAnsiDimYellow => self.terminal_ansi_dim_yellow,
462 ThemeColorField::TerminalAnsiBlue => self.terminal_ansi_blue,
463 ThemeColorField::TerminalAnsiBrightBlue => self.terminal_ansi_bright_blue,
464 ThemeColorField::TerminalAnsiDimBlue => self.terminal_ansi_dim_blue,
465 ThemeColorField::TerminalAnsiMagenta => self.terminal_ansi_magenta,
466 ThemeColorField::TerminalAnsiBrightMagenta => self.terminal_ansi_bright_magenta,
467 ThemeColorField::TerminalAnsiDimMagenta => self.terminal_ansi_dim_magenta,
468 ThemeColorField::TerminalAnsiCyan => self.terminal_ansi_cyan,
469 ThemeColorField::TerminalAnsiBrightCyan => self.terminal_ansi_bright_cyan,
470 ThemeColorField::TerminalAnsiDimCyan => self.terminal_ansi_dim_cyan,
471 ThemeColorField::TerminalAnsiWhite => self.terminal_ansi_white,
472 ThemeColorField::TerminalAnsiBrightWhite => self.terminal_ansi_bright_white,
473 ThemeColorField::TerminalAnsiDimWhite => self.terminal_ansi_dim_white,
474 ThemeColorField::LinkTextHover => self.link_text_hover,
475 ThemeColorField::VersionControlAdded => self.version_control_added,
476 ThemeColorField::VersionControlDeleted => self.version_control_deleted,
477 ThemeColorField::VersionControlModified => self.version_control_modified,
478 ThemeColorField::VersionControlRenamed => self.version_control_renamed,
479 ThemeColorField::VersionControlConflict => self.version_control_conflict,
480 ThemeColorField::VersionControlIgnored => self.version_control_ignored,
481 }
482 }
483
484 pub fn iter(&self) -> impl Iterator<Item = (ThemeColorField, Hsla)> + '_ {
485 ThemeColorField::iter().map(move |field| (field, self.color(field)))
486 }
487
488 pub fn to_vec(&self) -> Vec<(ThemeColorField, Hsla)> {
489 self.iter().collect()
490 }
491}
492
493pub fn all_theme_colors(cx: &mut App) -> Vec<(Hsla, SharedString)> {
494 let theme = cx.theme();
495 ThemeColorField::iter()
496 .map(|field| {
497 let color = theme.colors().color(field);
498 let name = field.as_ref().to_string();
499 (color, SharedString::from(name))
500 })
501 .collect()
502}
503
504#[derive(Refineable, Clone, PartialEq)]
505pub struct ThemeStyles {
506 /// The background appearance of the window.
507 pub window_background_appearance: WindowBackgroundAppearance,
508 pub system: SystemColors,
509 /// An array of colors used for theme elements that iterate through a series of colors.
510 ///
511 /// Example: Player colors, rainbow brackets and indent guides, etc.
512 pub accents: AccentColors,
513
514 #[refineable]
515 pub colors: ThemeColors,
516
517 #[refineable]
518 pub status: StatusColors,
519
520 pub player: PlayerColors,
521
522 pub syntax: Arc<SyntaxTheme>,
523}
524
525#[cfg(test)]
526mod tests {
527 use serde_json::json;
528
529 use super::*;
530
531 #[test]
532 fn override_a_single_theme_color() {
533 let mut colors = ThemeColors::light();
534
535 let magenta: Hsla = gpui::rgb(0xff00ff).into();
536
537 assert_ne!(colors.text, magenta);
538
539 let overrides = ThemeColorsRefinement {
540 text: Some(magenta),
541 ..Default::default()
542 };
543
544 colors.refine(&overrides);
545
546 assert_eq!(colors.text, magenta);
547 }
548
549 #[test]
550 fn override_multiple_theme_colors() {
551 let mut colors = ThemeColors::light();
552
553 let magenta: Hsla = gpui::rgb(0xff00ff).into();
554 let green: Hsla = gpui::rgb(0x00ff00).into();
555
556 assert_ne!(colors.text, magenta);
557 assert_ne!(colors.background, green);
558
559 let overrides = ThemeColorsRefinement {
560 text: Some(magenta),
561 background: Some(green),
562 ..Default::default()
563 };
564
565 colors.refine(&overrides);
566
567 assert_eq!(colors.text, magenta);
568 assert_eq!(colors.background, green);
569 }
570
571 #[test]
572 fn deserialize_theme_colors_refinement_from_json() {
573 let colors: ThemeColorsRefinement = serde_json::from_value(json!({
574 "background": "#ff00ff",
575 "text": "#ff0000"
576 }))
577 .unwrap();
578
579 assert_eq!(colors.background, Some(gpui::rgb(0xff00ff).into()));
580 assert_eq!(colors.text, Some(gpui::rgb(0xff0000).into()));
581 }
582}