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