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