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