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