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