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