1#![allow(missing_docs)]
2
3use anyhow::Result;
4use gpui::{FontStyle, FontWeight, HighlightStyle, Hsla, WindowBackgroundAppearance};
5use indexmap::IndexMap;
6use palette::FromColor;
7use schemars::gen::SchemaGenerator;
8use schemars::schema::{Schema, SchemaObject};
9use schemars::JsonSchema;
10use serde::{Deserialize, Deserializer, Serialize};
11use serde_json::Value;
12use serde_repr::{Deserialize_repr, Serialize_repr};
13
14use crate::{StatusColorsRefinement, ThemeColorsRefinement};
15
16pub(crate) fn try_parse_color(color: &str) -> Result<Hsla> {
17 let rgba = gpui::Rgba::try_from(color)?;
18 let rgba = palette::rgb::Srgba::from_components((rgba.r, rgba.g, rgba.b, rgba.a));
19 let hsla = palette::Hsla::from_color(rgba);
20
21 let hsla = gpui::hsla(
22 hsla.hue.into_positive_degrees() / 360.,
23 hsla.saturation,
24 hsla.lightness,
25 hsla.alpha,
26 );
27
28 Ok(hsla)
29}
30
31#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
32#[serde(rename_all = "snake_case")]
33pub enum AppearanceContent {
34 Light,
35 Dark,
36}
37
38/// The background appearance of the window.
39#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
40#[serde(rename_all = "snake_case")]
41pub enum WindowBackgroundContent {
42 Opaque,
43 Transparent,
44 Blurred,
45}
46
47impl From<WindowBackgroundContent> for WindowBackgroundAppearance {
48 fn from(value: WindowBackgroundContent) -> Self {
49 match value {
50 WindowBackgroundContent::Opaque => WindowBackgroundAppearance::Opaque,
51 WindowBackgroundContent::Transparent => WindowBackgroundAppearance::Transparent,
52 WindowBackgroundContent::Blurred => WindowBackgroundAppearance::Blurred,
53 }
54 }
55}
56
57/// The content of a serialized theme family.
58#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
59pub struct ThemeFamilyContent {
60 pub name: String,
61 pub author: String,
62 pub themes: Vec<ThemeContent>,
63}
64
65/// The content of a serialized theme.
66#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
67pub struct ThemeContent {
68 pub name: String,
69 pub appearance: AppearanceContent,
70 pub style: ThemeStyleContent,
71}
72
73/// The content of a serialized theme.
74#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
75#[serde(default)]
76pub struct ThemeStyleContent {
77 #[serde(default, rename = "background.appearance")]
78 pub window_background_appearance: Option<WindowBackgroundContent>,
79
80 #[serde(default)]
81 pub accents: Vec<AccentContent>,
82
83 #[serde(flatten, default)]
84 pub colors: ThemeColorsContent,
85
86 #[serde(flatten, default)]
87 pub status: StatusColorsContent,
88
89 #[serde(default)]
90 pub players: Vec<PlayerColorContent>,
91
92 /// The styles for syntax nodes.
93 #[serde(default)]
94 pub syntax: IndexMap<String, HighlightStyleContent>,
95}
96
97impl ThemeStyleContent {
98 /// Returns a [`ThemeColorsRefinement`] based on the colors in the [`ThemeContent`].
99 #[inline(always)]
100 pub fn theme_colors_refinement(&self) -> ThemeColorsRefinement {
101 self.colors.theme_colors_refinement()
102 }
103
104 /// Returns a [`StatusColorsRefinement`] based on the colors in the [`ThemeContent`].
105 #[inline(always)]
106 pub fn status_colors_refinement(&self) -> StatusColorsRefinement {
107 self.status.status_colors_refinement()
108 }
109
110 /// Returns the syntax style overrides in the [`ThemeContent`].
111 pub fn syntax_overrides(&self) -> Vec<(String, HighlightStyle)> {
112 self.syntax
113 .iter()
114 .map(|(key, style)| {
115 (
116 key.clone(),
117 HighlightStyle {
118 color: style
119 .color
120 .as_ref()
121 .and_then(|color| try_parse_color(color).ok()),
122 background_color: style
123 .background_color
124 .as_ref()
125 .and_then(|color| try_parse_color(color).ok()),
126 font_style: style.font_style.map(FontStyle::from),
127 font_weight: style.font_weight.map(FontWeight::from),
128 ..Default::default()
129 },
130 )
131 })
132 .collect()
133 }
134}
135
136#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
137#[serde(default)]
138pub struct ThemeColorsContent {
139 /// Border color. Used for most borders, is usually a high contrast color.
140 #[serde(rename = "border")]
141 pub border: Option<String>,
142
143 /// Border color. Used for deemphasized borders, like a visual divider between two sections
144 #[serde(rename = "border.variant")]
145 pub border_variant: Option<String>,
146
147 /// Border color. Used for focused elements, like keyboard focused list item.
148 #[serde(rename = "border.focused")]
149 pub border_focused: Option<String>,
150
151 /// Border color. Used for selected elements, like an active search filter or selected checkbox.
152 #[serde(rename = "border.selected")]
153 pub border_selected: Option<String>,
154
155 /// Border color. Used for transparent borders. Used for placeholder borders when an element gains a border on state change.
156 #[serde(rename = "border.transparent")]
157 pub border_transparent: Option<String>,
158
159 /// Border color. Used for disabled elements, like a disabled input or button.
160 #[serde(rename = "border.disabled")]
161 pub border_disabled: Option<String>,
162
163 /// Background color. Used for elevated surfaces, like a context menu, popup, or dialog.
164 #[serde(rename = "elevated_surface.background")]
165 pub elevated_surface_background: Option<String>,
166
167 /// Background Color. Used for grounded surfaces like a panel or tab.
168 #[serde(rename = "surface.background")]
169 pub surface_background: Option<String>,
170
171 /// Background Color. Used for the app background and blank panels or windows.
172 #[serde(rename = "background")]
173 pub background: Option<String>,
174
175 /// Background Color. Used for the background of an element that should have a different background than the surface it's on.
176 ///
177 /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons...
178 ///
179 /// For an element that should have the same background as the surface it's on, use `ghost_element_background`.
180 #[serde(rename = "element.background")]
181 pub element_background: Option<String>,
182
183 /// Background Color. Used for the hover state of an element that should have a different background than the surface it's on.
184 ///
185 /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen.
186 #[serde(rename = "element.hover")]
187 pub element_hover: Option<String>,
188
189 /// Background Color. Used for the active state of an element that should have a different background than the surface it's on.
190 ///
191 /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd.
192 #[serde(rename = "element.active")]
193 pub element_active: Option<String>,
194
195 /// Background Color. Used for the selected state of an element that should have a different background than the surface it's on.
196 ///
197 /// Selected states are triggered by the element being selected (or "activated") by the user.
198 ///
199 /// This could include a selected checkbox, a toggleable button that is toggled on, etc.
200 #[serde(rename = "element.selected")]
201 pub element_selected: Option<String>,
202
203 /// Background Color. Used for the disabled state of an element that should have a different background than the surface it's on.
204 ///
205 /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input.
206 #[serde(rename = "element.disabled")]
207 pub element_disabled: Option<String>,
208
209 /// Background Color. Used for the area that shows where a dragged element will be dropped.
210 #[serde(rename = "drop_target.background")]
211 pub drop_target_background: Option<String>,
212
213 /// Used for the background of a ghost element that should have the same background as the surface it's on.
214 ///
215 /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons...
216 ///
217 /// For an element that should have a different background than the surface it's on, use `element_background`.
218 #[serde(rename = "ghost_element.background")]
219 pub ghost_element_background: Option<String>,
220
221 /// Background Color. Used for the hover state of a ghost element that should have the same background as the surface it's on.
222 ///
223 /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen.
224 #[serde(rename = "ghost_element.hover")]
225 pub ghost_element_hover: Option<String>,
226
227 /// Background Color. Used for the active state of a ghost element that should have the same background as the surface it's on.
228 ///
229 /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd.
230 #[serde(rename = "ghost_element.active")]
231 pub ghost_element_active: Option<String>,
232
233 /// Background Color. Used for the selected state of a ghost element that should have the same background as the surface it's on.
234 ///
235 /// Selected states are triggered by the element being selected (or "activated") by the user.
236 ///
237 /// This could include a selected checkbox, a toggleable button that is toggled on, etc.
238 #[serde(rename = "ghost_element.selected")]
239 pub ghost_element_selected: Option<String>,
240
241 /// Background Color. Used for the disabled state of a ghost element that should have the same background as the surface it's on.
242 ///
243 /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input.
244 #[serde(rename = "ghost_element.disabled")]
245 pub ghost_element_disabled: Option<String>,
246
247 /// Text Color. Default text color used for most text.
248 #[serde(rename = "text")]
249 pub text: Option<String>,
250
251 /// Text Color. Color of muted or deemphasized text. It is a subdued version of the standard text color.
252 #[serde(rename = "text.muted")]
253 pub text_muted: Option<String>,
254
255 /// Text Color. Color of the placeholder text typically shown in input fields to guide the user to enter valid data.
256 #[serde(rename = "text.placeholder")]
257 pub text_placeholder: Option<String>,
258
259 /// Text Color. Color used for text denoting disabled elements. Typically, the color is faded or grayed out to emphasize the disabled state.
260 #[serde(rename = "text.disabled")]
261 pub text_disabled: Option<String>,
262
263 /// Text Color. Color used for emphasis or highlighting certain text, like an active filter or a matched character in a search.
264 #[serde(rename = "text.accent")]
265 pub text_accent: Option<String>,
266
267 /// Fill Color. Used for the default fill color of an icon.
268 #[serde(rename = "icon")]
269 pub icon: Option<String>,
270
271 /// Fill Color. Used for the muted or deemphasized fill color of an icon.
272 ///
273 /// This might be used to show an icon in an inactive pane, or to deemphasize a series of icons to give them less visual weight.
274 #[serde(rename = "icon.muted")]
275 pub icon_muted: Option<String>,
276
277 /// Fill Color. Used for the disabled fill color of an icon.
278 ///
279 /// Disabled states are shown when a user cannot interact with an element, like a icon button.
280 #[serde(rename = "icon.disabled")]
281 pub icon_disabled: Option<String>,
282
283 /// Fill Color. Used for the placeholder fill color of an icon.
284 ///
285 /// This might be used to show an icon in an input that disappears when the user enters text.
286 #[serde(rename = "icon.placeholder")]
287 pub icon_placeholder: Option<String>,
288
289 /// Fill Color. Used for the accent fill color of an icon.
290 ///
291 /// This might be used to show when a toggleable icon button is selected.
292 #[serde(rename = "icon.accent")]
293 pub icon_accent: Option<String>,
294
295 #[serde(rename = "status_bar.background")]
296 pub status_bar_background: Option<String>,
297
298 #[serde(rename = "title_bar.background")]
299 pub title_bar_background: Option<String>,
300
301 #[serde(rename = "title_bar.inactive_background")]
302 pub title_bar_inactive_background: Option<String>,
303
304 #[serde(rename = "toolbar.background")]
305 pub toolbar_background: Option<String>,
306
307 #[serde(rename = "tab_bar.background")]
308 pub tab_bar_background: Option<String>,
309
310 #[serde(rename = "tab.inactive_background")]
311 pub tab_inactive_background: Option<String>,
312
313 #[serde(rename = "tab.active_background")]
314 pub tab_active_background: Option<String>,
315
316 #[serde(rename = "search.match_background")]
317 pub search_match_background: Option<String>,
318
319 #[serde(rename = "panel.background")]
320 pub panel_background: Option<String>,
321
322 #[serde(rename = "panel.focused_border")]
323 pub panel_focused_border: Option<String>,
324
325 #[serde(rename = "panel.indent_guide")]
326 pub panel_indent_guide: Option<String>,
327
328 #[serde(rename = "panel.indent_guide_hover")]
329 pub panel_indent_guide_hover: Option<String>,
330
331 #[serde(rename = "panel.indent_guide_active")]
332 pub panel_indent_guide_active: Option<String>,
333
334 #[serde(rename = "pane.focused_border")]
335 pub pane_focused_border: Option<String>,
336
337 #[serde(rename = "pane_group.border")]
338 pub pane_group_border: Option<String>,
339
340 /// The deprecated version of `scrollbar.thumb.background`.
341 ///
342 /// Don't use this field.
343 #[serde(rename = "scrollbar_thumb.background", skip_serializing)]
344 #[schemars(skip)]
345 pub deprecated_scrollbar_thumb_background: Option<String>,
346
347 /// The color of the scrollbar thumb.
348 #[serde(rename = "scrollbar.thumb.background")]
349 pub scrollbar_thumb_background: Option<String>,
350
351 /// The color of the scrollbar thumb when hovered over.
352 #[serde(rename = "scrollbar.thumb.hover_background")]
353 pub scrollbar_thumb_hover_background: Option<String>,
354
355 /// The border color of the scrollbar thumb.
356 #[serde(rename = "scrollbar.thumb.border")]
357 pub scrollbar_thumb_border: Option<String>,
358
359 /// The background color of the scrollbar track.
360 #[serde(rename = "scrollbar.track.background")]
361 pub scrollbar_track_background: Option<String>,
362
363 /// The border color of the scrollbar track.
364 #[serde(rename = "scrollbar.track.border")]
365 pub scrollbar_track_border: Option<String>,
366
367 #[serde(rename = "editor.foreground")]
368 pub editor_foreground: Option<String>,
369
370 #[serde(rename = "editor.background")]
371 pub editor_background: Option<String>,
372
373 #[serde(rename = "editor.gutter.background")]
374 pub editor_gutter_background: Option<String>,
375
376 #[serde(rename = "editor.subheader.background")]
377 pub editor_subheader_background: Option<String>,
378
379 #[serde(rename = "editor.active_line.background")]
380 pub editor_active_line_background: Option<String>,
381
382 #[serde(rename = "editor.highlighted_line.background")]
383 pub editor_highlighted_line_background: Option<String>,
384
385 /// Text Color. Used for the text of the line number in the editor gutter.
386 #[serde(rename = "editor.line_number")]
387 pub editor_line_number: Option<String>,
388
389 /// Text Color. Used for the text of the line number in the editor gutter when the line is highlighted.
390 #[serde(rename = "editor.active_line_number")]
391 pub editor_active_line_number: Option<String>,
392
393 /// Text Color. Used for the text of the line number in the editor gutter when the line is hovered over.
394 #[serde(rename = "editor.hover_line_number")]
395 pub editor_hover_line_number: Option<String>,
396
397 /// Text Color. Used to mark invisible characters in the editor.
398 ///
399 /// Example: spaces, tabs, carriage returns, etc.
400 #[serde(rename = "editor.invisible")]
401 pub editor_invisible: Option<String>,
402
403 #[serde(rename = "editor.wrap_guide")]
404 pub editor_wrap_guide: Option<String>,
405
406 #[serde(rename = "editor.active_wrap_guide")]
407 pub editor_active_wrap_guide: Option<String>,
408
409 #[serde(rename = "editor.indent_guide")]
410 pub editor_indent_guide: Option<String>,
411
412 #[serde(rename = "editor.indent_guide_active")]
413 pub editor_indent_guide_active: Option<String>,
414
415 /// Read-access of a symbol, like reading a variable.
416 ///
417 /// A document highlight is a range inside a text document which deserves
418 /// special attention. Usually a document highlight is visualized by changing
419 /// the background color of its range.
420 #[serde(rename = "editor.document_highlight.read_background")]
421 pub editor_document_highlight_read_background: Option<String>,
422
423 /// Read-access of a symbol, like reading a variable.
424 ///
425 /// A document highlight is a range inside a text document which deserves
426 /// special attention. Usually a document highlight is visualized by changing
427 /// the background color of its range.
428 #[serde(rename = "editor.document_highlight.write_background")]
429 pub editor_document_highlight_write_background: Option<String>,
430
431 /// Highlighted brackets background color.
432 ///
433 /// Matching brackets in the cursor scope are highlighted with this background color.
434 #[serde(rename = "editor.document_highlight.bracket_background")]
435 pub editor_document_highlight_bracket_background: Option<String>,
436
437 /// Terminal background color.
438 #[serde(rename = "terminal.background")]
439 pub terminal_background: Option<String>,
440
441 /// Terminal foreground color.
442 #[serde(rename = "terminal.foreground")]
443 pub terminal_foreground: Option<String>,
444
445 /// Terminal ANSI background color.
446 #[serde(rename = "terminal.ansi.background")]
447 pub terminal_ansi_background: Option<String>,
448
449 /// Bright terminal foreground color.
450 #[serde(rename = "terminal.bright_foreground")]
451 pub terminal_bright_foreground: Option<String>,
452
453 /// Dim terminal foreground color.
454 #[serde(rename = "terminal.dim_foreground")]
455 pub terminal_dim_foreground: Option<String>,
456
457 /// Black ANSI terminal color.
458 #[serde(rename = "terminal.ansi.black")]
459 pub terminal_ansi_black: Option<String>,
460
461 /// Bright black ANSI terminal color.
462 #[serde(rename = "terminal.ansi.bright_black")]
463 pub terminal_ansi_bright_black: Option<String>,
464
465 /// Dim black ANSI terminal color.
466 #[serde(rename = "terminal.ansi.dim_black")]
467 pub terminal_ansi_dim_black: Option<String>,
468
469 /// Red ANSI terminal color.
470 #[serde(rename = "terminal.ansi.red")]
471 pub terminal_ansi_red: Option<String>,
472
473 /// Bright red ANSI terminal color.
474 #[serde(rename = "terminal.ansi.bright_red")]
475 pub terminal_ansi_bright_red: Option<String>,
476
477 /// Dim red ANSI terminal color.
478 #[serde(rename = "terminal.ansi.dim_red")]
479 pub terminal_ansi_dim_red: Option<String>,
480
481 /// Green ANSI terminal color.
482 #[serde(rename = "terminal.ansi.green")]
483 pub terminal_ansi_green: Option<String>,
484
485 /// Bright green ANSI terminal color.
486 #[serde(rename = "terminal.ansi.bright_green")]
487 pub terminal_ansi_bright_green: Option<String>,
488
489 /// Dim green ANSI terminal color.
490 #[serde(rename = "terminal.ansi.dim_green")]
491 pub terminal_ansi_dim_green: Option<String>,
492
493 /// Yellow ANSI terminal color.
494 #[serde(rename = "terminal.ansi.yellow")]
495 pub terminal_ansi_yellow: Option<String>,
496
497 /// Bright yellow ANSI terminal color.
498 #[serde(rename = "terminal.ansi.bright_yellow")]
499 pub terminal_ansi_bright_yellow: Option<String>,
500
501 /// Dim yellow ANSI terminal color.
502 #[serde(rename = "terminal.ansi.dim_yellow")]
503 pub terminal_ansi_dim_yellow: Option<String>,
504
505 /// Blue ANSI terminal color.
506 #[serde(rename = "terminal.ansi.blue")]
507 pub terminal_ansi_blue: Option<String>,
508
509 /// Bright blue ANSI terminal color.
510 #[serde(rename = "terminal.ansi.bright_blue")]
511 pub terminal_ansi_bright_blue: Option<String>,
512
513 /// Dim blue ANSI terminal color.
514 #[serde(rename = "terminal.ansi.dim_blue")]
515 pub terminal_ansi_dim_blue: Option<String>,
516
517 /// Magenta ANSI terminal color.
518 #[serde(rename = "terminal.ansi.magenta")]
519 pub terminal_ansi_magenta: Option<String>,
520
521 /// Bright magenta ANSI terminal color.
522 #[serde(rename = "terminal.ansi.bright_magenta")]
523 pub terminal_ansi_bright_magenta: Option<String>,
524
525 /// Dim magenta ANSI terminal color.
526 #[serde(rename = "terminal.ansi.dim_magenta")]
527 pub terminal_ansi_dim_magenta: Option<String>,
528
529 /// Cyan ANSI terminal color.
530 #[serde(rename = "terminal.ansi.cyan")]
531 pub terminal_ansi_cyan: Option<String>,
532
533 /// Bright cyan ANSI terminal color.
534 #[serde(rename = "terminal.ansi.bright_cyan")]
535 pub terminal_ansi_bright_cyan: Option<String>,
536
537 /// Dim cyan ANSI terminal color.
538 #[serde(rename = "terminal.ansi.dim_cyan")]
539 pub terminal_ansi_dim_cyan: Option<String>,
540
541 /// White ANSI terminal color.
542 #[serde(rename = "terminal.ansi.white")]
543 pub terminal_ansi_white: Option<String>,
544
545 /// Bright white ANSI terminal color.
546 #[serde(rename = "terminal.ansi.bright_white")]
547 pub terminal_ansi_bright_white: Option<String>,
548
549 /// Dim white ANSI terminal color.
550 #[serde(rename = "terminal.ansi.dim_white")]
551 pub terminal_ansi_dim_white: Option<String>,
552
553 #[serde(rename = "link_text.hover")]
554 pub link_text_hover: Option<String>,
555}
556
557impl ThemeColorsContent {
558 /// Returns a [`ThemeColorsRefinement`] based on the colors in the [`ThemeColorsContent`].
559 pub fn theme_colors_refinement(&self) -> ThemeColorsRefinement {
560 let border = self
561 .border
562 .as_ref()
563 .and_then(|color| try_parse_color(color).ok());
564 let editor_document_highlight_read_background = self
565 .editor_document_highlight_read_background
566 .as_ref()
567 .and_then(|color| try_parse_color(color).ok());
568 ThemeColorsRefinement {
569 border,
570 border_variant: self
571 .border_variant
572 .as_ref()
573 .and_then(|color| try_parse_color(color).ok()),
574 border_focused: self
575 .border_focused
576 .as_ref()
577 .and_then(|color| try_parse_color(color).ok()),
578 border_selected: self
579 .border_selected
580 .as_ref()
581 .and_then(|color| try_parse_color(color).ok()),
582 border_transparent: self
583 .border_transparent
584 .as_ref()
585 .and_then(|color| try_parse_color(color).ok()),
586 border_disabled: self
587 .border_disabled
588 .as_ref()
589 .and_then(|color| try_parse_color(color).ok()),
590 elevated_surface_background: self
591 .elevated_surface_background
592 .as_ref()
593 .and_then(|color| try_parse_color(color).ok()),
594 surface_background: self
595 .surface_background
596 .as_ref()
597 .and_then(|color| try_parse_color(color).ok()),
598 background: self
599 .background
600 .as_ref()
601 .and_then(|color| try_parse_color(color).ok()),
602 element_background: self
603 .element_background
604 .as_ref()
605 .and_then(|color| try_parse_color(color).ok()),
606 element_hover: self
607 .element_hover
608 .as_ref()
609 .and_then(|color| try_parse_color(color).ok()),
610 element_active: self
611 .element_active
612 .as_ref()
613 .and_then(|color| try_parse_color(color).ok()),
614 element_selected: self
615 .element_selected
616 .as_ref()
617 .and_then(|color| try_parse_color(color).ok()),
618 element_disabled: self
619 .element_disabled
620 .as_ref()
621 .and_then(|color| try_parse_color(color).ok()),
622 drop_target_background: self
623 .drop_target_background
624 .as_ref()
625 .and_then(|color| try_parse_color(color).ok()),
626 ghost_element_background: self
627 .ghost_element_background
628 .as_ref()
629 .and_then(|color| try_parse_color(color).ok()),
630 ghost_element_hover: self
631 .ghost_element_hover
632 .as_ref()
633 .and_then(|color| try_parse_color(color).ok()),
634 ghost_element_active: self
635 .ghost_element_active
636 .as_ref()
637 .and_then(|color| try_parse_color(color).ok()),
638 ghost_element_selected: self
639 .ghost_element_selected
640 .as_ref()
641 .and_then(|color| try_parse_color(color).ok()),
642 ghost_element_disabled: self
643 .ghost_element_disabled
644 .as_ref()
645 .and_then(|color| try_parse_color(color).ok()),
646 text: self
647 .text
648 .as_ref()
649 .and_then(|color| try_parse_color(color).ok()),
650 text_muted: self
651 .text_muted
652 .as_ref()
653 .and_then(|color| try_parse_color(color).ok()),
654 text_placeholder: self
655 .text_placeholder
656 .as_ref()
657 .and_then(|color| try_parse_color(color).ok()),
658 text_disabled: self
659 .text_disabled
660 .as_ref()
661 .and_then(|color| try_parse_color(color).ok()),
662 text_accent: self
663 .text_accent
664 .as_ref()
665 .and_then(|color| try_parse_color(color).ok()),
666 icon: self
667 .icon
668 .as_ref()
669 .and_then(|color| try_parse_color(color).ok()),
670 icon_muted: self
671 .icon_muted
672 .as_ref()
673 .and_then(|color| try_parse_color(color).ok()),
674 icon_disabled: self
675 .icon_disabled
676 .as_ref()
677 .and_then(|color| try_parse_color(color).ok()),
678 icon_placeholder: self
679 .icon_placeholder
680 .as_ref()
681 .and_then(|color| try_parse_color(color).ok()),
682 icon_accent: self
683 .icon_accent
684 .as_ref()
685 .and_then(|color| try_parse_color(color).ok()),
686 status_bar_background: self
687 .status_bar_background
688 .as_ref()
689 .and_then(|color| try_parse_color(color).ok()),
690 title_bar_background: self
691 .title_bar_background
692 .as_ref()
693 .and_then(|color| try_parse_color(color).ok()),
694 title_bar_inactive_background: self
695 .title_bar_inactive_background
696 .as_ref()
697 .and_then(|color| try_parse_color(color).ok()),
698 toolbar_background: self
699 .toolbar_background
700 .as_ref()
701 .and_then(|color| try_parse_color(color).ok()),
702 tab_bar_background: self
703 .tab_bar_background
704 .as_ref()
705 .and_then(|color| try_parse_color(color).ok()),
706 tab_inactive_background: self
707 .tab_inactive_background
708 .as_ref()
709 .and_then(|color| try_parse_color(color).ok()),
710 tab_active_background: self
711 .tab_active_background
712 .as_ref()
713 .and_then(|color| try_parse_color(color).ok()),
714 search_match_background: self
715 .search_match_background
716 .as_ref()
717 .and_then(|color| try_parse_color(color).ok()),
718 panel_background: self
719 .panel_background
720 .as_ref()
721 .and_then(|color| try_parse_color(color).ok()),
722 panel_focused_border: self
723 .panel_focused_border
724 .as_ref()
725 .and_then(|color| try_parse_color(color).ok()),
726 panel_indent_guide: self
727 .panel_indent_guide
728 .as_ref()
729 .and_then(|color| try_parse_color(color).ok()),
730 panel_indent_guide_hover: self
731 .panel_indent_guide_hover
732 .as_ref()
733 .and_then(|color| try_parse_color(color).ok()),
734 panel_indent_guide_active: self
735 .panel_indent_guide_active
736 .as_ref()
737 .and_then(|color| try_parse_color(color).ok()),
738 pane_focused_border: self
739 .pane_focused_border
740 .as_ref()
741 .and_then(|color| try_parse_color(color).ok()),
742 pane_group_border: self
743 .pane_group_border
744 .as_ref()
745 .and_then(|color| try_parse_color(color).ok())
746 .or(border),
747 scrollbar_thumb_background: self
748 .scrollbar_thumb_background
749 .as_ref()
750 .and_then(|color| try_parse_color(color).ok())
751 .or_else(|| {
752 self.deprecated_scrollbar_thumb_background
753 .as_ref()
754 .and_then(|color| try_parse_color(color).ok())
755 }),
756 scrollbar_thumb_hover_background: self
757 .scrollbar_thumb_hover_background
758 .as_ref()
759 .and_then(|color| try_parse_color(color).ok()),
760 scrollbar_thumb_border: self
761 .scrollbar_thumb_border
762 .as_ref()
763 .and_then(|color| try_parse_color(color).ok()),
764 scrollbar_track_background: self
765 .scrollbar_track_background
766 .as_ref()
767 .and_then(|color| try_parse_color(color).ok()),
768 scrollbar_track_border: self
769 .scrollbar_track_border
770 .as_ref()
771 .and_then(|color| try_parse_color(color).ok()),
772 editor_foreground: self
773 .editor_foreground
774 .as_ref()
775 .and_then(|color| try_parse_color(color).ok()),
776 editor_background: self
777 .editor_background
778 .as_ref()
779 .and_then(|color| try_parse_color(color).ok()),
780 editor_gutter_background: self
781 .editor_gutter_background
782 .as_ref()
783 .and_then(|color| try_parse_color(color).ok()),
784 editor_subheader_background: self
785 .editor_subheader_background
786 .as_ref()
787 .and_then(|color| try_parse_color(color).ok()),
788 editor_active_line_background: self
789 .editor_active_line_background
790 .as_ref()
791 .and_then(|color| try_parse_color(color).ok()),
792 editor_highlighted_line_background: self
793 .editor_highlighted_line_background
794 .as_ref()
795 .and_then(|color| try_parse_color(color).ok()),
796 editor_line_number: self
797 .editor_line_number
798 .as_ref()
799 .and_then(|color| try_parse_color(color).ok()),
800 editor_hover_line_number: self
801 .editor_hover_line_number
802 .as_ref()
803 .and_then(|color| try_parse_color(color).ok()),
804 editor_active_line_number: self
805 .editor_active_line_number
806 .as_ref()
807 .and_then(|color| try_parse_color(color).ok()),
808 editor_invisible: self
809 .editor_invisible
810 .as_ref()
811 .and_then(|color| try_parse_color(color).ok()),
812 editor_wrap_guide: self
813 .editor_wrap_guide
814 .as_ref()
815 .and_then(|color| try_parse_color(color).ok()),
816 editor_active_wrap_guide: self
817 .editor_active_wrap_guide
818 .as_ref()
819 .and_then(|color| try_parse_color(color).ok()),
820 editor_indent_guide: self
821 .editor_indent_guide
822 .as_ref()
823 .and_then(|color| try_parse_color(color).ok()),
824 editor_indent_guide_active: self
825 .editor_indent_guide_active
826 .as_ref()
827 .and_then(|color| try_parse_color(color).ok()),
828 editor_document_highlight_read_background,
829 editor_document_highlight_write_background: self
830 .editor_document_highlight_write_background
831 .as_ref()
832 .and_then(|color| try_parse_color(color).ok()),
833 editor_document_highlight_bracket_background: self
834 .editor_document_highlight_bracket_background
835 .as_ref()
836 .and_then(|color| try_parse_color(color).ok())
837 // Fall back to `editor.document_highlight.read_background`, for backwards compatibility.
838 .or(editor_document_highlight_read_background),
839 terminal_background: self
840 .terminal_background
841 .as_ref()
842 .and_then(|color| try_parse_color(color).ok()),
843 terminal_ansi_background: self
844 .terminal_ansi_background
845 .as_ref()
846 .and_then(|color| try_parse_color(color).ok()),
847 terminal_foreground: self
848 .terminal_foreground
849 .as_ref()
850 .and_then(|color| try_parse_color(color).ok()),
851 terminal_bright_foreground: self
852 .terminal_bright_foreground
853 .as_ref()
854 .and_then(|color| try_parse_color(color).ok()),
855 terminal_dim_foreground: self
856 .terminal_dim_foreground
857 .as_ref()
858 .and_then(|color| try_parse_color(color).ok()),
859 terminal_ansi_black: self
860 .terminal_ansi_black
861 .as_ref()
862 .and_then(|color| try_parse_color(color).ok()),
863 terminal_ansi_bright_black: self
864 .terminal_ansi_bright_black
865 .as_ref()
866 .and_then(|color| try_parse_color(color).ok()),
867 terminal_ansi_dim_black: self
868 .terminal_ansi_dim_black
869 .as_ref()
870 .and_then(|color| try_parse_color(color).ok()),
871 terminal_ansi_red: self
872 .terminal_ansi_red
873 .as_ref()
874 .and_then(|color| try_parse_color(color).ok()),
875 terminal_ansi_bright_red: self
876 .terminal_ansi_bright_red
877 .as_ref()
878 .and_then(|color| try_parse_color(color).ok()),
879 terminal_ansi_dim_red: self
880 .terminal_ansi_dim_red
881 .as_ref()
882 .and_then(|color| try_parse_color(color).ok()),
883 terminal_ansi_green: self
884 .terminal_ansi_green
885 .as_ref()
886 .and_then(|color| try_parse_color(color).ok()),
887 terminal_ansi_bright_green: self
888 .terminal_ansi_bright_green
889 .as_ref()
890 .and_then(|color| try_parse_color(color).ok()),
891 terminal_ansi_dim_green: self
892 .terminal_ansi_dim_green
893 .as_ref()
894 .and_then(|color| try_parse_color(color).ok()),
895 terminal_ansi_yellow: self
896 .terminal_ansi_yellow
897 .as_ref()
898 .and_then(|color| try_parse_color(color).ok()),
899 terminal_ansi_bright_yellow: self
900 .terminal_ansi_bright_yellow
901 .as_ref()
902 .and_then(|color| try_parse_color(color).ok()),
903 terminal_ansi_dim_yellow: self
904 .terminal_ansi_dim_yellow
905 .as_ref()
906 .and_then(|color| try_parse_color(color).ok()),
907 terminal_ansi_blue: self
908 .terminal_ansi_blue
909 .as_ref()
910 .and_then(|color| try_parse_color(color).ok()),
911 terminal_ansi_bright_blue: self
912 .terminal_ansi_bright_blue
913 .as_ref()
914 .and_then(|color| try_parse_color(color).ok()),
915 terminal_ansi_dim_blue: self
916 .terminal_ansi_dim_blue
917 .as_ref()
918 .and_then(|color| try_parse_color(color).ok()),
919 terminal_ansi_magenta: self
920 .terminal_ansi_magenta
921 .as_ref()
922 .and_then(|color| try_parse_color(color).ok()),
923 terminal_ansi_bright_magenta: self
924 .terminal_ansi_bright_magenta
925 .as_ref()
926 .and_then(|color| try_parse_color(color).ok()),
927 terminal_ansi_dim_magenta: self
928 .terminal_ansi_dim_magenta
929 .as_ref()
930 .and_then(|color| try_parse_color(color).ok()),
931 terminal_ansi_cyan: self
932 .terminal_ansi_cyan
933 .as_ref()
934 .and_then(|color| try_parse_color(color).ok()),
935 terminal_ansi_bright_cyan: self
936 .terminal_ansi_bright_cyan
937 .as_ref()
938 .and_then(|color| try_parse_color(color).ok()),
939 terminal_ansi_dim_cyan: self
940 .terminal_ansi_dim_cyan
941 .as_ref()
942 .and_then(|color| try_parse_color(color).ok()),
943 terminal_ansi_white: self
944 .terminal_ansi_white
945 .as_ref()
946 .and_then(|color| try_parse_color(color).ok()),
947 terminal_ansi_bright_white: self
948 .terminal_ansi_bright_white
949 .as_ref()
950 .and_then(|color| try_parse_color(color).ok()),
951 terminal_ansi_dim_white: self
952 .terminal_ansi_dim_white
953 .as_ref()
954 .and_then(|color| try_parse_color(color).ok()),
955 link_text_hover: self
956 .link_text_hover
957 .as_ref()
958 .and_then(|color| try_parse_color(color).ok()),
959 }
960 }
961}
962
963#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
964#[serde(default)]
965pub struct StatusColorsContent {
966 /// Indicates some kind of conflict, like a file changed on disk while it was open, or
967 /// merge conflicts in a Git repository.
968 #[serde(rename = "conflict")]
969 pub conflict: Option<String>,
970
971 #[serde(rename = "conflict.background")]
972 pub conflict_background: Option<String>,
973
974 #[serde(rename = "conflict.border")]
975 pub conflict_border: Option<String>,
976
977 /// Indicates something new, like a new file added to a Git repository.
978 #[serde(rename = "created")]
979 pub created: Option<String>,
980
981 #[serde(rename = "created.background")]
982 pub created_background: Option<String>,
983
984 #[serde(rename = "created.border")]
985 pub created_border: Option<String>,
986
987 /// Indicates that something no longer exists, like a deleted file.
988 #[serde(rename = "deleted")]
989 pub deleted: Option<String>,
990
991 #[serde(rename = "deleted.background")]
992 pub deleted_background: Option<String>,
993
994 #[serde(rename = "deleted.border")]
995 pub deleted_border: Option<String>,
996
997 /// Indicates a system error, a failed operation or a diagnostic error.
998 #[serde(rename = "error")]
999 pub error: Option<String>,
1000
1001 #[serde(rename = "error.background")]
1002 pub error_background: Option<String>,
1003
1004 #[serde(rename = "error.border")]
1005 pub error_border: Option<String>,
1006
1007 /// Represents a hidden status, such as a file being hidden in a file tree.
1008 #[serde(rename = "hidden")]
1009 pub hidden: Option<String>,
1010
1011 #[serde(rename = "hidden.background")]
1012 pub hidden_background: Option<String>,
1013
1014 #[serde(rename = "hidden.border")]
1015 pub hidden_border: Option<String>,
1016
1017 /// Indicates a hint or some kind of additional information.
1018 #[serde(rename = "hint")]
1019 pub hint: Option<String>,
1020
1021 #[serde(rename = "hint.background")]
1022 pub hint_background: Option<String>,
1023
1024 #[serde(rename = "hint.border")]
1025 pub hint_border: Option<String>,
1026
1027 /// Indicates that something is deliberately ignored, such as a file or operation ignored by Git.
1028 #[serde(rename = "ignored")]
1029 pub ignored: Option<String>,
1030
1031 #[serde(rename = "ignored.background")]
1032 pub ignored_background: Option<String>,
1033
1034 #[serde(rename = "ignored.border")]
1035 pub ignored_border: Option<String>,
1036
1037 /// Represents informational status updates or messages.
1038 #[serde(rename = "info")]
1039 pub info: Option<String>,
1040
1041 #[serde(rename = "info.background")]
1042 pub info_background: Option<String>,
1043
1044 #[serde(rename = "info.border")]
1045 pub info_border: Option<String>,
1046
1047 /// Indicates a changed or altered status, like a file that has been edited.
1048 #[serde(rename = "modified")]
1049 pub modified: Option<String>,
1050
1051 #[serde(rename = "modified.background")]
1052 pub modified_background: Option<String>,
1053
1054 #[serde(rename = "modified.border")]
1055 pub modified_border: Option<String>,
1056
1057 /// Indicates something that is predicted, like automatic code completion, or generated code.
1058 #[serde(rename = "predictive")]
1059 pub predictive: Option<String>,
1060
1061 #[serde(rename = "predictive.background")]
1062 pub predictive_background: Option<String>,
1063
1064 #[serde(rename = "predictive.border")]
1065 pub predictive_border: Option<String>,
1066
1067 /// Represents a renamed status, such as a file that has been renamed.
1068 #[serde(rename = "renamed")]
1069 pub renamed: Option<String>,
1070
1071 #[serde(rename = "renamed.background")]
1072 pub renamed_background: Option<String>,
1073
1074 #[serde(rename = "renamed.border")]
1075 pub renamed_border: Option<String>,
1076
1077 /// Indicates a successful operation or task completion.
1078 #[serde(rename = "success")]
1079 pub success: Option<String>,
1080
1081 #[serde(rename = "success.background")]
1082 pub success_background: Option<String>,
1083
1084 #[serde(rename = "success.border")]
1085 pub success_border: Option<String>,
1086
1087 /// Indicates some kind of unreachable status, like a block of code that can never be reached.
1088 #[serde(rename = "unreachable")]
1089 pub unreachable: Option<String>,
1090
1091 #[serde(rename = "unreachable.background")]
1092 pub unreachable_background: Option<String>,
1093
1094 #[serde(rename = "unreachable.border")]
1095 pub unreachable_border: Option<String>,
1096
1097 /// Represents a warning status, like an operation that is about to fail.
1098 #[serde(rename = "warning")]
1099 pub warning: Option<String>,
1100
1101 #[serde(rename = "warning.background")]
1102 pub warning_background: Option<String>,
1103
1104 #[serde(rename = "warning.border")]
1105 pub warning_border: Option<String>,
1106}
1107
1108impl StatusColorsContent {
1109 /// Returns a [`StatusColorsRefinement`] based on the colors in the [`StatusColorsContent`].
1110 pub fn status_colors_refinement(&self) -> StatusColorsRefinement {
1111 StatusColorsRefinement {
1112 conflict: self
1113 .conflict
1114 .as_ref()
1115 .and_then(|color| try_parse_color(color).ok()),
1116 conflict_background: self
1117 .conflict_background
1118 .as_ref()
1119 .and_then(|color| try_parse_color(color).ok()),
1120 conflict_border: self
1121 .conflict_border
1122 .as_ref()
1123 .and_then(|color| try_parse_color(color).ok()),
1124 created: self
1125 .created
1126 .as_ref()
1127 .and_then(|color| try_parse_color(color).ok()),
1128 created_background: self
1129 .created_background
1130 .as_ref()
1131 .and_then(|color| try_parse_color(color).ok()),
1132 created_border: self
1133 .created_border
1134 .as_ref()
1135 .and_then(|color| try_parse_color(color).ok()),
1136 deleted: self
1137 .deleted
1138 .as_ref()
1139 .and_then(|color| try_parse_color(color).ok()),
1140 deleted_background: self
1141 .deleted_background
1142 .as_ref()
1143 .and_then(|color| try_parse_color(color).ok()),
1144 deleted_border: self
1145 .deleted_border
1146 .as_ref()
1147 .and_then(|color| try_parse_color(color).ok()),
1148 error: self
1149 .error
1150 .as_ref()
1151 .and_then(|color| try_parse_color(color).ok()),
1152 error_background: self
1153 .error_background
1154 .as_ref()
1155 .and_then(|color| try_parse_color(color).ok()),
1156 error_border: self
1157 .error_border
1158 .as_ref()
1159 .and_then(|color| try_parse_color(color).ok()),
1160 hidden: self
1161 .hidden
1162 .as_ref()
1163 .and_then(|color| try_parse_color(color).ok()),
1164 hidden_background: self
1165 .hidden_background
1166 .as_ref()
1167 .and_then(|color| try_parse_color(color).ok()),
1168 hidden_border: self
1169 .hidden_border
1170 .as_ref()
1171 .and_then(|color| try_parse_color(color).ok()),
1172 hint: self
1173 .hint
1174 .as_ref()
1175 .and_then(|color| try_parse_color(color).ok()),
1176 hint_background: self
1177 .hint_background
1178 .as_ref()
1179 .and_then(|color| try_parse_color(color).ok()),
1180 hint_border: self
1181 .hint_border
1182 .as_ref()
1183 .and_then(|color| try_parse_color(color).ok()),
1184 ignored: self
1185 .ignored
1186 .as_ref()
1187 .and_then(|color| try_parse_color(color).ok()),
1188 ignored_background: self
1189 .ignored_background
1190 .as_ref()
1191 .and_then(|color| try_parse_color(color).ok()),
1192 ignored_border: self
1193 .ignored_border
1194 .as_ref()
1195 .and_then(|color| try_parse_color(color).ok()),
1196 info: self
1197 .info
1198 .as_ref()
1199 .and_then(|color| try_parse_color(color).ok()),
1200 info_background: self
1201 .info_background
1202 .as_ref()
1203 .and_then(|color| try_parse_color(color).ok()),
1204 info_border: self
1205 .info_border
1206 .as_ref()
1207 .and_then(|color| try_parse_color(color).ok()),
1208 modified: self
1209 .modified
1210 .as_ref()
1211 .and_then(|color| try_parse_color(color).ok()),
1212 modified_background: self
1213 .modified_background
1214 .as_ref()
1215 .and_then(|color| try_parse_color(color).ok()),
1216 modified_border: self
1217 .modified_border
1218 .as_ref()
1219 .and_then(|color| try_parse_color(color).ok()),
1220 predictive: self
1221 .predictive
1222 .as_ref()
1223 .and_then(|color| try_parse_color(color).ok()),
1224 predictive_background: self
1225 .predictive_background
1226 .as_ref()
1227 .and_then(|color| try_parse_color(color).ok()),
1228 predictive_border: self
1229 .predictive_border
1230 .as_ref()
1231 .and_then(|color| try_parse_color(color).ok()),
1232 renamed: self
1233 .renamed
1234 .as_ref()
1235 .and_then(|color| try_parse_color(color).ok()),
1236 renamed_background: self
1237 .renamed_background
1238 .as_ref()
1239 .and_then(|color| try_parse_color(color).ok()),
1240 renamed_border: self
1241 .renamed_border
1242 .as_ref()
1243 .and_then(|color| try_parse_color(color).ok()),
1244 success: self
1245 .success
1246 .as_ref()
1247 .and_then(|color| try_parse_color(color).ok()),
1248 success_background: self
1249 .success_background
1250 .as_ref()
1251 .and_then(|color| try_parse_color(color).ok()),
1252 success_border: self
1253 .success_border
1254 .as_ref()
1255 .and_then(|color| try_parse_color(color).ok()),
1256 unreachable: self
1257 .unreachable
1258 .as_ref()
1259 .and_then(|color| try_parse_color(color).ok()),
1260 unreachable_background: self
1261 .unreachable_background
1262 .as_ref()
1263 .and_then(|color| try_parse_color(color).ok()),
1264 unreachable_border: self
1265 .unreachable_border
1266 .as_ref()
1267 .and_then(|color| try_parse_color(color).ok()),
1268 warning: self
1269 .warning
1270 .as_ref()
1271 .and_then(|color| try_parse_color(color).ok()),
1272 warning_background: self
1273 .warning_background
1274 .as_ref()
1275 .and_then(|color| try_parse_color(color).ok()),
1276 warning_border: self
1277 .warning_border
1278 .as_ref()
1279 .and_then(|color| try_parse_color(color).ok()),
1280 }
1281 }
1282}
1283
1284#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
1285pub struct AccentContent(pub Option<String>);
1286
1287#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
1288pub struct PlayerColorContent {
1289 pub cursor: Option<String>,
1290 pub background: Option<String>,
1291 pub selection: Option<String>,
1292}
1293
1294#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq)]
1295#[serde(rename_all = "snake_case")]
1296pub enum FontStyleContent {
1297 Normal,
1298 Italic,
1299 Oblique,
1300}
1301
1302impl From<FontStyleContent> for FontStyle {
1303 fn from(value: FontStyleContent) -> Self {
1304 match value {
1305 FontStyleContent::Normal => FontStyle::Normal,
1306 FontStyleContent::Italic => FontStyle::Italic,
1307 FontStyleContent::Oblique => FontStyle::Oblique,
1308 }
1309 }
1310}
1311
1312#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq)]
1313#[repr(u16)]
1314pub enum FontWeightContent {
1315 Thin = 100,
1316 ExtraLight = 200,
1317 Light = 300,
1318 Normal = 400,
1319 Medium = 500,
1320 Semibold = 600,
1321 Bold = 700,
1322 ExtraBold = 800,
1323 Black = 900,
1324}
1325
1326impl JsonSchema for FontWeightContent {
1327 fn schema_name() -> String {
1328 "FontWeightContent".to_owned()
1329 }
1330
1331 fn is_referenceable() -> bool {
1332 false
1333 }
1334
1335 fn json_schema(_: &mut SchemaGenerator) -> Schema {
1336 SchemaObject {
1337 enum_values: Some(vec![
1338 100.into(),
1339 200.into(),
1340 300.into(),
1341 400.into(),
1342 500.into(),
1343 600.into(),
1344 700.into(),
1345 800.into(),
1346 900.into(),
1347 ]),
1348 ..Default::default()
1349 }
1350 .into()
1351 }
1352}
1353
1354impl From<FontWeightContent> for FontWeight {
1355 fn from(value: FontWeightContent) -> Self {
1356 match value {
1357 FontWeightContent::Thin => FontWeight::THIN,
1358 FontWeightContent::ExtraLight => FontWeight::EXTRA_LIGHT,
1359 FontWeightContent::Light => FontWeight::LIGHT,
1360 FontWeightContent::Normal => FontWeight::NORMAL,
1361 FontWeightContent::Medium => FontWeight::MEDIUM,
1362 FontWeightContent::Semibold => FontWeight::SEMIBOLD,
1363 FontWeightContent::Bold => FontWeight::BOLD,
1364 FontWeightContent::ExtraBold => FontWeight::EXTRA_BOLD,
1365 FontWeightContent::Black => FontWeight::BLACK,
1366 }
1367 }
1368}
1369
1370#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
1371#[serde(default)]
1372pub struct HighlightStyleContent {
1373 pub color: Option<String>,
1374
1375 #[serde(deserialize_with = "treat_error_as_none")]
1376 pub background_color: Option<String>,
1377
1378 #[serde(deserialize_with = "treat_error_as_none")]
1379 pub font_style: Option<FontStyleContent>,
1380
1381 #[serde(deserialize_with = "treat_error_as_none")]
1382 pub font_weight: Option<FontWeightContent>,
1383}
1384
1385impl HighlightStyleContent {
1386 pub fn is_empty(&self) -> bool {
1387 self.color.is_none()
1388 && self.background_color.is_none()
1389 && self.font_style.is_none()
1390 && self.font_weight.is_none()
1391 }
1392}
1393
1394fn treat_error_as_none<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
1395where
1396 T: Deserialize<'de>,
1397 D: Deserializer<'de>,
1398{
1399 let value: Value = Deserialize::deserialize(deserializer)?;
1400 Ok(T::deserialize(value).ok())
1401}