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