1use std::fmt::{self, Debug};
2
3use gpui::{Hsla, Rgba};
4use theme::{
5 Appearance, PlayerColor, PlayerColors, StatusColorsRefinement, SystemColors,
6 ThemeColorsRefinement, UserHighlightStyle, UserSyntaxTheme, UserTheme, UserThemeFamily,
7 UserThemeStylesRefinement,
8};
9
10struct RawSyntaxPrinter<'a>(&'a str);
11
12impl<'a> Debug for RawSyntaxPrinter<'a> {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 write!(f, "{}", self.0)
15 }
16}
17
18struct HslaPrinter(Hsla);
19
20impl Debug for HslaPrinter {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 write!(f, "{:?}", IntoPrinter(&Rgba::from(self.0)))
23 }
24}
25
26struct IntoPrinter<'a, D: Debug>(&'a D);
27
28impl<'a, D: Debug> Debug for IntoPrinter<'a, D> {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 write!(f, "{:?}.into()", self.0)
31 }
32}
33
34pub struct OptionPrinter<'a, T>(&'a Option<T>);
35
36impl<'a, T: Debug> Debug for OptionPrinter<'a, T> {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 match self.0 {
39 Some(value) => write!(f, "Some({:?})", value),
40 None => write!(f, "None"),
41 }
42 }
43}
44
45pub struct VecPrinter<'a, T>(&'a Vec<T>);
46
47impl<'a, T: Debug> Debug for VecPrinter<'a, T> {
48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 write!(f, "vec!{:?}", &self.0)
50 }
51}
52
53pub struct UserThemeFamilyPrinter(UserThemeFamily);
54
55impl UserThemeFamilyPrinter {
56 pub fn new(theme_family: UserThemeFamily) -> Self {
57 Self(theme_family)
58 }
59}
60
61impl Debug for UserThemeFamilyPrinter {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 f.debug_struct("UserThemeFamily")
64 .field("name", &IntoPrinter(&self.0.name))
65 .field("author", &IntoPrinter(&self.0.author))
66 .field(
67 "themes",
68 &VecPrinter(
69 &self
70 .0
71 .themes
72 .iter()
73 .map(|theme| UserThemePrinter(theme))
74 .collect(),
75 ),
76 )
77 .finish()
78 }
79}
80
81pub struct UserThemePrinter<'a>(&'a UserTheme);
82
83impl<'a> Debug for UserThemePrinter<'a> {
84 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
85 f.debug_struct("UserTheme")
86 .field("name", &IntoPrinter(&self.0.name))
87 .field("appearance", &AppearancePrinter(self.0.appearance))
88 .field("styles", &UserThemeStylesRefinementPrinter(&self.0.styles))
89 .finish()
90 }
91}
92
93pub struct AppearancePrinter(Appearance);
94
95impl Debug for AppearancePrinter {
96 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
97 write!(f, "Appearance::{:?}", self.0)
98 }
99}
100
101pub struct UserThemeStylesRefinementPrinter<'a>(&'a UserThemeStylesRefinement);
102
103impl<'a> Debug for UserThemeStylesRefinementPrinter<'a> {
104 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
105 f.debug_struct("UserThemeStylesRefinement")
106 .field("colors", &ThemeColorsRefinementPrinter(&self.0.colors))
107 .field("status", &StatusColorsRefinementPrinter(&self.0.status))
108 .field(
109 "syntax",
110 &OptionPrinter(
111 &self
112 .0
113 .syntax
114 .as_ref()
115 .map(|syntax| UserSyntaxThemePrinter(syntax)),
116 ),
117 )
118 .finish()
119 }
120}
121
122pub struct SystemColorsPrinter<'a>(&'a SystemColors);
123
124impl<'a> Debug for SystemColorsPrinter<'a> {
125 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
126 f.debug_struct("SystemColors")
127 .field("transparent", &HslaPrinter(self.0.transparent))
128 .field(
129 "mac_os_traffic_light_red",
130 &HslaPrinter(self.0.mac_os_traffic_light_red),
131 )
132 .field(
133 "mac_os_traffic_light_yellow",
134 &HslaPrinter(self.0.mac_os_traffic_light_yellow),
135 )
136 .field(
137 "mac_os_traffic_light_green",
138 &HslaPrinter(self.0.mac_os_traffic_light_green),
139 )
140 .finish()
141 }
142}
143
144pub struct ThemeColorsRefinementPrinter<'a>(&'a ThemeColorsRefinement);
145
146impl<'a> Debug for ThemeColorsRefinementPrinter<'a> {
147 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
148 let theme_colors = vec![
149 ("border", self.0.border),
150 ("border_variant", self.0.border_variant),
151 ("border_focused", self.0.border_focused),
152 ("border_selected", self.0.border_selected),
153 ("border_transparent", self.0.border_transparent),
154 ("border_disabled", self.0.border_disabled),
155 (
156 "elevated_surface_background",
157 self.0.elevated_surface_background,
158 ),
159 ("surface_background", self.0.surface_background),
160 ("background", self.0.background),
161 ("element_background", self.0.element_background),
162 ("element_hover", self.0.element_hover),
163 ("element_active", self.0.element_active),
164 ("element_selected", self.0.element_selected),
165 ("element_disabled", self.0.element_disabled),
166 ("drop_target_background", self.0.drop_target_background),
167 ("ghost_element_background", self.0.ghost_element_background),
168 ("ghost_element_hover", self.0.ghost_element_hover),
169 ("ghost_element_active", self.0.ghost_element_active),
170 ("ghost_element_selected", self.0.ghost_element_selected),
171 ("ghost_element_disabled", self.0.ghost_element_disabled),
172 ("text", self.0.text),
173 ("text_muted", self.0.text_muted),
174 ("text_placeholder", self.0.text_placeholder),
175 ("text_disabled", self.0.text_disabled),
176 ("text_accent", self.0.text_accent),
177 ("icon", self.0.icon),
178 ("icon_muted", self.0.icon_muted),
179 ("icon_disabled", self.0.icon_disabled),
180 ("icon_placeholder", self.0.icon_placeholder),
181 ("icon_accent", self.0.icon_accent),
182 ("status_bar_background", self.0.status_bar_background),
183 ("title_bar_background", self.0.title_bar_background),
184 ("toolbar_background", self.0.toolbar_background),
185 ("tab_bar_background", self.0.tab_bar_background),
186 ("tab_inactive_background", self.0.tab_inactive_background),
187 ("tab_active_background", self.0.tab_active_background),
188 ("editor_background", self.0.editor_background),
189 ("editor_gutter_background", self.0.editor_gutter_background),
190 (
191 "editor_subheader_background",
192 self.0.editor_subheader_background,
193 ),
194 (
195 "editor_active_line_background",
196 self.0.editor_active_line_background,
197 ),
198 (
199 "editor_highlighted_line_background",
200 self.0.editor_highlighted_line_background,
201 ),
202 ("editor_line_number", self.0.editor_line_number),
203 (
204 "editor_active_line_number",
205 self.0.editor_active_line_number,
206 ),
207 ("editor_invisible", self.0.editor_invisible),
208 ("editor_wrap_guide", self.0.editor_wrap_guide),
209 ("editor_active_wrap_guide", self.0.editor_active_wrap_guide),
210 (
211 "editor_document_highlight_read_background",
212 self.0.editor_document_highlight_read_background,
213 ),
214 (
215 "editor_document_highlight_write_background",
216 self.0.editor_document_highlight_write_background,
217 ),
218 ("terminal_background", self.0.terminal_background),
219 (
220 "terminal_ansi_bright_black",
221 self.0.terminal_ansi_bright_black,
222 ),
223 ("terminal_ansi_bright_red", self.0.terminal_ansi_bright_red),
224 (
225 "terminal_ansi_bright_green",
226 self.0.terminal_ansi_bright_green,
227 ),
228 (
229 "terminal_ansi_bright_yellow",
230 self.0.terminal_ansi_bright_yellow,
231 ),
232 (
233 "terminal_ansi_bright_blue",
234 self.0.terminal_ansi_bright_blue,
235 ),
236 (
237 "terminal_ansi_bright_magenta",
238 self.0.terminal_ansi_bright_magenta,
239 ),
240 (
241 "terminal_ansi_bright_cyan",
242 self.0.terminal_ansi_bright_cyan,
243 ),
244 (
245 "terminal_ansi_bright_white",
246 self.0.terminal_ansi_bright_white,
247 ),
248 ("terminal_ansi_black", self.0.terminal_ansi_black),
249 ("terminal_ansi_red", self.0.terminal_ansi_red),
250 ("terminal_ansi_green", self.0.terminal_ansi_green),
251 ("terminal_ansi_yellow", self.0.terminal_ansi_yellow),
252 ("terminal_ansi_blue", self.0.terminal_ansi_blue),
253 ("terminal_ansi_magenta", self.0.terminal_ansi_magenta),
254 ("terminal_ansi_cyan", self.0.terminal_ansi_cyan),
255 ("terminal_ansi_white", self.0.terminal_ansi_white),
256 ];
257
258 f.write_str("ThemeColorsRefinement {")?;
259
260 for (color_name, color) in theme_colors {
261 if let Some(color) = color {
262 f.write_str(color_name)?;
263 f.write_str(": ")?;
264 f.write_str("Some(")?;
265 HslaPrinter(color).fmt(f)?;
266 f.write_str(")")?;
267 f.write_str(",")?;
268 }
269 }
270
271 f.write_str("..Default::default()")?;
272 f.write_str("}")
273 }
274}
275
276pub struct StatusColorsRefinementPrinter<'a>(&'a StatusColorsRefinement);
277
278impl<'a> Debug for StatusColorsRefinementPrinter<'a> {
279 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
280 let status_colors = vec![
281 ("conflict", self.0.conflict),
282 ("created", self.0.created),
283 ("deleted", self.0.deleted),
284 ("error", self.0.error),
285 ("hidden", self.0.hidden),
286 ("hint", self.0.hint),
287 ("ignored", self.0.ignored),
288 ("info", self.0.info),
289 ("modified", self.0.modified),
290 ("predictive", self.0.predictive),
291 ("renamed", self.0.renamed),
292 ("success", self.0.success),
293 ("unreachable", self.0.unreachable),
294 ("warning", self.0.warning),
295 ];
296
297 f.write_str("StatusColorsRefinement {")?;
298
299 for (color_name, color) in status_colors {
300 if let Some(color) = color {
301 f.write_str(color_name)?;
302 f.write_str(": ")?;
303 f.write_str("Some(")?;
304 HslaPrinter(color).fmt(f)?;
305 f.write_str(")")?;
306 f.write_str(",")?;
307 }
308 }
309
310 f.write_str("..Default::default()")?;
311 f.write_str("}")
312 }
313}
314
315pub struct PlayerColorsPrinter<'a>(&'a PlayerColors);
316
317impl<'a> Debug for PlayerColorsPrinter<'a> {
318 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
319 f.debug_tuple("PlayerColors")
320 .field(&VecPrinter(
321 &self
322 .0
323 .0
324 .iter()
325 .map(|player_color| PlayerColorPrinter(player_color))
326 .collect(),
327 ))
328 .finish()
329 }
330}
331
332pub struct PlayerColorPrinter<'a>(&'a PlayerColor);
333
334impl<'a> Debug for PlayerColorPrinter<'a> {
335 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
336 f.debug_struct("PlayerColor")
337 .field("cursor", &HslaPrinter(self.0.cursor))
338 .field("background", &HslaPrinter(self.0.background))
339 .field("selection", &HslaPrinter(self.0.selection))
340 .finish()
341 }
342}
343
344pub struct UserSyntaxThemePrinter<'a>(&'a UserSyntaxTheme);
345
346impl<'a> Debug for UserSyntaxThemePrinter<'a> {
347 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
348 f.debug_struct("UserSyntaxTheme")
349 .field(
350 "highlights",
351 &VecPrinter(
352 &self
353 .0
354 .highlights
355 .iter()
356 .map(|(token, highlight)| {
357 (IntoPrinter(token), UserHighlightStylePrinter(&highlight))
358 })
359 .collect(),
360 ),
361 )
362 .finish()
363 }
364}
365
366pub struct UserHighlightStylePrinter<'a>(&'a UserHighlightStyle);
367
368impl<'a> Debug for UserHighlightStylePrinter<'a> {
369 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
370 f.write_str("UserHighlightStyle {")?;
371
372 if let Some(color) = self.0.color {
373 f.write_str("color")?;
374 f.write_str(": ")?;
375 f.write_str("Some(")?;
376 HslaPrinter(color).fmt(f)?;
377 f.write_str(")")?;
378 f.write_str(",")?;
379 }
380
381 if let Some(font_style) = self.0.font_style {
382 f.write_str("font_style")?;
383 f.write_str(": ")?;
384 f.write_str("Some(")?;
385 write!(f, "UserFontStyle::{:?}", font_style)?;
386 f.write_str(")")?;
387 f.write_str(",")?;
388 }
389
390 if let Some(font_weight) = self.0.font_weight.as_ref() {
391 f.write_str("font_weight")?;
392 f.write_str(": ")?;
393 f.write_str("Some(")?;
394 write!(f, "UserFontWeight({:?})", font_weight.0)?;
395 f.write_str(")")?;
396 f.write_str(",")?;
397 }
398
399 f.write_str("..Default::default()")?;
400 f.write_str("}")
401 }
402}