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