fallback_themes.rs

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