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