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