colors.rs

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