fallback_themes.rs

  1use std::sync::Arc;
  2
  3use gpui::{FontStyle, FontWeight, HighlightStyle, Hsla, WindowBackgroundAppearance, hsla};
  4
  5use crate::{
  6    AccentColors, Appearance, DEFAULT_DARK_THEME, PlayerColors, StatusColors,
  7    StatusColorsRefinement, SyntaxTheme, SystemColors, Theme, ThemeColors, ThemeColorsRefinement,
  8    ThemeFamily, ThemeStyles, default_color_scales,
  9};
 10
 11/// The default theme family for Zed.
 12///
 13/// This is used to construct the default theme fallback values, as well as to
 14/// have a theme available at compile time for tests.
 15pub fn zed_default_themes() -> ThemeFamily {
 16    ThemeFamily {
 17        id: "zed-default".to_string(),
 18        name: "Zed Default".into(),
 19        author: "".into(),
 20        themes: vec![zed_default_dark()],
 21        scales: default_color_scales(),
 22    }
 23}
 24
 25// If a theme customizes a foreground version of a status color, but does not
 26// customize the background color, then use a partly-transparent version of the
 27// foreground color for the background color.
 28/// Applies default status color backgrounds from their foreground counterparts.
 29pub fn apply_status_color_defaults(status: &mut StatusColorsRefinement) {
 30    for (fg_color, bg_color) in [
 31        (&status.deleted, &mut status.deleted_background),
 32        (&status.created, &mut status.created_background),
 33        (&status.modified, &mut status.modified_background),
 34        (&status.conflict, &mut status.conflict_background),
 35        (&status.error, &mut status.error_background),
 36        (&status.hidden, &mut status.hidden_background),
 37    ] {
 38        if bg_color.is_none()
 39            && let Some(fg_color) = fg_color
 40        {
 41            *bg_color = Some(fg_color.opacity(0.25));
 42        }
 43    }
 44}
 45
 46/// Applies default theme color values derived from player colors.
 47pub fn apply_theme_color_defaults(
 48    theme_colors: &mut ThemeColorsRefinement,
 49    player_colors: &PlayerColors,
 50) {
 51    if theme_colors.element_selection_background.is_none() {
 52        let mut selection = player_colors.local().selection;
 53        if selection.a == 1.0 {
 54            selection.a = 0.25;
 55        }
 56        theme_colors.element_selection_background = Some(selection);
 57    }
 58}
 59
 60pub(crate) fn zed_default_dark() -> Theme {
 61    let bg = hsla(215. / 360., 12. / 100., 15. / 100., 1.);
 62    let editor = hsla(220. / 360., 12. / 100., 18. / 100., 1.);
 63    let elevated_surface = hsla(225. / 360., 12. / 100., 17. / 100., 1.);
 64    let hover = hsla(225.0 / 360., 11.8 / 100., 26.7 / 100., 1.0);
 65
 66    let blue = hsla(207.8 / 360., 81. / 100., 66. / 100., 1.0);
 67    let gray = hsla(218.8 / 360., 10. / 100., 40. / 100., 1.0);
 68    let green = hsla(95. / 360., 38. / 100., 62. / 100., 1.0);
 69    let orange = hsla(29. / 360., 54. / 100., 61. / 100., 1.0);
 70    let purple = hsla(286. / 360., 51. / 100., 64. / 100., 1.0);
 71    let red = hsla(355. / 360., 65. / 100., 65. / 100., 1.0);
 72    let teal = hsla(187. / 360., 47. / 100., 55. / 100., 1.0);
 73    let yellow = hsla(39. / 360., 67. / 100., 69. / 100., 1.0);
 74
 75    const ADDED_COLOR: Hsla = Hsla {
 76        h: 134. / 360.,
 77        s: 0.55,
 78        l: 0.40,
 79        a: 1.0,
 80    };
 81    const WORD_ADDED_COLOR: Hsla = Hsla {
 82        h: 134. / 360.,
 83        s: 0.55,
 84        l: 0.40,
 85        a: 0.35,
 86    };
 87    const MODIFIED_COLOR: Hsla = Hsla {
 88        h: 48. / 360.,
 89        s: 0.76,
 90        l: 0.47,
 91        a: 1.0,
 92    };
 93    const REMOVED_COLOR: Hsla = Hsla {
 94        h: 350. / 360.,
 95        s: 0.88,
 96        l: 0.25,
 97        a: 1.0,
 98    };
 99    const WORD_DELETED_COLOR: Hsla = Hsla {
100        h: 350. / 360.,
101        s: 0.88,
102        l: 0.25,
103        a: 0.80,
104    };
105
106    let player = PlayerColors::dark();
107    Theme {
108        id: "one_dark".to_string(),
109        name: DEFAULT_DARK_THEME.into(),
110        appearance: Appearance::Dark,
111        styles: ThemeStyles {
112            window_background_appearance: WindowBackgroundAppearance::Opaque,
113            system: SystemColors::default(),
114            accents: AccentColors(Arc::from(vec![
115                blue, orange, purple, teal, red, green, yellow,
116            ])),
117            colors: ThemeColors {
118                border: hsla(225. / 360., 13. / 100., 12. / 100., 1.),
119                border_variant: hsla(228. / 360., 8. / 100., 25. / 100., 1.),
120                border_focused: hsla(223. / 360., 78. / 100., 65. / 100., 1.),
121                border_selected: hsla(222.6 / 360., 77.5 / 100., 65.1 / 100., 1.0),
122                border_transparent: SystemColors::default().transparent,
123                border_disabled: hsla(222.0 / 360., 11.6 / 100., 33.7 / 100., 1.0),
124                elevated_surface_background: elevated_surface,
125                surface_background: bg,
126                background: bg,
127                element_background: hsla(223.0 / 360., 13. / 100., 21. / 100., 1.0),
128                element_hover: hover,
129                element_active: hsla(220.0 / 360., 11.8 / 100., 20.0 / 100., 1.0),
130                element_selected: hsla(224.0 / 360., 11.3 / 100., 26.1 / 100., 1.0),
131                element_disabled: SystemColors::default().transparent,
132                element_selection_background: player.local().selection.alpha(0.25),
133                drop_target_background: hsla(220.0 / 360., 8.3 / 100., 21.4 / 100., 1.0),
134                drop_target_border: hsla(221. / 360., 11. / 100., 86. / 100., 1.0),
135                ghost_element_background: SystemColors::default().transparent,
136                ghost_element_hover: hover,
137                ghost_element_active: hsla(220.0 / 360., 11.8 / 100., 20.0 / 100., 1.0),
138                ghost_element_selected: hsla(224.0 / 360., 11.3 / 100., 26.1 / 100., 1.0),
139                ghost_element_disabled: SystemColors::default().transparent,
140                text: hsla(221. / 360., 11. / 100., 86. / 100., 1.0),
141                text_muted: hsla(218.0 / 360., 7. / 100., 46. / 100., 1.0),
142                text_placeholder: hsla(220.0 / 360., 6.6 / 100., 44.5 / 100., 1.0),
143                text_disabled: hsla(220.0 / 360., 6.6 / 100., 44.5 / 100., 1.0),
144                text_accent: hsla(222.6 / 360., 77.5 / 100., 65.1 / 100., 1.0),
145                icon: hsla(222.9 / 360., 9.9 / 100., 86.1 / 100., 1.0),
146                icon_muted: hsla(220.0 / 360., 12.1 / 100., 66.1 / 100., 1.0),
147                icon_disabled: hsla(220.0 / 360., 6.4 / 100., 45.7 / 100., 1.0),
148                icon_placeholder: hsla(220.0 / 360., 6.4 / 100., 45.7 / 100., 1.0),
149                icon_accent: blue,
150                debugger_accent: red,
151                status_bar_background: bg,
152                title_bar_background: bg,
153                title_bar_inactive_background: bg,
154                toolbar_background: editor,
155                tab_bar_background: bg,
156                tab_inactive_background: bg,
157                tab_active_background: editor,
158                search_match_background: bg,
159                search_active_match_background: bg,
160
161                editor_background: editor,
162                editor_gutter_background: editor,
163                editor_subheader_background: bg,
164                editor_active_line_background: hsla(222.9 / 360., 13.5 / 100., 20.4 / 100., 1.0),
165                editor_highlighted_line_background: hsla(207.8 / 360., 81. / 100., 66. / 100., 0.1),
166                editor_debugger_active_line_background: hsla(
167                    207.8 / 360.,
168                    81. / 100.,
169                    66. / 100.,
170                    0.2,
171                ),
172                editor_line_number: hsla(222.0 / 360., 11.5 / 100., 34.1 / 100., 1.0),
173                editor_active_line_number: hsla(216.0 / 360., 5.9 / 100., 49.6 / 100., 1.0),
174                editor_hover_line_number: hsla(216.0 / 360., 5.9 / 100., 56.7 / 100., 1.0),
175                editor_invisible: hsla(222.0 / 360., 11.5 / 100., 34.1 / 100., 1.0),
176                editor_wrap_guide: hsla(228. / 360., 8. / 100., 25. / 100., 1.),
177                editor_active_wrap_guide: hsla(228. / 360., 8. / 100., 25. / 100., 1.),
178                editor_indent_guide: hsla(228. / 360., 8. / 100., 25. / 100., 1.),
179                editor_indent_guide_active: hsla(225. / 360., 13. / 100., 12. / 100., 1.),
180                editor_document_highlight_read_background: hsla(
181                    207.8 / 360.,
182                    81. / 100.,
183                    66. / 100.,
184                    0.2,
185                ),
186                editor_document_highlight_write_background: gpui::red(),
187                editor_document_highlight_bracket_background: gpui::green(),
188
189                terminal_background: bg,
190                // todo("Use one colors for terminal")
191                terminal_ansi_background: crate::black().dark().step_12(),
192                terminal_foreground: crate::white().dark().step_12(),
193                terminal_bright_foreground: crate::white().dark().step_11(),
194                terminal_dim_foreground: crate::white().dark().step_10(),
195                terminal_ansi_black: crate::black().dark().step_12(),
196                terminal_ansi_red: crate::red().dark().step_11(),
197                terminal_ansi_green: crate::green().dark().step_11(),
198                terminal_ansi_yellow: crate::yellow().dark().step_11(),
199                terminal_ansi_blue: crate::blue().dark().step_11(),
200                terminal_ansi_magenta: crate::violet().dark().step_11(),
201                terminal_ansi_cyan: crate::cyan().dark().step_11(),
202                terminal_ansi_white: crate::neutral().dark().step_12(),
203                terminal_ansi_bright_black: crate::black().dark().step_11(),
204                terminal_ansi_bright_red: crate::red().dark().step_10(),
205                terminal_ansi_bright_green: crate::green().dark().step_10(),
206                terminal_ansi_bright_yellow: crate::yellow().dark().step_10(),
207                terminal_ansi_bright_blue: crate::blue().dark().step_10(),
208                terminal_ansi_bright_magenta: crate::violet().dark().step_10(),
209                terminal_ansi_bright_cyan: crate::cyan().dark().step_10(),
210                terminal_ansi_bright_white: crate::neutral().dark().step_11(),
211                terminal_ansi_dim_black: crate::black().dark().step_10(),
212                terminal_ansi_dim_red: crate::red().dark().step_9(),
213                terminal_ansi_dim_green: crate::green().dark().step_9(),
214                terminal_ansi_dim_yellow: crate::yellow().dark().step_9(),
215                terminal_ansi_dim_blue: crate::blue().dark().step_9(),
216                terminal_ansi_dim_magenta: crate::violet().dark().step_9(),
217                terminal_ansi_dim_cyan: crate::cyan().dark().step_9(),
218                terminal_ansi_dim_white: crate::neutral().dark().step_10(),
219                panel_background: bg,
220                panel_focused_border: blue,
221                panel_indent_guide: hsla(228. / 360., 8. / 100., 25. / 100., 1.),
222                panel_indent_guide_hover: hsla(225. / 360., 13. / 100., 12. / 100., 1.),
223                panel_indent_guide_active: hsla(225. / 360., 13. / 100., 12. / 100., 1.),
224                panel_overlay_background: bg,
225                panel_overlay_hover: hover,
226                pane_focused_border: blue,
227                pane_group_border: hsla(225. / 360., 13. / 100., 12. / 100., 1.),
228                scrollbar_thumb_background: gpui::transparent_black(),
229                scrollbar_thumb_hover_background: hover,
230                scrollbar_thumb_active_background: hsla(
231                    225.0 / 360.,
232                    11.8 / 100.,
233                    26.7 / 100.,
234                    1.0,
235                ),
236                scrollbar_thumb_border: hsla(228. / 360., 8. / 100., 25. / 100., 1.),
237                scrollbar_track_background: gpui::transparent_black(),
238                scrollbar_track_border: hsla(228. / 360., 8. / 100., 25. / 100., 1.),
239                minimap_thumb_background: hsla(225.0 / 360., 11.8 / 100., 26.7 / 100., 0.7),
240                minimap_thumb_hover_background: hsla(225.0 / 360., 11.8 / 100., 26.7 / 100., 0.7),
241                minimap_thumb_active_background: hsla(225.0 / 360., 11.8 / 100., 26.7 / 100., 0.7),
242                minimap_thumb_border: hsla(228. / 360., 8. / 100., 25. / 100., 1.),
243                editor_foreground: hsla(218. / 360., 14. / 100., 71. / 100., 1.),
244                link_text_hover: blue,
245                version_control_added: ADDED_COLOR,
246                version_control_deleted: REMOVED_COLOR,
247                version_control_modified: MODIFIED_COLOR,
248                version_control_renamed: MODIFIED_COLOR,
249                version_control_conflict: crate::orange().light().step_12(),
250                version_control_ignored: crate::gray().light().step_12(),
251                version_control_word_added: WORD_ADDED_COLOR,
252                version_control_word_deleted: WORD_DELETED_COLOR,
253                version_control_conflict_marker_ours: crate::green().light().step_12().alpha(0.5),
254                version_control_conflict_marker_theirs: crate::blue().light().step_12().alpha(0.5),
255
256                vim_normal_background: SystemColors::default().transparent,
257                vim_insert_background: SystemColors::default().transparent,
258                vim_replace_background: SystemColors::default().transparent,
259                vim_visual_background: SystemColors::default().transparent,
260                vim_visual_line_background: SystemColors::default().transparent,
261                vim_visual_block_background: SystemColors::default().transparent,
262                vim_yank_background: hsla(207.8 / 360., 81. / 100., 66. / 100., 0.2),
263                vim_helix_normal_background: SystemColors::default().transparent,
264                vim_helix_select_background: SystemColors::default().transparent,
265                vim_normal_foreground: SystemColors::default().transparent,
266                vim_insert_foreground: SystemColors::default().transparent,
267                vim_replace_foreground: SystemColors::default().transparent,
268                vim_visual_foreground: SystemColors::default().transparent,
269                vim_visual_line_foreground: SystemColors::default().transparent,
270                vim_visual_block_foreground: SystemColors::default().transparent,
271                vim_helix_normal_foreground: SystemColors::default().transparent,
272                vim_helix_select_foreground: SystemColors::default().transparent,
273            },
274            status: StatusColors {
275                conflict: yellow,
276                conflict_background: yellow,
277                conflict_border: yellow,
278                created: green,
279                created_background: green,
280                created_border: green,
281                deleted: red,
282                deleted_background: red,
283                deleted_border: red,
284                error: red,
285                error_background: red,
286                error_border: red,
287                hidden: gray,
288                hidden_background: gray,
289                hidden_border: gray,
290                hint: blue,
291                hint_background: blue,
292                hint_border: blue,
293                ignored: gray,
294                ignored_background: gray,
295                ignored_border: gray,
296                info: blue,
297                info_background: blue,
298                info_border: blue,
299                modified: yellow,
300                modified_background: yellow,
301                modified_border: yellow,
302                predictive: gray,
303                predictive_background: gray,
304                predictive_border: gray,
305                renamed: blue,
306                renamed_background: blue,
307                renamed_border: blue,
308                success: green,
309                success_background: green,
310                success_border: green,
311                unreachable: gray,
312                unreachable_background: gray,
313                unreachable_border: gray,
314                warning: yellow,
315                warning_background: yellow,
316                warning_border: yellow,
317            },
318            player,
319            syntax: Arc::new(SyntaxTheme::new(vec![
320                ("attribute".into(), purple.into()),
321                ("boolean".into(), orange.into()),
322                ("comment".into(), gray.into()),
323                ("comment.doc".into(), gray.into()),
324                ("constant".into(), yellow.into()),
325                ("constructor".into(), blue.into()),
326                ("embedded".into(), HighlightStyle::default()),
327                (
328                    "emphasis".into(),
329                    HighlightStyle {
330                        font_style: Some(FontStyle::Italic),
331                        ..HighlightStyle::default()
332                    },
333                ),
334                (
335                    "emphasis.strong".into(),
336                    HighlightStyle {
337                        font_weight: Some(FontWeight::BOLD),
338                        ..HighlightStyle::default()
339                    },
340                ),
341                ("enum".into(), teal.into()),
342                ("function".into(), blue.into()),
343                ("function.method".into(), blue.into()),
344                ("function.definition".into(), blue.into()),
345                ("hint".into(), blue.into()),
346                ("keyword".into(), purple.into()),
347                ("label".into(), HighlightStyle::default()),
348                ("link_text".into(), blue.into()),
349                (
350                    "link_uri".into(),
351                    HighlightStyle {
352                        color: Some(teal),
353                        font_style: Some(FontStyle::Italic),
354                        ..HighlightStyle::default()
355                    },
356                ),
357                ("number".into(), orange.into()),
358                ("operator".into(), HighlightStyle::default()),
359                ("predictive".into(), HighlightStyle::default()),
360                ("preproc".into(), purple.into()),
361                ("primary".into(), HighlightStyle::default()),
362                ("property".into(), red.into()),
363                ("punctuation".into(), HighlightStyle::default()),
364                ("punctuation.bracket".into(), HighlightStyle::default()),
365                ("punctuation.delimiter".into(), HighlightStyle::default()),
366                ("punctuation.list_marker".into(), HighlightStyle::default()),
367                ("punctuation.special".into(), HighlightStyle::default()),
368                ("string".into(), green.into()),
369                ("string.escape".into(), HighlightStyle::default()),
370                ("string.regex".into(), red.into()),
371                ("string.special".into(), HighlightStyle::default()),
372                ("string.special.symbol".into(), HighlightStyle::default()),
373                ("tag".into(), HighlightStyle::default()),
374                ("text.literal".into(), HighlightStyle::default()),
375                ("title".into(), HighlightStyle::default()),
376                ("type".into(), teal.into()),
377                ("variable".into(), HighlightStyle::default()),
378                ("variable.special".into(), red.into()),
379                ("variant".into(), HighlightStyle::default()),
380                ("diff.plus".into(), green.into()),
381                ("diff.minus".into(), red.into()),
382            ])),
383        },
384    }
385}