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