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                minimap_thumb_background: hsla(225.0 / 360., 11.8 / 100., 26.7 / 100., 0.7),
203                minimap_thumb_hover_background: hsla(225.0 / 360., 11.8 / 100., 26.7 / 100., 0.7),
204                minimap_thumb_active_background: hsla(225.0 / 360., 11.8 / 100., 26.7 / 100., 0.7),
205                minimap_thumb_border: hsla(228. / 360., 8. / 100., 25. / 100., 1.),
206                editor_foreground: hsla(218. / 360., 14. / 100., 71. / 100., 1.),
207                link_text_hover: blue,
208                version_control_added: ADDED_COLOR,
209                version_control_deleted: REMOVED_COLOR,
210                version_control_modified: MODIFIED_COLOR,
211                version_control_renamed: MODIFIED_COLOR,
212                version_control_conflict: crate::orange().light().step_12(),
213                version_control_ignored: crate::gray().light().step_12(),
214                version_control_conflict_marker_ours: crate::green().light().step_12().alpha(0.5),
215                version_control_conflict_marker_theirs: crate::blue().light().step_12().alpha(0.5),
216            },
217            status: StatusColors {
218                conflict: yellow,
219                conflict_background: yellow,
220                conflict_border: yellow,
221                created: green,
222                created_background: green,
223                created_border: green,
224                deleted: red,
225                deleted_background: red,
226                deleted_border: red,
227                error: red,
228                error_background: red,
229                error_border: red,
230                hidden: gray,
231                hidden_background: gray,
232                hidden_border: gray,
233                hint: blue,
234                hint_background: blue,
235                hint_border: blue,
236                ignored: gray,
237                ignored_background: gray,
238                ignored_border: gray,
239                info: blue,
240                info_background: blue,
241                info_border: blue,
242                modified: yellow,
243                modified_background: yellow,
244                modified_border: yellow,
245                predictive: gray,
246                predictive_background: gray,
247                predictive_border: gray,
248                renamed: blue,
249                renamed_background: blue,
250                renamed_border: blue,
251                success: green,
252                success_background: green,
253                success_border: green,
254                unreachable: gray,
255                unreachable_background: gray,
256                unreachable_border: gray,
257                warning: yellow,
258                warning_background: yellow,
259                warning_border: yellow,
260            },
261            player: PlayerColors::dark(),
262            syntax: Arc::new(SyntaxTheme {
263                highlights: vec![
264                    ("attribute".into(), purple.into()),
265                    ("boolean".into(), orange.into()),
266                    ("comment".into(), gray.into()),
267                    ("comment.doc".into(), gray.into()),
268                    ("constant".into(), yellow.into()),
269                    ("constructor".into(), blue.into()),
270                    ("embedded".into(), HighlightStyle::default()),
271                    (
272                        "emphasis".into(),
273                        HighlightStyle {
274                            font_style: Some(FontStyle::Italic),
275                            ..HighlightStyle::default()
276                        },
277                    ),
278                    (
279                        "emphasis.strong".into(),
280                        HighlightStyle {
281                            font_weight: Some(FontWeight::BOLD),
282                            ..HighlightStyle::default()
283                        },
284                    ),
285                    ("enum".into(), HighlightStyle::default()),
286                    ("function".into(), blue.into()),
287                    ("function.method".into(), blue.into()),
288                    ("function.definition".into(), blue.into()),
289                    ("hint".into(), blue.into()),
290                    ("keyword".into(), purple.into()),
291                    ("label".into(), HighlightStyle::default()),
292                    ("link_text".into(), blue.into()),
293                    (
294                        "link_uri".into(),
295                        HighlightStyle {
296                            color: Some(teal),
297                            font_style: Some(FontStyle::Italic),
298                            ..HighlightStyle::default()
299                        },
300                    ),
301                    ("number".into(), orange.into()),
302                    ("operator".into(), HighlightStyle::default()),
303                    ("predictive".into(), HighlightStyle::default()),
304                    ("preproc".into(), HighlightStyle::default()),
305                    ("primary".into(), HighlightStyle::default()),
306                    ("property".into(), red.into()),
307                    ("punctuation".into(), HighlightStyle::default()),
308                    ("punctuation.bracket".into(), HighlightStyle::default()),
309                    ("punctuation.delimiter".into(), HighlightStyle::default()),
310                    ("punctuation.list_marker".into(), HighlightStyle::default()),
311                    ("punctuation.special".into(), HighlightStyle::default()),
312                    ("string".into(), green.into()),
313                    ("string.escape".into(), HighlightStyle::default()),
314                    ("string.regex".into(), red.into()),
315                    ("string.special".into(), HighlightStyle::default()),
316                    ("string.special.symbol".into(), HighlightStyle::default()),
317                    ("tag".into(), HighlightStyle::default()),
318                    ("text.literal".into(), HighlightStyle::default()),
319                    ("title".into(), HighlightStyle::default()),
320                    ("type".into(), teal.into()),
321                    ("variable".into(), HighlightStyle::default()),
322                    ("variable.special".into(), red.into()),
323                    ("variant".into(), HighlightStyle::default()),
324                ],
325            }),
326        },
327    }
328}