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