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 /// Added version control color.
557 #[serde(rename = "version_control.added")]
558 pub version_control_added: Option<String>,
559
560 /// Deleted version control color.
561 #[serde(rename = "version_control.deleted")]
562 pub version_control_deleted: Option<String>,
563
564 /// Modified version control color.
565 #[serde(rename = "version_control.modified")]
566 pub version_control_modified: Option<String>,
567
568 /// Renamed version control color.
569 #[serde(rename = "version_control.renamed")]
570 pub version_control_renamed: Option<String>,
571
572 /// Conflict version control color.
573 #[serde(rename = "version_control.conflict")]
574 pub version_control_conflict: Option<String>,
575
576 /// Ignored version control color.
577 #[serde(rename = "version_control.ignored")]
578 pub version_control_ignored: Option<String>,
579}
580
581impl ThemeColorsContent {
582 /// Returns a [`ThemeColorsRefinement`] based on the colors in the [`ThemeColorsContent`].
583 pub fn theme_colors_refinement(&self) -> ThemeColorsRefinement {
584 let border = self
585 .border
586 .as_ref()
587 .and_then(|color| try_parse_color(color).ok());
588 let editor_document_highlight_read_background = self
589 .editor_document_highlight_read_background
590 .as_ref()
591 .and_then(|color| try_parse_color(color).ok());
592 ThemeColorsRefinement {
593 border,
594 border_variant: self
595 .border_variant
596 .as_ref()
597 .and_then(|color| try_parse_color(color).ok()),
598 border_focused: self
599 .border_focused
600 .as_ref()
601 .and_then(|color| try_parse_color(color).ok()),
602 border_selected: self
603 .border_selected
604 .as_ref()
605 .and_then(|color| try_parse_color(color).ok()),
606 border_transparent: self
607 .border_transparent
608 .as_ref()
609 .and_then(|color| try_parse_color(color).ok()),
610 border_disabled: self
611 .border_disabled
612 .as_ref()
613 .and_then(|color| try_parse_color(color).ok()),
614 elevated_surface_background: self
615 .elevated_surface_background
616 .as_ref()
617 .and_then(|color| try_parse_color(color).ok()),
618 surface_background: self
619 .surface_background
620 .as_ref()
621 .and_then(|color| try_parse_color(color).ok()),
622 background: self
623 .background
624 .as_ref()
625 .and_then(|color| try_parse_color(color).ok()),
626 element_background: self
627 .element_background
628 .as_ref()
629 .and_then(|color| try_parse_color(color).ok()),
630 element_hover: self
631 .element_hover
632 .as_ref()
633 .and_then(|color| try_parse_color(color).ok()),
634 element_active: self
635 .element_active
636 .as_ref()
637 .and_then(|color| try_parse_color(color).ok()),
638 element_selected: self
639 .element_selected
640 .as_ref()
641 .and_then(|color| try_parse_color(color).ok()),
642 element_disabled: self
643 .element_disabled
644 .as_ref()
645 .and_then(|color| try_parse_color(color).ok()),
646 drop_target_background: self
647 .drop_target_background
648 .as_ref()
649 .and_then(|color| try_parse_color(color).ok()),
650 ghost_element_background: self
651 .ghost_element_background
652 .as_ref()
653 .and_then(|color| try_parse_color(color).ok()),
654 ghost_element_hover: self
655 .ghost_element_hover
656 .as_ref()
657 .and_then(|color| try_parse_color(color).ok()),
658 ghost_element_active: self
659 .ghost_element_active
660 .as_ref()
661 .and_then(|color| try_parse_color(color).ok()),
662 ghost_element_selected: self
663 .ghost_element_selected
664 .as_ref()
665 .and_then(|color| try_parse_color(color).ok()),
666 ghost_element_disabled: self
667 .ghost_element_disabled
668 .as_ref()
669 .and_then(|color| try_parse_color(color).ok()),
670 text: self
671 .text
672 .as_ref()
673 .and_then(|color| try_parse_color(color).ok()),
674 text_muted: self
675 .text_muted
676 .as_ref()
677 .and_then(|color| try_parse_color(color).ok()),
678 text_placeholder: self
679 .text_placeholder
680 .as_ref()
681 .and_then(|color| try_parse_color(color).ok()),
682 text_disabled: self
683 .text_disabled
684 .as_ref()
685 .and_then(|color| try_parse_color(color).ok()),
686 text_accent: self
687 .text_accent
688 .as_ref()
689 .and_then(|color| try_parse_color(color).ok()),
690 icon: self
691 .icon
692 .as_ref()
693 .and_then(|color| try_parse_color(color).ok()),
694 icon_muted: self
695 .icon_muted
696 .as_ref()
697 .and_then(|color| try_parse_color(color).ok()),
698 icon_disabled: self
699 .icon_disabled
700 .as_ref()
701 .and_then(|color| try_parse_color(color).ok()),
702 icon_placeholder: self
703 .icon_placeholder
704 .as_ref()
705 .and_then(|color| try_parse_color(color).ok()),
706 icon_accent: self
707 .icon_accent
708 .as_ref()
709 .and_then(|color| try_parse_color(color).ok()),
710 status_bar_background: self
711 .status_bar_background
712 .as_ref()
713 .and_then(|color| try_parse_color(color).ok()),
714 title_bar_background: self
715 .title_bar_background
716 .as_ref()
717 .and_then(|color| try_parse_color(color).ok()),
718 title_bar_inactive_background: self
719 .title_bar_inactive_background
720 .as_ref()
721 .and_then(|color| try_parse_color(color).ok()),
722 toolbar_background: self
723 .toolbar_background
724 .as_ref()
725 .and_then(|color| try_parse_color(color).ok()),
726 tab_bar_background: self
727 .tab_bar_background
728 .as_ref()
729 .and_then(|color| try_parse_color(color).ok()),
730 tab_inactive_background: self
731 .tab_inactive_background
732 .as_ref()
733 .and_then(|color| try_parse_color(color).ok()),
734 tab_active_background: self
735 .tab_active_background
736 .as_ref()
737 .and_then(|color| try_parse_color(color).ok()),
738 search_match_background: self
739 .search_match_background
740 .as_ref()
741 .and_then(|color| try_parse_color(color).ok()),
742 panel_background: self
743 .panel_background
744 .as_ref()
745 .and_then(|color| try_parse_color(color).ok()),
746 panel_focused_border: self
747 .panel_focused_border
748 .as_ref()
749 .and_then(|color| try_parse_color(color).ok()),
750 panel_indent_guide: self
751 .panel_indent_guide
752 .as_ref()
753 .and_then(|color| try_parse_color(color).ok()),
754 panel_indent_guide_hover: self
755 .panel_indent_guide_hover
756 .as_ref()
757 .and_then(|color| try_parse_color(color).ok()),
758 panel_indent_guide_active: self
759 .panel_indent_guide_active
760 .as_ref()
761 .and_then(|color| try_parse_color(color).ok()),
762 pane_focused_border: self
763 .pane_focused_border
764 .as_ref()
765 .and_then(|color| try_parse_color(color).ok()),
766 pane_group_border: self
767 .pane_group_border
768 .as_ref()
769 .and_then(|color| try_parse_color(color).ok())
770 .or(border),
771 scrollbar_thumb_background: self
772 .scrollbar_thumb_background
773 .as_ref()
774 .and_then(|color| try_parse_color(color).ok())
775 .or_else(|| {
776 self.deprecated_scrollbar_thumb_background
777 .as_ref()
778 .and_then(|color| try_parse_color(color).ok())
779 }),
780 scrollbar_thumb_hover_background: self
781 .scrollbar_thumb_hover_background
782 .as_ref()
783 .and_then(|color| try_parse_color(color).ok()),
784 scrollbar_thumb_border: self
785 .scrollbar_thumb_border
786 .as_ref()
787 .and_then(|color| try_parse_color(color).ok()),
788 scrollbar_track_background: self
789 .scrollbar_track_background
790 .as_ref()
791 .and_then(|color| try_parse_color(color).ok()),
792 scrollbar_track_border: self
793 .scrollbar_track_border
794 .as_ref()
795 .and_then(|color| try_parse_color(color).ok()),
796 editor_foreground: self
797 .editor_foreground
798 .as_ref()
799 .and_then(|color| try_parse_color(color).ok()),
800 editor_background: self
801 .editor_background
802 .as_ref()
803 .and_then(|color| try_parse_color(color).ok()),
804 editor_gutter_background: self
805 .editor_gutter_background
806 .as_ref()
807 .and_then(|color| try_parse_color(color).ok()),
808 editor_subheader_background: self
809 .editor_subheader_background
810 .as_ref()
811 .and_then(|color| try_parse_color(color).ok()),
812 editor_active_line_background: self
813 .editor_active_line_background
814 .as_ref()
815 .and_then(|color| try_parse_color(color).ok()),
816 editor_highlighted_line_background: self
817 .editor_highlighted_line_background
818 .as_ref()
819 .and_then(|color| try_parse_color(color).ok()),
820 editor_line_number: self
821 .editor_line_number
822 .as_ref()
823 .and_then(|color| try_parse_color(color).ok()),
824 editor_hover_line_number: self
825 .editor_hover_line_number
826 .as_ref()
827 .and_then(|color| try_parse_color(color).ok()),
828 editor_active_line_number: self
829 .editor_active_line_number
830 .as_ref()
831 .and_then(|color| try_parse_color(color).ok()),
832 editor_invisible: self
833 .editor_invisible
834 .as_ref()
835 .and_then(|color| try_parse_color(color).ok()),
836 editor_wrap_guide: self
837 .editor_wrap_guide
838 .as_ref()
839 .and_then(|color| try_parse_color(color).ok()),
840 editor_active_wrap_guide: self
841 .editor_active_wrap_guide
842 .as_ref()
843 .and_then(|color| try_parse_color(color).ok()),
844 editor_indent_guide: self
845 .editor_indent_guide
846 .as_ref()
847 .and_then(|color| try_parse_color(color).ok()),
848 editor_indent_guide_active: self
849 .editor_indent_guide_active
850 .as_ref()
851 .and_then(|color| try_parse_color(color).ok()),
852 editor_document_highlight_read_background,
853 editor_document_highlight_write_background: self
854 .editor_document_highlight_write_background
855 .as_ref()
856 .and_then(|color| try_parse_color(color).ok()),
857 editor_document_highlight_bracket_background: self
858 .editor_document_highlight_bracket_background
859 .as_ref()
860 .and_then(|color| try_parse_color(color).ok())
861 // Fall back to `editor.document_highlight.read_background`, for backwards compatibility.
862 .or(editor_document_highlight_read_background),
863 terminal_background: self
864 .terminal_background
865 .as_ref()
866 .and_then(|color| try_parse_color(color).ok()),
867 terminal_ansi_background: self
868 .terminal_ansi_background
869 .as_ref()
870 .and_then(|color| try_parse_color(color).ok()),
871 terminal_foreground: self
872 .terminal_foreground
873 .as_ref()
874 .and_then(|color| try_parse_color(color).ok()),
875 terminal_bright_foreground: self
876 .terminal_bright_foreground
877 .as_ref()
878 .and_then(|color| try_parse_color(color).ok()),
879 terminal_dim_foreground: self
880 .terminal_dim_foreground
881 .as_ref()
882 .and_then(|color| try_parse_color(color).ok()),
883 terminal_ansi_black: self
884 .terminal_ansi_black
885 .as_ref()
886 .and_then(|color| try_parse_color(color).ok()),
887 terminal_ansi_bright_black: self
888 .terminal_ansi_bright_black
889 .as_ref()
890 .and_then(|color| try_parse_color(color).ok()),
891 terminal_ansi_dim_black: self
892 .terminal_ansi_dim_black
893 .as_ref()
894 .and_then(|color| try_parse_color(color).ok()),
895 terminal_ansi_red: self
896 .terminal_ansi_red
897 .as_ref()
898 .and_then(|color| try_parse_color(color).ok()),
899 terminal_ansi_bright_red: self
900 .terminal_ansi_bright_red
901 .as_ref()
902 .and_then(|color| try_parse_color(color).ok()),
903 terminal_ansi_dim_red: self
904 .terminal_ansi_dim_red
905 .as_ref()
906 .and_then(|color| try_parse_color(color).ok()),
907 terminal_ansi_green: self
908 .terminal_ansi_green
909 .as_ref()
910 .and_then(|color| try_parse_color(color).ok()),
911 terminal_ansi_bright_green: self
912 .terminal_ansi_bright_green
913 .as_ref()
914 .and_then(|color| try_parse_color(color).ok()),
915 terminal_ansi_dim_green: self
916 .terminal_ansi_dim_green
917 .as_ref()
918 .and_then(|color| try_parse_color(color).ok()),
919 terminal_ansi_yellow: self
920 .terminal_ansi_yellow
921 .as_ref()
922 .and_then(|color| try_parse_color(color).ok()),
923 terminal_ansi_bright_yellow: self
924 .terminal_ansi_bright_yellow
925 .as_ref()
926 .and_then(|color| try_parse_color(color).ok()),
927 terminal_ansi_dim_yellow: self
928 .terminal_ansi_dim_yellow
929 .as_ref()
930 .and_then(|color| try_parse_color(color).ok()),
931 terminal_ansi_blue: self
932 .terminal_ansi_blue
933 .as_ref()
934 .and_then(|color| try_parse_color(color).ok()),
935 terminal_ansi_bright_blue: self
936 .terminal_ansi_bright_blue
937 .as_ref()
938 .and_then(|color| try_parse_color(color).ok()),
939 terminal_ansi_dim_blue: self
940 .terminal_ansi_dim_blue
941 .as_ref()
942 .and_then(|color| try_parse_color(color).ok()),
943 terminal_ansi_magenta: self
944 .terminal_ansi_magenta
945 .as_ref()
946 .and_then(|color| try_parse_color(color).ok()),
947 terminal_ansi_bright_magenta: self
948 .terminal_ansi_bright_magenta
949 .as_ref()
950 .and_then(|color| try_parse_color(color).ok()),
951 terminal_ansi_dim_magenta: self
952 .terminal_ansi_dim_magenta
953 .as_ref()
954 .and_then(|color| try_parse_color(color).ok()),
955 terminal_ansi_cyan: self
956 .terminal_ansi_cyan
957 .as_ref()
958 .and_then(|color| try_parse_color(color).ok()),
959 terminal_ansi_bright_cyan: self
960 .terminal_ansi_bright_cyan
961 .as_ref()
962 .and_then(|color| try_parse_color(color).ok()),
963 terminal_ansi_dim_cyan: self
964 .terminal_ansi_dim_cyan
965 .as_ref()
966 .and_then(|color| try_parse_color(color).ok()),
967 terminal_ansi_white: self
968 .terminal_ansi_white
969 .as_ref()
970 .and_then(|color| try_parse_color(color).ok()),
971 terminal_ansi_bright_white: self
972 .terminal_ansi_bright_white
973 .as_ref()
974 .and_then(|color| try_parse_color(color).ok()),
975 terminal_ansi_dim_white: self
976 .terminal_ansi_dim_white
977 .as_ref()
978 .and_then(|color| try_parse_color(color).ok()),
979 link_text_hover: self
980 .link_text_hover
981 .as_ref()
982 .and_then(|color| try_parse_color(color).ok()),
983 version_control_added: self
984 .version_control_added
985 .as_ref()
986 .and_then(|color| try_parse_color(color).ok()),
987 version_control_deleted: self
988 .version_control_deleted
989 .as_ref()
990 .and_then(|color| try_parse_color(color).ok()),
991 version_control_modified: self
992 .version_control_modified
993 .as_ref()
994 .and_then(|color| try_parse_color(color).ok()),
995 version_control_renamed: self
996 .version_control_renamed
997 .as_ref()
998 .and_then(|color| try_parse_color(color).ok()),
999 version_control_conflict: self
1000 .version_control_conflict
1001 .as_ref()
1002 .and_then(|color| try_parse_color(color).ok()),
1003 version_control_ignored: self
1004 .version_control_ignored
1005 .as_ref()
1006 .and_then(|color| try_parse_color(color).ok()),
1007 }
1008 }
1009}
1010
1011#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
1012#[serde(default)]
1013pub struct StatusColorsContent {
1014 /// Indicates some kind of conflict, like a file changed on disk while it was open, or
1015 /// merge conflicts in a Git repository.
1016 #[serde(rename = "conflict")]
1017 pub conflict: Option<String>,
1018
1019 #[serde(rename = "conflict.background")]
1020 pub conflict_background: Option<String>,
1021
1022 #[serde(rename = "conflict.border")]
1023 pub conflict_border: Option<String>,
1024
1025 /// Indicates something new, like a new file added to a Git repository.
1026 #[serde(rename = "created")]
1027 pub created: Option<String>,
1028
1029 #[serde(rename = "created.background")]
1030 pub created_background: Option<String>,
1031
1032 #[serde(rename = "created.border")]
1033 pub created_border: Option<String>,
1034
1035 /// Indicates that something no longer exists, like a deleted file.
1036 #[serde(rename = "deleted")]
1037 pub deleted: Option<String>,
1038
1039 #[serde(rename = "deleted.background")]
1040 pub deleted_background: Option<String>,
1041
1042 #[serde(rename = "deleted.border")]
1043 pub deleted_border: Option<String>,
1044
1045 /// Indicates a system error, a failed operation or a diagnostic error.
1046 #[serde(rename = "error")]
1047 pub error: Option<String>,
1048
1049 #[serde(rename = "error.background")]
1050 pub error_background: Option<String>,
1051
1052 #[serde(rename = "error.border")]
1053 pub error_border: Option<String>,
1054
1055 /// Represents a hidden status, such as a file being hidden in a file tree.
1056 #[serde(rename = "hidden")]
1057 pub hidden: Option<String>,
1058
1059 #[serde(rename = "hidden.background")]
1060 pub hidden_background: Option<String>,
1061
1062 #[serde(rename = "hidden.border")]
1063 pub hidden_border: Option<String>,
1064
1065 /// Indicates a hint or some kind of additional information.
1066 #[serde(rename = "hint")]
1067 pub hint: Option<String>,
1068
1069 #[serde(rename = "hint.background")]
1070 pub hint_background: Option<String>,
1071
1072 #[serde(rename = "hint.border")]
1073 pub hint_border: Option<String>,
1074
1075 /// Indicates that something is deliberately ignored, such as a file or operation ignored by Git.
1076 #[serde(rename = "ignored")]
1077 pub ignored: Option<String>,
1078
1079 #[serde(rename = "ignored.background")]
1080 pub ignored_background: Option<String>,
1081
1082 #[serde(rename = "ignored.border")]
1083 pub ignored_border: Option<String>,
1084
1085 /// Represents informational status updates or messages.
1086 #[serde(rename = "info")]
1087 pub info: Option<String>,
1088
1089 #[serde(rename = "info.background")]
1090 pub info_background: Option<String>,
1091
1092 #[serde(rename = "info.border")]
1093 pub info_border: Option<String>,
1094
1095 /// Indicates a changed or altered status, like a file that has been edited.
1096 #[serde(rename = "modified")]
1097 pub modified: Option<String>,
1098
1099 #[serde(rename = "modified.background")]
1100 pub modified_background: Option<String>,
1101
1102 #[serde(rename = "modified.border")]
1103 pub modified_border: Option<String>,
1104
1105 /// Indicates something that is predicted, like automatic code completion, or generated code.
1106 #[serde(rename = "predictive")]
1107 pub predictive: Option<String>,
1108
1109 #[serde(rename = "predictive.background")]
1110 pub predictive_background: Option<String>,
1111
1112 #[serde(rename = "predictive.border")]
1113 pub predictive_border: Option<String>,
1114
1115 /// Represents a renamed status, such as a file that has been renamed.
1116 #[serde(rename = "renamed")]
1117 pub renamed: Option<String>,
1118
1119 #[serde(rename = "renamed.background")]
1120 pub renamed_background: Option<String>,
1121
1122 #[serde(rename = "renamed.border")]
1123 pub renamed_border: Option<String>,
1124
1125 /// Indicates a successful operation or task completion.
1126 #[serde(rename = "success")]
1127 pub success: Option<String>,
1128
1129 #[serde(rename = "success.background")]
1130 pub success_background: Option<String>,
1131
1132 #[serde(rename = "success.border")]
1133 pub success_border: Option<String>,
1134
1135 /// Indicates some kind of unreachable status, like a block of code that can never be reached.
1136 #[serde(rename = "unreachable")]
1137 pub unreachable: Option<String>,
1138
1139 #[serde(rename = "unreachable.background")]
1140 pub unreachable_background: Option<String>,
1141
1142 #[serde(rename = "unreachable.border")]
1143 pub unreachable_border: Option<String>,
1144
1145 /// Represents a warning status, like an operation that is about to fail.
1146 #[serde(rename = "warning")]
1147 pub warning: Option<String>,
1148
1149 #[serde(rename = "warning.background")]
1150 pub warning_background: Option<String>,
1151
1152 #[serde(rename = "warning.border")]
1153 pub warning_border: Option<String>,
1154}
1155
1156impl StatusColorsContent {
1157 /// Returns a [`StatusColorsRefinement`] based on the colors in the [`StatusColorsContent`].
1158 pub fn status_colors_refinement(&self) -> StatusColorsRefinement {
1159 StatusColorsRefinement {
1160 conflict: self
1161 .conflict
1162 .as_ref()
1163 .and_then(|color| try_parse_color(color).ok()),
1164 conflict_background: self
1165 .conflict_background
1166 .as_ref()
1167 .and_then(|color| try_parse_color(color).ok()),
1168 conflict_border: self
1169 .conflict_border
1170 .as_ref()
1171 .and_then(|color| try_parse_color(color).ok()),
1172 created: self
1173 .created
1174 .as_ref()
1175 .and_then(|color| try_parse_color(color).ok()),
1176 created_background: self
1177 .created_background
1178 .as_ref()
1179 .and_then(|color| try_parse_color(color).ok()),
1180 created_border: self
1181 .created_border
1182 .as_ref()
1183 .and_then(|color| try_parse_color(color).ok()),
1184 deleted: self
1185 .deleted
1186 .as_ref()
1187 .and_then(|color| try_parse_color(color).ok()),
1188 deleted_background: self
1189 .deleted_background
1190 .as_ref()
1191 .and_then(|color| try_parse_color(color).ok()),
1192 deleted_border: self
1193 .deleted_border
1194 .as_ref()
1195 .and_then(|color| try_parse_color(color).ok()),
1196 error: self
1197 .error
1198 .as_ref()
1199 .and_then(|color| try_parse_color(color).ok()),
1200 error_background: self
1201 .error_background
1202 .as_ref()
1203 .and_then(|color| try_parse_color(color).ok()),
1204 error_border: self
1205 .error_border
1206 .as_ref()
1207 .and_then(|color| try_parse_color(color).ok()),
1208 hidden: self
1209 .hidden
1210 .as_ref()
1211 .and_then(|color| try_parse_color(color).ok()),
1212 hidden_background: self
1213 .hidden_background
1214 .as_ref()
1215 .and_then(|color| try_parse_color(color).ok()),
1216 hidden_border: self
1217 .hidden_border
1218 .as_ref()
1219 .and_then(|color| try_parse_color(color).ok()),
1220 hint: self
1221 .hint
1222 .as_ref()
1223 .and_then(|color| try_parse_color(color).ok()),
1224 hint_background: self
1225 .hint_background
1226 .as_ref()
1227 .and_then(|color| try_parse_color(color).ok()),
1228 hint_border: self
1229 .hint_border
1230 .as_ref()
1231 .and_then(|color| try_parse_color(color).ok()),
1232 ignored: self
1233 .ignored
1234 .as_ref()
1235 .and_then(|color| try_parse_color(color).ok()),
1236 ignored_background: self
1237 .ignored_background
1238 .as_ref()
1239 .and_then(|color| try_parse_color(color).ok()),
1240 ignored_border: self
1241 .ignored_border
1242 .as_ref()
1243 .and_then(|color| try_parse_color(color).ok()),
1244 info: self
1245 .info
1246 .as_ref()
1247 .and_then(|color| try_parse_color(color).ok()),
1248 info_background: self
1249 .info_background
1250 .as_ref()
1251 .and_then(|color| try_parse_color(color).ok()),
1252 info_border: self
1253 .info_border
1254 .as_ref()
1255 .and_then(|color| try_parse_color(color).ok()),
1256 modified: self
1257 .modified
1258 .as_ref()
1259 .and_then(|color| try_parse_color(color).ok()),
1260 modified_background: self
1261 .modified_background
1262 .as_ref()
1263 .and_then(|color| try_parse_color(color).ok()),
1264 modified_border: self
1265 .modified_border
1266 .as_ref()
1267 .and_then(|color| try_parse_color(color).ok()),
1268 predictive: self
1269 .predictive
1270 .as_ref()
1271 .and_then(|color| try_parse_color(color).ok()),
1272 predictive_background: self
1273 .predictive_background
1274 .as_ref()
1275 .and_then(|color| try_parse_color(color).ok()),
1276 predictive_border: self
1277 .predictive_border
1278 .as_ref()
1279 .and_then(|color| try_parse_color(color).ok()),
1280 renamed: self
1281 .renamed
1282 .as_ref()
1283 .and_then(|color| try_parse_color(color).ok()),
1284 renamed_background: self
1285 .renamed_background
1286 .as_ref()
1287 .and_then(|color| try_parse_color(color).ok()),
1288 renamed_border: self
1289 .renamed_border
1290 .as_ref()
1291 .and_then(|color| try_parse_color(color).ok()),
1292 success: self
1293 .success
1294 .as_ref()
1295 .and_then(|color| try_parse_color(color).ok()),
1296 success_background: self
1297 .success_background
1298 .as_ref()
1299 .and_then(|color| try_parse_color(color).ok()),
1300 success_border: self
1301 .success_border
1302 .as_ref()
1303 .and_then(|color| try_parse_color(color).ok()),
1304 unreachable: self
1305 .unreachable
1306 .as_ref()
1307 .and_then(|color| try_parse_color(color).ok()),
1308 unreachable_background: self
1309 .unreachable_background
1310 .as_ref()
1311 .and_then(|color| try_parse_color(color).ok()),
1312 unreachable_border: self
1313 .unreachable_border
1314 .as_ref()
1315 .and_then(|color| try_parse_color(color).ok()),
1316 warning: self
1317 .warning
1318 .as_ref()
1319 .and_then(|color| try_parse_color(color).ok()),
1320 warning_background: self
1321 .warning_background
1322 .as_ref()
1323 .and_then(|color| try_parse_color(color).ok()),
1324 warning_border: self
1325 .warning_border
1326 .as_ref()
1327 .and_then(|color| try_parse_color(color).ok()),
1328 }
1329 }
1330}
1331
1332#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
1333pub struct AccentContent(pub Option<String>);
1334
1335#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
1336pub struct PlayerColorContent {
1337 pub cursor: Option<String>,
1338 pub background: Option<String>,
1339 pub selection: Option<String>,
1340}
1341
1342#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq)]
1343#[serde(rename_all = "snake_case")]
1344pub enum FontStyleContent {
1345 Normal,
1346 Italic,
1347 Oblique,
1348}
1349
1350impl From<FontStyleContent> for FontStyle {
1351 fn from(value: FontStyleContent) -> Self {
1352 match value {
1353 FontStyleContent::Normal => FontStyle::Normal,
1354 FontStyleContent::Italic => FontStyle::Italic,
1355 FontStyleContent::Oblique => FontStyle::Oblique,
1356 }
1357 }
1358}
1359
1360#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq)]
1361#[repr(u16)]
1362pub enum FontWeightContent {
1363 Thin = 100,
1364 ExtraLight = 200,
1365 Light = 300,
1366 Normal = 400,
1367 Medium = 500,
1368 Semibold = 600,
1369 Bold = 700,
1370 ExtraBold = 800,
1371 Black = 900,
1372}
1373
1374impl JsonSchema for FontWeightContent {
1375 fn schema_name() -> String {
1376 "FontWeightContent".to_owned()
1377 }
1378
1379 fn is_referenceable() -> bool {
1380 false
1381 }
1382
1383 fn json_schema(_: &mut SchemaGenerator) -> Schema {
1384 SchemaObject {
1385 enum_values: Some(vec![
1386 100.into(),
1387 200.into(),
1388 300.into(),
1389 400.into(),
1390 500.into(),
1391 600.into(),
1392 700.into(),
1393 800.into(),
1394 900.into(),
1395 ]),
1396 ..Default::default()
1397 }
1398 .into()
1399 }
1400}
1401
1402impl From<FontWeightContent> for FontWeight {
1403 fn from(value: FontWeightContent) -> Self {
1404 match value {
1405 FontWeightContent::Thin => FontWeight::THIN,
1406 FontWeightContent::ExtraLight => FontWeight::EXTRA_LIGHT,
1407 FontWeightContent::Light => FontWeight::LIGHT,
1408 FontWeightContent::Normal => FontWeight::NORMAL,
1409 FontWeightContent::Medium => FontWeight::MEDIUM,
1410 FontWeightContent::Semibold => FontWeight::SEMIBOLD,
1411 FontWeightContent::Bold => FontWeight::BOLD,
1412 FontWeightContent::ExtraBold => FontWeight::EXTRA_BOLD,
1413 FontWeightContent::Black => FontWeight::BLACK,
1414 }
1415 }
1416}
1417
1418#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
1419#[serde(default)]
1420pub struct HighlightStyleContent {
1421 pub color: Option<String>,
1422
1423 #[serde(deserialize_with = "treat_error_as_none")]
1424 pub background_color: Option<String>,
1425
1426 #[serde(deserialize_with = "treat_error_as_none")]
1427 pub font_style: Option<FontStyleContent>,
1428
1429 #[serde(deserialize_with = "treat_error_as_none")]
1430 pub font_weight: Option<FontWeightContent>,
1431}
1432
1433impl HighlightStyleContent {
1434 pub fn is_empty(&self) -> bool {
1435 self.color.is_none()
1436 && self.background_color.is_none()
1437 && self.font_style.is_none()
1438 && self.font_weight.is_none()
1439 }
1440}
1441
1442fn treat_error_as_none<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
1443where
1444 T: Deserialize<'de>,
1445 D: Deserializer<'de>,
1446{
1447 let value: Value = Deserialize::deserialize(deserializer)?;
1448 Ok(T::deserialize(value).ok())
1449}