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