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