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