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