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