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
894#[skip_serializing_none]
895#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]
896#[serde(default)]
897pub struct HighlightStyleContent {
898 pub color: Option<String>,
899
900 #[serde(deserialize_with = "treat_error_as_none")]
901 pub background_color: Option<String>,
902
903 #[serde(deserialize_with = "treat_error_as_none")]
904 pub font_style: Option<FontStyleContent>,
905
906 #[serde(deserialize_with = "treat_error_as_none")]
907 pub font_weight: Option<FontWeightContent>,
908}
909
910impl HighlightStyleContent {
911 pub fn is_empty(&self) -> bool {
912 self.color.is_none()
913 && self.background_color.is_none()
914 && self.font_style.is_none()
915 && self.font_weight.is_none()
916 }
917}
918
919fn treat_error_as_none<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
920where
921 T: Deserialize<'de>,
922 D: Deserializer<'de>,
923{
924 let value: Value = Deserialize::deserialize(deserializer)?;
925 Ok(T::deserialize(value).ok())
926}
927
928#[skip_serializing_none]
929#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]
930#[serde(default)]
931pub struct StatusColorsContent {
932 /// Indicates some kind of conflict, like a file changed on disk while it was open, or
933 /// merge conflicts in a Git repository.
934 #[serde(rename = "conflict")]
935 pub conflict: Option<String>,
936
937 #[serde(rename = "conflict.background")]
938 pub conflict_background: Option<String>,
939
940 #[serde(rename = "conflict.border")]
941 pub conflict_border: Option<String>,
942
943 /// Indicates something new, like a new file added to a Git repository.
944 #[serde(rename = "created")]
945 pub created: Option<String>,
946
947 #[serde(rename = "created.background")]
948 pub created_background: Option<String>,
949
950 #[serde(rename = "created.border")]
951 pub created_border: Option<String>,
952
953 /// Indicates that something no longer exists, like a deleted file.
954 #[serde(rename = "deleted")]
955 pub deleted: Option<String>,
956
957 #[serde(rename = "deleted.background")]
958 pub deleted_background: Option<String>,
959
960 #[serde(rename = "deleted.border")]
961 pub deleted_border: Option<String>,
962
963 /// Indicates a system error, a failed operation or a diagnostic error.
964 #[serde(rename = "error")]
965 pub error: Option<String>,
966
967 #[serde(rename = "error.background")]
968 pub error_background: Option<String>,
969
970 #[serde(rename = "error.border")]
971 pub error_border: Option<String>,
972
973 /// Represents a hidden status, such as a file being hidden in a file tree.
974 #[serde(rename = "hidden")]
975 pub hidden: Option<String>,
976
977 #[serde(rename = "hidden.background")]
978 pub hidden_background: Option<String>,
979
980 #[serde(rename = "hidden.border")]
981 pub hidden_border: Option<String>,
982
983 /// Indicates a hint or some kind of additional information.
984 #[serde(rename = "hint")]
985 pub hint: Option<String>,
986
987 #[serde(rename = "hint.background")]
988 pub hint_background: Option<String>,
989
990 #[serde(rename = "hint.border")]
991 pub hint_border: Option<String>,
992
993 /// Indicates that something is deliberately ignored, such as a file or operation ignored by Git.
994 #[serde(rename = "ignored")]
995 pub ignored: Option<String>,
996
997 #[serde(rename = "ignored.background")]
998 pub ignored_background: Option<String>,
999
1000 #[serde(rename = "ignored.border")]
1001 pub ignored_border: Option<String>,
1002
1003 /// Represents informational status updates or messages.
1004 #[serde(rename = "info")]
1005 pub info: Option<String>,
1006
1007 #[serde(rename = "info.background")]
1008 pub info_background: Option<String>,
1009
1010 #[serde(rename = "info.border")]
1011 pub info_border: Option<String>,
1012
1013 /// Indicates a changed or altered status, like a file that has been edited.
1014 #[serde(rename = "modified")]
1015 pub modified: Option<String>,
1016
1017 #[serde(rename = "modified.background")]
1018 pub modified_background: Option<String>,
1019
1020 #[serde(rename = "modified.border")]
1021 pub modified_border: Option<String>,
1022
1023 /// Indicates something that is predicted, like automatic code completion, or generated code.
1024 #[serde(rename = "predictive")]
1025 pub predictive: Option<String>,
1026
1027 #[serde(rename = "predictive.background")]
1028 pub predictive_background: Option<String>,
1029
1030 #[serde(rename = "predictive.border")]
1031 pub predictive_border: Option<String>,
1032
1033 /// Represents a renamed status, such as a file that has been renamed.
1034 #[serde(rename = "renamed")]
1035 pub renamed: Option<String>,
1036
1037 #[serde(rename = "renamed.background")]
1038 pub renamed_background: Option<String>,
1039
1040 #[serde(rename = "renamed.border")]
1041 pub renamed_border: Option<String>,
1042
1043 /// Indicates a successful operation or task completion.
1044 #[serde(rename = "success")]
1045 pub success: Option<String>,
1046
1047 #[serde(rename = "success.background")]
1048 pub success_background: Option<String>,
1049
1050 #[serde(rename = "success.border")]
1051 pub success_border: Option<String>,
1052
1053 /// Indicates some kind of unreachable status, like a block of code that can never be reached.
1054 #[serde(rename = "unreachable")]
1055 pub unreachable: Option<String>,
1056
1057 #[serde(rename = "unreachable.background")]
1058 pub unreachable_background: Option<String>,
1059
1060 #[serde(rename = "unreachable.border")]
1061 pub unreachable_border: Option<String>,
1062
1063 /// Represents a warning status, like an operation that is about to fail.
1064 #[serde(rename = "warning")]
1065 pub warning: Option<String>,
1066
1067 #[serde(rename = "warning.background")]
1068 pub warning_background: Option<String>,
1069
1070 #[serde(rename = "warning.border")]
1071 pub warning_border: Option<String>,
1072}
1073
1074/// The background appearance of the window.
1075#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, JsonSchema, MergeFrom)]
1076#[serde(rename_all = "snake_case")]
1077pub enum WindowBackgroundContent {
1078 Opaque,
1079 Transparent,
1080 Blurred,
1081}
1082
1083impl Into<gpui::WindowBackgroundAppearance> for WindowBackgroundContent {
1084 fn into(self) -> gpui::WindowBackgroundAppearance {
1085 match self {
1086 WindowBackgroundContent::Opaque => gpui::WindowBackgroundAppearance::Opaque,
1087 WindowBackgroundContent::Transparent => gpui::WindowBackgroundAppearance::Transparent,
1088 WindowBackgroundContent::Blurred => gpui::WindowBackgroundAppearance::Blurred,
1089 }
1090 }
1091}
1092
1093#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]
1094#[serde(rename_all = "snake_case")]
1095pub enum FontStyleContent {
1096 Normal,
1097 Italic,
1098 Oblique,
1099}
1100
1101impl From<FontStyleContent> for FontStyle {
1102 fn from(value: FontStyleContent) -> Self {
1103 match value {
1104 FontStyleContent::Normal => FontStyle::Normal,
1105 FontStyleContent::Italic => FontStyle::Italic,
1106 FontStyleContent::Oblique => FontStyle::Oblique,
1107 }
1108 }
1109}
1110
1111#[derive(
1112 Debug, Clone, Copy, Serialize_repr, Deserialize_repr, JsonSchema_repr, PartialEq, MergeFrom,
1113)]
1114#[repr(u16)]
1115pub enum FontWeightContent {
1116 Thin = 100,
1117 ExtraLight = 200,
1118 Light = 300,
1119 Normal = 400,
1120 Medium = 500,
1121 Semibold = 600,
1122 Bold = 700,
1123 ExtraBold = 800,
1124 Black = 900,
1125}
1126
1127impl From<FontWeightContent> for FontWeight {
1128 fn from(value: FontWeightContent) -> Self {
1129 match value {
1130 FontWeightContent::Thin => FontWeight::THIN,
1131 FontWeightContent::ExtraLight => FontWeight::EXTRA_LIGHT,
1132 FontWeightContent::Light => FontWeight::LIGHT,
1133 FontWeightContent::Normal => FontWeight::NORMAL,
1134 FontWeightContent::Medium => FontWeight::MEDIUM,
1135 FontWeightContent::Semibold => FontWeight::SEMIBOLD,
1136 FontWeightContent::Bold => FontWeight::BOLD,
1137 FontWeightContent::ExtraBold => FontWeight::EXTRA_BOLD,
1138 FontWeightContent::Black => FontWeight::BLACK,
1139 }
1140 }
1141}
1142
1143#[cfg(test)]
1144mod tests {
1145 use super::*;
1146 use serde_json::json;
1147
1148 #[test]
1149 fn test_buffer_line_height_deserialize_valid() {
1150 assert_eq!(
1151 serde_json::from_value::<BufferLineHeight>(json!("comfortable")).unwrap(),
1152 BufferLineHeight::Comfortable
1153 );
1154 assert_eq!(
1155 serde_json::from_value::<BufferLineHeight>(json!("standard")).unwrap(),
1156 BufferLineHeight::Standard
1157 );
1158 assert_eq!(
1159 serde_json::from_value::<BufferLineHeight>(json!({"custom": 1.0})).unwrap(),
1160 BufferLineHeight::Custom(1.0)
1161 );
1162 assert_eq!(
1163 serde_json::from_value::<BufferLineHeight>(json!({"custom": 1.5})).unwrap(),
1164 BufferLineHeight::Custom(1.5)
1165 );
1166 }
1167
1168 #[test]
1169 fn test_buffer_line_height_deserialize_invalid() {
1170 assert!(
1171 serde_json::from_value::<BufferLineHeight>(json!({"custom": 0.99}))
1172 .err()
1173 .unwrap()
1174 .to_string()
1175 .contains("buffer_line_height.custom must be at least 1.0")
1176 );
1177 assert!(
1178 serde_json::from_value::<BufferLineHeight>(json!({"custom": 0.0}))
1179 .err()
1180 .unwrap()
1181 .to_string()
1182 .contains("buffer_line_height.custom must be at least 1.0")
1183 );
1184 assert!(
1185 serde_json::from_value::<BufferLineHeight>(json!({"custom": -1.0}))
1186 .err()
1187 .unwrap()
1188 .to_string()
1189 .contains("buffer_line_height.custom must be at least 1.0")
1190 );
1191 }
1192
1193 #[test]
1194 fn test_buffer_font_weight_schema_has_default() {
1195 use schemars::schema_for;
1196
1197 let schema = schema_for!(ThemeSettingsContent);
1198 let schema_value = serde_json::to_value(&schema).unwrap();
1199
1200 let properties = &schema_value["properties"];
1201 let buffer_font_weight = &properties["buffer_font_weight"];
1202
1203 assert!(
1204 buffer_font_weight.get("default").is_some(),
1205 "buffer_font_weight should have a default value in the schema"
1206 );
1207
1208 let default_value = &buffer_font_weight["default"];
1209 assert_eq!(
1210 default_value.as_f64(),
1211 Some(FontWeight::NORMAL.0 as f64),
1212 "buffer_font_weight default should be 400.0 (FontWeight::NORMAL)"
1213 );
1214
1215 let defs = &schema_value["$defs"];
1216 let font_weight_def = &defs["FontWeight"];
1217
1218 assert_eq!(
1219 font_weight_def["minimum"].as_f64(),
1220 Some(FontWeight::THIN.0 as f64),
1221 "FontWeight should have minimum of 100.0"
1222 );
1223 assert_eq!(
1224 font_weight_def["maximum"].as_f64(),
1225 Some(FontWeight::BLACK.0 as f64),
1226 "FontWeight should have maximum of 900.0"
1227 );
1228 assert_eq!(
1229 font_weight_def["default"].as_f64(),
1230 Some(FontWeight::NORMAL.0 as f64),
1231 "FontWeight should have default of 400.0"
1232 );
1233 }
1234}