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