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