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