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
304    /// Represents the "ours" region of a merge conflict.
305    pub version_control_conflict_marker_ours: Hsla,
306    /// Represents the "theirs" region of a merge conflict.
307    pub version_control_conflict_marker_theirs: Hsla,
308}
309
310#[derive(EnumIter, Debug, Clone, Copy, AsRefStr)]
311#[strum(serialize_all = "snake_case")]
312pub enum ThemeColorField {
313    Border,
314    BorderVariant,
315    BorderFocused,
316    BorderSelected,
317    BorderTransparent,
318    BorderDisabled,
319    ElevatedSurfaceBackground,
320    SurfaceBackground,
321    Background,
322    ElementBackground,
323    ElementHover,
324    ElementActive,
325    ElementSelected,
326    ElementDisabled,
327    DropTargetBackground,
328    DropTargetBorder,
329    GhostElementBackground,
330    GhostElementHover,
331    GhostElementActive,
332    GhostElementSelected,
333    GhostElementDisabled,
334    Text,
335    TextMuted,
336    TextPlaceholder,
337    TextDisabled,
338    TextAccent,
339    Icon,
340    IconMuted,
341    IconDisabled,
342    IconPlaceholder,
343    IconAccent,
344    StatusBarBackground,
345    TitleBarBackground,
346    TitleBarInactiveBackground,
347    ToolbarBackground,
348    TabBarBackground,
349    TabInactiveBackground,
350    TabActiveBackground,
351    SearchMatchBackground,
352    PanelBackground,
353    PanelFocusedBorder,
354    PanelIndentGuide,
355    PanelIndentGuideHover,
356    PanelIndentGuideActive,
357    PanelOverlayBackground,
358    PanelOverlayHover,
359    PaneFocusedBorder,
360    PaneGroupBorder,
361    ScrollbarThumbBackground,
362    ScrollbarThumbHoverBackground,
363    ScrollbarThumbActiveBackground,
364    ScrollbarThumbBorder,
365    ScrollbarTrackBackground,
366    ScrollbarTrackBorder,
367    MinimapThumbBackground,
368    MinimapThumbHoverBackground,
369    MinimapThumbActiveBackground,
370    MinimapThumbBorder,
371    EditorForeground,
372    EditorBackground,
373    EditorGutterBackground,
374    EditorSubheaderBackground,
375    EditorActiveLineBackground,
376    EditorHighlightedLineBackground,
377    EditorLineNumber,
378    EditorActiveLineNumber,
379    EditorInvisible,
380    EditorWrapGuide,
381    EditorActiveWrapGuide,
382    EditorIndentGuide,
383    EditorIndentGuideActive,
384    EditorDocumentHighlightReadBackground,
385    EditorDocumentHighlightWriteBackground,
386    EditorDocumentHighlightBracketBackground,
387    TerminalBackground,
388    TerminalForeground,
389    TerminalBrightForeground,
390    TerminalDimForeground,
391    TerminalAnsiBackground,
392    TerminalAnsiBlack,
393    TerminalAnsiBrightBlack,
394    TerminalAnsiDimBlack,
395    TerminalAnsiRed,
396    TerminalAnsiBrightRed,
397    TerminalAnsiDimRed,
398    TerminalAnsiGreen,
399    TerminalAnsiBrightGreen,
400    TerminalAnsiDimGreen,
401    TerminalAnsiYellow,
402    TerminalAnsiBrightYellow,
403    TerminalAnsiDimYellow,
404    TerminalAnsiBlue,
405    TerminalAnsiBrightBlue,
406    TerminalAnsiDimBlue,
407    TerminalAnsiMagenta,
408    TerminalAnsiBrightMagenta,
409    TerminalAnsiDimMagenta,
410    TerminalAnsiCyan,
411    TerminalAnsiBrightCyan,
412    TerminalAnsiDimCyan,
413    TerminalAnsiWhite,
414    TerminalAnsiBrightWhite,
415    TerminalAnsiDimWhite,
416    LinkTextHover,
417    VersionControlAdded,
418    VersionControlDeleted,
419    VersionControlModified,
420    VersionControlRenamed,
421    VersionControlConflict,
422    VersionControlIgnored,
423}
424
425impl ThemeColors {
426    pub fn color(&self, field: ThemeColorField) -> Hsla {
427        match field {
428            ThemeColorField::Border => self.border,
429            ThemeColorField::BorderVariant => self.border_variant,
430            ThemeColorField::BorderFocused => self.border_focused,
431            ThemeColorField::BorderSelected => self.border_selected,
432            ThemeColorField::BorderTransparent => self.border_transparent,
433            ThemeColorField::BorderDisabled => self.border_disabled,
434            ThemeColorField::ElevatedSurfaceBackground => self.elevated_surface_background,
435            ThemeColorField::SurfaceBackground => self.surface_background,
436            ThemeColorField::Background => self.background,
437            ThemeColorField::ElementBackground => self.element_background,
438            ThemeColorField::ElementHover => self.element_hover,
439            ThemeColorField::ElementActive => self.element_active,
440            ThemeColorField::ElementSelected => self.element_selected,
441            ThemeColorField::ElementDisabled => self.element_disabled,
442            ThemeColorField::DropTargetBackground => self.drop_target_background,
443            ThemeColorField::DropTargetBorder => self.drop_target_border,
444            ThemeColorField::GhostElementBackground => self.ghost_element_background,
445            ThemeColorField::GhostElementHover => self.ghost_element_hover,
446            ThemeColorField::GhostElementActive => self.ghost_element_active,
447            ThemeColorField::GhostElementSelected => self.ghost_element_selected,
448            ThemeColorField::GhostElementDisabled => self.ghost_element_disabled,
449            ThemeColorField::Text => self.text,
450            ThemeColorField::TextMuted => self.text_muted,
451            ThemeColorField::TextPlaceholder => self.text_placeholder,
452            ThemeColorField::TextDisabled => self.text_disabled,
453            ThemeColorField::TextAccent => self.text_accent,
454            ThemeColorField::Icon => self.icon,
455            ThemeColorField::IconMuted => self.icon_muted,
456            ThemeColorField::IconDisabled => self.icon_disabled,
457            ThemeColorField::IconPlaceholder => self.icon_placeholder,
458            ThemeColorField::IconAccent => self.icon_accent,
459            ThemeColorField::StatusBarBackground => self.status_bar_background,
460            ThemeColorField::TitleBarBackground => self.title_bar_background,
461            ThemeColorField::TitleBarInactiveBackground => self.title_bar_inactive_background,
462            ThemeColorField::ToolbarBackground => self.toolbar_background,
463            ThemeColorField::TabBarBackground => self.tab_bar_background,
464            ThemeColorField::TabInactiveBackground => self.tab_inactive_background,
465            ThemeColorField::TabActiveBackground => self.tab_active_background,
466            ThemeColorField::SearchMatchBackground => self.search_match_background,
467            ThemeColorField::PanelBackground => self.panel_background,
468            ThemeColorField::PanelFocusedBorder => self.panel_focused_border,
469            ThemeColorField::PanelIndentGuide => self.panel_indent_guide,
470            ThemeColorField::PanelIndentGuideHover => self.panel_indent_guide_hover,
471            ThemeColorField::PanelIndentGuideActive => self.panel_indent_guide_active,
472            ThemeColorField::PanelOverlayBackground => self.panel_overlay_background,
473            ThemeColorField::PanelOverlayHover => self.panel_overlay_hover,
474            ThemeColorField::PaneFocusedBorder => self.pane_focused_border,
475            ThemeColorField::PaneGroupBorder => self.pane_group_border,
476            ThemeColorField::ScrollbarThumbBackground => self.scrollbar_thumb_background,
477            ThemeColorField::ScrollbarThumbHoverBackground => self.scrollbar_thumb_hover_background,
478            ThemeColorField::ScrollbarThumbActiveBackground => {
479                self.scrollbar_thumb_active_background
480            }
481            ThemeColorField::ScrollbarThumbBorder => self.scrollbar_thumb_border,
482            ThemeColorField::ScrollbarTrackBackground => self.scrollbar_track_background,
483            ThemeColorField::ScrollbarTrackBorder => self.scrollbar_track_border,
484            ThemeColorField::MinimapThumbBackground => self.minimap_thumb_background,
485            ThemeColorField::MinimapThumbHoverBackground => self.minimap_thumb_hover_background,
486            ThemeColorField::MinimapThumbActiveBackground => self.minimap_thumb_active_background,
487            ThemeColorField::MinimapThumbBorder => self.minimap_thumb_border,
488            ThemeColorField::EditorForeground => self.editor_foreground,
489            ThemeColorField::EditorBackground => self.editor_background,
490            ThemeColorField::EditorGutterBackground => self.editor_gutter_background,
491            ThemeColorField::EditorSubheaderBackground => self.editor_subheader_background,
492            ThemeColorField::EditorActiveLineBackground => self.editor_active_line_background,
493            ThemeColorField::EditorHighlightedLineBackground => {
494                self.editor_highlighted_line_background
495            }
496            ThemeColorField::EditorLineNumber => self.editor_line_number,
497            ThemeColorField::EditorActiveLineNumber => self.editor_active_line_number,
498            ThemeColorField::EditorInvisible => self.editor_invisible,
499            ThemeColorField::EditorWrapGuide => self.editor_wrap_guide,
500            ThemeColorField::EditorActiveWrapGuide => self.editor_active_wrap_guide,
501            ThemeColorField::EditorIndentGuide => self.editor_indent_guide,
502            ThemeColorField::EditorIndentGuideActive => self.editor_indent_guide_active,
503            ThemeColorField::EditorDocumentHighlightReadBackground => {
504                self.editor_document_highlight_read_background
505            }
506            ThemeColorField::EditorDocumentHighlightWriteBackground => {
507                self.editor_document_highlight_write_background
508            }
509            ThemeColorField::EditorDocumentHighlightBracketBackground => {
510                self.editor_document_highlight_bracket_background
511            }
512            ThemeColorField::TerminalBackground => self.terminal_background,
513            ThemeColorField::TerminalForeground => self.terminal_foreground,
514            ThemeColorField::TerminalBrightForeground => self.terminal_bright_foreground,
515            ThemeColorField::TerminalDimForeground => self.terminal_dim_foreground,
516            ThemeColorField::TerminalAnsiBackground => self.terminal_ansi_background,
517            ThemeColorField::TerminalAnsiBlack => self.terminal_ansi_black,
518            ThemeColorField::TerminalAnsiBrightBlack => self.terminal_ansi_bright_black,
519            ThemeColorField::TerminalAnsiDimBlack => self.terminal_ansi_dim_black,
520            ThemeColorField::TerminalAnsiRed => self.terminal_ansi_red,
521            ThemeColorField::TerminalAnsiBrightRed => self.terminal_ansi_bright_red,
522            ThemeColorField::TerminalAnsiDimRed => self.terminal_ansi_dim_red,
523            ThemeColorField::TerminalAnsiGreen => self.terminal_ansi_green,
524            ThemeColorField::TerminalAnsiBrightGreen => self.terminal_ansi_bright_green,
525            ThemeColorField::TerminalAnsiDimGreen => self.terminal_ansi_dim_green,
526            ThemeColorField::TerminalAnsiYellow => self.terminal_ansi_yellow,
527            ThemeColorField::TerminalAnsiBrightYellow => self.terminal_ansi_bright_yellow,
528            ThemeColorField::TerminalAnsiDimYellow => self.terminal_ansi_dim_yellow,
529            ThemeColorField::TerminalAnsiBlue => self.terminal_ansi_blue,
530            ThemeColorField::TerminalAnsiBrightBlue => self.terminal_ansi_bright_blue,
531            ThemeColorField::TerminalAnsiDimBlue => self.terminal_ansi_dim_blue,
532            ThemeColorField::TerminalAnsiMagenta => self.terminal_ansi_magenta,
533            ThemeColorField::TerminalAnsiBrightMagenta => self.terminal_ansi_bright_magenta,
534            ThemeColorField::TerminalAnsiDimMagenta => self.terminal_ansi_dim_magenta,
535            ThemeColorField::TerminalAnsiCyan => self.terminal_ansi_cyan,
536            ThemeColorField::TerminalAnsiBrightCyan => self.terminal_ansi_bright_cyan,
537            ThemeColorField::TerminalAnsiDimCyan => self.terminal_ansi_dim_cyan,
538            ThemeColorField::TerminalAnsiWhite => self.terminal_ansi_white,
539            ThemeColorField::TerminalAnsiBrightWhite => self.terminal_ansi_bright_white,
540            ThemeColorField::TerminalAnsiDimWhite => self.terminal_ansi_dim_white,
541            ThemeColorField::LinkTextHover => self.link_text_hover,
542            ThemeColorField::VersionControlAdded => self.version_control_added,
543            ThemeColorField::VersionControlDeleted => self.version_control_deleted,
544            ThemeColorField::VersionControlModified => self.version_control_modified,
545            ThemeColorField::VersionControlRenamed => self.version_control_renamed,
546            ThemeColorField::VersionControlConflict => self.version_control_conflict,
547            ThemeColorField::VersionControlIgnored => self.version_control_ignored,
548        }
549    }
550
551    pub fn iter(&self) -> impl Iterator<Item = (ThemeColorField, Hsla)> + '_ {
552        ThemeColorField::iter().map(move |field| (field, self.color(field)))
553    }
554
555    pub fn to_vec(&self) -> Vec<(ThemeColorField, Hsla)> {
556        self.iter().collect()
557    }
558}
559
560pub fn all_theme_colors(cx: &mut App) -> Vec<(Hsla, SharedString)> {
561    let theme = cx.theme();
562    ThemeColorField::iter()
563        .map(|field| {
564            let color = theme.colors().color(field);
565            let name = field.as_ref().to_string();
566            (color, SharedString::from(name))
567        })
568        .collect()
569}
570
571#[derive(Refineable, Clone, Debug, PartialEq)]
572pub struct ThemeStyles {
573    /// The background appearance of the window.
574    pub window_background_appearance: WindowBackgroundAppearance,
575    pub system: SystemColors,
576    /// An array of colors used for theme elements that iterate through a series of colors.
577    ///
578    /// Example: Player colors, rainbow brackets and indent guides, etc.
579    pub accents: AccentColors,
580
581    #[refineable]
582    pub colors: ThemeColors,
583
584    #[refineable]
585    pub status: StatusColors,
586
587    pub player: PlayerColors,
588
589    pub syntax: Arc<SyntaxTheme>,
590}
591
592#[cfg(test)]
593mod tests {
594    use serde_json::json;
595
596    use super::*;
597
598    #[test]
599    fn override_a_single_theme_color() {
600        let mut colors = ThemeColors::light();
601
602        let magenta: Hsla = gpui::rgb(0xff00ff).into();
603
604        assert_ne!(colors.text, magenta);
605
606        let overrides = ThemeColorsRefinement {
607            text: Some(magenta),
608            ..Default::default()
609        };
610
611        colors.refine(&overrides);
612
613        assert_eq!(colors.text, magenta);
614    }
615
616    #[test]
617    fn override_multiple_theme_colors() {
618        let mut colors = ThemeColors::light();
619
620        let magenta: Hsla = gpui::rgb(0xff00ff).into();
621        let green: Hsla = gpui::rgb(0x00ff00).into();
622
623        assert_ne!(colors.text, magenta);
624        assert_ne!(colors.background, green);
625
626        let overrides = ThemeColorsRefinement {
627            text: Some(magenta),
628            background: Some(green),
629            ..Default::default()
630        };
631
632        colors.refine(&overrides);
633
634        assert_eq!(colors.text, magenta);
635        assert_eq!(colors.background, green);
636    }
637
638    #[test]
639    fn deserialize_theme_colors_refinement_from_json() {
640        let colors: ThemeColorsRefinement = serde_json::from_value(json!({
641            "background": "#ff00ff",
642            "text": "#ff0000"
643        }))
644        .unwrap();
645
646        assert_eq!(colors.background, Some(gpui::rgb(0xff00ff).into()));
647        assert_eq!(colors.text, Some(gpui::rgb(0xff0000).into()));
648    }
649}