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