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