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