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