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