1use collections::{HashMap, IndexMap};
2use gpui::{FontFallbacks, FontFeatures, FontStyle, FontWeight};
3use schemars::{JsonSchema, JsonSchema_repr, json_schema};
4use serde::{Deserialize, Deserializer, Serialize};
5use serde_json::Value;
6use serde_repr::{Deserialize_repr, Serialize_repr};
7use std::sync::Arc;
8use util::schemars::replace_subschema;
9
10use crate::ParameterizedJsonSchema;
11
12/// Settings for rendering text in UI and text buffers.
13#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
14pub struct ThemeSettingsContent {
15 /// The default font size for text in the UI.
16 #[serde(default)]
17 pub ui_font_size: Option<f32>,
18 /// The name of a font to use for rendering in the UI.
19 #[serde(default)]
20 pub ui_font_family: Option<FontFamilyName>,
21 /// The font fallbacks to use for rendering in the UI.
22 #[serde(default)]
23 #[schemars(default = "default_font_fallbacks")]
24 #[schemars(extend("uniqueItems" = true))]
25 pub ui_font_fallbacks: Option<Vec<FontFamilyName>>,
26 /// The OpenType features to enable for text in the UI.
27 #[serde(default)]
28 #[schemars(default = "default_font_features")]
29 pub ui_font_features: Option<FontFeatures>,
30 /// The weight of the UI font in CSS units from 100 to 900.
31 #[serde(default)]
32 pub ui_font_weight: Option<f32>,
33 /// The name of a font to use for rendering in text buffers.
34 #[serde(default)]
35 pub buffer_font_family: Option<FontFamilyName>,
36 /// The font fallbacks to use for rendering in text buffers.
37 #[serde(default)]
38 #[schemars(extend("uniqueItems" = true))]
39 pub buffer_font_fallbacks: Option<Vec<FontFamilyName>>,
40 /// The default font size for rendering in text buffers.
41 #[serde(default)]
42 pub buffer_font_size: Option<f32>,
43 /// The weight of the editor font in CSS units from 100 to 900.
44 #[serde(default)]
45 pub buffer_font_weight: Option<f32>,
46 /// The buffer's line height.
47 #[serde(default)]
48 pub buffer_line_height: Option<BufferLineHeight>,
49 /// The OpenType features to enable for rendering in text buffers.
50 #[serde(default)]
51 #[schemars(default = "default_font_features")]
52 pub buffer_font_features: Option<FontFeatures>,
53 /// The font size for the agent panel. Falls back to the UI font size if unset.
54 #[serde(default)]
55 pub agent_font_size: Option<Option<f32>>,
56 /// The name of the Zed theme to use.
57 #[serde(default)]
58 pub theme: Option<ThemeSelection>,
59 /// The name of the icon theme to use.
60 #[serde(default)]
61 pub icon_theme: Option<IconThemeSelection>,
62
63 /// UNSTABLE: Expect many elements to be broken.
64 ///
65 // Controls the density of the UI.
66 #[serde(rename = "unstable.ui_density", default)]
67 pub ui_density: Option<UiDensity>,
68
69 /// How much to fade out unused code.
70 #[serde(default)]
71 pub unnecessary_code_fade: Option<f32>,
72
73 /// EXPERIMENTAL: Overrides for the current theme.
74 ///
75 /// These values will override the ones on the current theme specified in `theme`.
76 #[serde(rename = "experimental.theme_overrides", default)]
77 pub experimental_theme_overrides: Option<ThemeStyleContent>,
78
79 /// Overrides per theme
80 ///
81 /// These values will override the ones on the specified theme
82 #[serde(default)]
83 pub theme_overrides: HashMap<String, ThemeStyleContent>,
84}
85
86fn default_font_features() -> Option<FontFeatures> {
87 Some(FontFeatures::default())
88}
89
90fn default_font_fallbacks() -> Option<FontFallbacks> {
91 Some(FontFallbacks::default())
92}
93
94/// Represents the selection of a theme, which can be either static or dynamic.
95#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
96#[serde(untagged)]
97pub enum ThemeSelection {
98 /// A static theme selection, represented by a single theme name.
99 Static(ThemeName),
100 /// A dynamic theme selection, which can change based the [ThemeMode].
101 Dynamic {
102 /// The mode used to determine which theme to use.
103 #[serde(default)]
104 mode: ThemeMode,
105 /// The theme to use for light mode.
106 light: ThemeName,
107 /// The theme to use for dark mode.
108 dark: ThemeName,
109 },
110}
111
112/// Represents the selection of an icon theme, which can be either static or dynamic.
113#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
114#[serde(untagged)]
115pub enum IconThemeSelection {
116 /// A static icon theme selection, represented by a single icon theme name.
117 Static(IconThemeName),
118 /// A dynamic icon theme selection, which can change based on the [`ThemeMode`].
119 Dynamic {
120 /// The mode used to determine which theme to use.
121 #[serde(default)]
122 mode: ThemeMode,
123 /// The icon theme to use for light mode.
124 light: IconThemeName,
125 /// The icon theme to use for dark mode.
126 dark: IconThemeName,
127 },
128}
129
130// TODO: Rename ThemeMode -> ThemeAppearanceMode
131/// The mode use to select a theme.
132///
133/// `Light` and `Dark` will select their respective themes.
134///
135/// `System` will select the theme based on the system's appearance.
136#[derive(Debug, PartialEq, Eq, Clone, Copy, Default, Serialize, Deserialize, JsonSchema)]
137#[serde(rename_all = "snake_case")]
138pub enum ThemeMode {
139 /// Use the specified `light` theme.
140 Light,
141
142 /// Use the specified `dark` theme.
143 Dark,
144
145 /// Use the theme based on the system's appearance.
146 #[default]
147 System,
148}
149
150/// Specifies the density of the UI.
151/// Note: This setting is still experimental. See [this tracking issue](https://github.com/zed-industries/zed/issues/18078)
152#[derive(
153 Debug,
154 Default,
155 PartialEq,
156 Eq,
157 PartialOrd,
158 Ord,
159 Hash,
160 Clone,
161 Copy,
162 Serialize,
163 Deserialize,
164 JsonSchema,
165)]
166#[serde(rename_all = "snake_case")]
167pub enum UiDensity {
168 /// A denser UI with tighter spacing and smaller elements.
169 #[serde(alias = "compact")]
170 Compact,
171 #[default]
172 #[serde(alias = "default")]
173 /// The default UI density.
174 Default,
175 #[serde(alias = "comfortable")]
176 /// A looser UI with more spacing and larger elements.
177 Comfortable,
178}
179
180impl UiDensity {
181 /// The spacing ratio of a given density.
182 /// TODO: Standardize usage throughout the app or remove
183 pub fn spacing_ratio(self) -> f32 {
184 match self {
185 UiDensity::Compact => 0.75,
186 UiDensity::Default => 1.0,
187 UiDensity::Comfortable => 1.25,
188 }
189 }
190}
191
192/// Newtype for font family name. Its `ParameterizedJsonSchema` lists the font families known at
193/// runtime.
194#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
195#[serde(transparent)]
196pub struct FontFamilyName(pub Arc<str>);
197
198inventory::submit! {
199 ParameterizedJsonSchema {
200 add_and_get_ref: |generator, params, _cx| {
201 replace_subschema::<FontFamilyName>(generator, || {
202 json_schema!({
203 "type": "string",
204 "enum": params.font_names,
205 })
206 })
207 }
208 }
209}
210
211/// The buffer's line height.
212#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, JsonSchema, Default)]
213#[serde(rename_all = "snake_case")]
214pub enum BufferLineHeight {
215 /// A less dense line height.
216 #[default]
217 Comfortable,
218 /// The default line height.
219 Standard,
220 /// A custom line height, where 1.0 is the font's height. Must be at least 1.0.
221 Custom(#[serde(deserialize_with = "deserialize_line_height")] f32),
222}
223
224fn deserialize_line_height<'de, D>(deserializer: D) -> Result<f32, D::Error>
225where
226 D: serde::Deserializer<'de>,
227{
228 let value = f32::deserialize(deserializer)?;
229 if value < 1.0 {
230 return Err(serde::de::Error::custom(
231 "buffer_line_height.custom must be at least 1.0",
232 ));
233 }
234
235 Ok(value)
236}
237
238/// The content of a serialized theme.
239#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
240#[serde(default)]
241pub struct ThemeStyleContent {
242 #[serde(default, rename = "background.appearance")]
243 pub window_background_appearance: Option<WindowBackgroundContent>,
244
245 #[serde(default)]
246 pub accents: Vec<AccentContent>,
247
248 #[serde(flatten, default)]
249 pub colors: ThemeColorsContent,
250
251 #[serde(flatten, default)]
252 pub status: StatusColorsContent,
253
254 #[serde(default)]
255 pub players: Vec<PlayerColorContent>,
256
257 /// The styles for syntax nodes.
258 #[serde(default)]
259 pub syntax: IndexMap<String, HighlightStyleContent>,
260}
261
262#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
263pub struct AccentContent(pub Option<String>);
264
265#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
266pub struct PlayerColorContent {
267 pub cursor: Option<String>,
268 pub background: Option<String>,
269 pub selection: Option<String>,
270}
271
272/// Newtype for a theme name. Its `ParameterizedJsonSchema` lists the theme names known at runtime.
273#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
274#[serde(transparent)]
275pub struct ThemeName(pub Arc<str>);
276
277inventory::submit! {
278 ParameterizedJsonSchema {
279 add_and_get_ref: |generator, _params, cx| {
280 todo!()
281 // replace_subschema::<ThemeName>(generator, || json_schema!({
282 // "type": "string",
283 // "enum": ThemeRegistry::global(cx).list_names(),
284 // }))
285 }
286 }
287}
288
289/// Newtype for a icon theme name. Its `ParameterizedJsonSchema` lists the icon theme names known at
290/// runtime.
291#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
292#[serde(transparent)]
293pub struct IconThemeName(pub Arc<str>);
294
295inventory::submit! {
296 ParameterizedJsonSchema {
297 add_and_get_ref: |generator, _params, cx| {
298 todo!()
299 // replace_subschema::<IconThemeName>(generator, || json_schema!({
300 // "type": "string",
301 // "enum": ThemeRegistry::global(cx)
302 // .list_icon_themes()
303 // .into_iter()
304 // .map(|icon_theme| icon_theme.name)
305 // .collect::<Vec<SharedString>>(),
306 // }))
307 }
308 }
309}
310
311#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, 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#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
816#[serde(default)]
817pub struct HighlightStyleContent {
818 pub color: Option<String>,
819
820 #[serde(deserialize_with = "treat_error_as_none")]
821 pub background_color: Option<String>,
822
823 #[serde(deserialize_with = "treat_error_as_none")]
824 pub font_style: Option<FontStyleContent>,
825
826 #[serde(deserialize_with = "treat_error_as_none")]
827 pub font_weight: Option<FontWeightContent>,
828}
829
830impl HighlightStyleContent {
831 pub fn is_empty(&self) -> bool {
832 self.color.is_none()
833 && self.background_color.is_none()
834 && self.font_style.is_none()
835 && self.font_weight.is_none()
836 }
837}
838
839fn treat_error_as_none<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
840where
841 T: Deserialize<'de>,
842 D: Deserializer<'de>,
843{
844 let value: Value = Deserialize::deserialize(deserializer)?;
845 Ok(T::deserialize(value).ok())
846}
847
848#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
849#[serde(default)]
850pub struct StatusColorsContent {
851 /// Indicates some kind of conflict, like a file changed on disk while it was open, or
852 /// merge conflicts in a Git repository.
853 #[serde(rename = "conflict")]
854 pub conflict: Option<String>,
855
856 #[serde(rename = "conflict.background")]
857 pub conflict_background: Option<String>,
858
859 #[serde(rename = "conflict.border")]
860 pub conflict_border: Option<String>,
861
862 /// Indicates something new, like a new file added to a Git repository.
863 #[serde(rename = "created")]
864 pub created: Option<String>,
865
866 #[serde(rename = "created.background")]
867 pub created_background: Option<String>,
868
869 #[serde(rename = "created.border")]
870 pub created_border: Option<String>,
871
872 /// Indicates that something no longer exists, like a deleted file.
873 #[serde(rename = "deleted")]
874 pub deleted: Option<String>,
875
876 #[serde(rename = "deleted.background")]
877 pub deleted_background: Option<String>,
878
879 #[serde(rename = "deleted.border")]
880 pub deleted_border: Option<String>,
881
882 /// Indicates a system error, a failed operation or a diagnostic error.
883 #[serde(rename = "error")]
884 pub error: Option<String>,
885
886 #[serde(rename = "error.background")]
887 pub error_background: Option<String>,
888
889 #[serde(rename = "error.border")]
890 pub error_border: Option<String>,
891
892 /// Represents a hidden status, such as a file being hidden in a file tree.
893 #[serde(rename = "hidden")]
894 pub hidden: Option<String>,
895
896 #[serde(rename = "hidden.background")]
897 pub hidden_background: Option<String>,
898
899 #[serde(rename = "hidden.border")]
900 pub hidden_border: Option<String>,
901
902 /// Indicates a hint or some kind of additional information.
903 #[serde(rename = "hint")]
904 pub hint: Option<String>,
905
906 #[serde(rename = "hint.background")]
907 pub hint_background: Option<String>,
908
909 #[serde(rename = "hint.border")]
910 pub hint_border: Option<String>,
911
912 /// Indicates that something is deliberately ignored, such as a file or operation ignored by Git.
913 #[serde(rename = "ignored")]
914 pub ignored: Option<String>,
915
916 #[serde(rename = "ignored.background")]
917 pub ignored_background: Option<String>,
918
919 #[serde(rename = "ignored.border")]
920 pub ignored_border: Option<String>,
921
922 /// Represents informational status updates or messages.
923 #[serde(rename = "info")]
924 pub info: Option<String>,
925
926 #[serde(rename = "info.background")]
927 pub info_background: Option<String>,
928
929 #[serde(rename = "info.border")]
930 pub info_border: Option<String>,
931
932 /// Indicates a changed or altered status, like a file that has been edited.
933 #[serde(rename = "modified")]
934 pub modified: Option<String>,
935
936 #[serde(rename = "modified.background")]
937 pub modified_background: Option<String>,
938
939 #[serde(rename = "modified.border")]
940 pub modified_border: Option<String>,
941
942 /// Indicates something that is predicted, like automatic code completion, or generated code.
943 #[serde(rename = "predictive")]
944 pub predictive: Option<String>,
945
946 #[serde(rename = "predictive.background")]
947 pub predictive_background: Option<String>,
948
949 #[serde(rename = "predictive.border")]
950 pub predictive_border: Option<String>,
951
952 /// Represents a renamed status, such as a file that has been renamed.
953 #[serde(rename = "renamed")]
954 pub renamed: Option<String>,
955
956 #[serde(rename = "renamed.background")]
957 pub renamed_background: Option<String>,
958
959 #[serde(rename = "renamed.border")]
960 pub renamed_border: Option<String>,
961
962 /// Indicates a successful operation or task completion.
963 #[serde(rename = "success")]
964 pub success: Option<String>,
965
966 #[serde(rename = "success.background")]
967 pub success_background: Option<String>,
968
969 #[serde(rename = "success.border")]
970 pub success_border: Option<String>,
971
972 /// Indicates some kind of unreachable status, like a block of code that can never be reached.
973 #[serde(rename = "unreachable")]
974 pub unreachable: Option<String>,
975
976 #[serde(rename = "unreachable.background")]
977 pub unreachable_background: Option<String>,
978
979 #[serde(rename = "unreachable.border")]
980 pub unreachable_border: Option<String>,
981
982 /// Represents a warning status, like an operation that is about to fail.
983 #[serde(rename = "warning")]
984 pub warning: Option<String>,
985
986 #[serde(rename = "warning.background")]
987 pub warning_background: Option<String>,
988
989 #[serde(rename = "warning.border")]
990 pub warning_border: Option<String>,
991}
992
993/// The background appearance of the window.
994#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
995#[serde(rename_all = "snake_case")]
996pub enum WindowBackgroundContent {
997 Opaque,
998 Transparent,
999 Blurred,
1000}
1001
1002impl Into<gpui::WindowBackgroundAppearance> for WindowBackgroundContent {
1003 fn into(self) -> gpui::WindowBackgroundAppearance {
1004 match self {
1005 WindowBackgroundContent::Opaque => gpui::WindowBackgroundAppearance::Opaque,
1006 WindowBackgroundContent::Transparent => gpui::WindowBackgroundAppearance::Transparent,
1007 WindowBackgroundContent::Blurred => gpui::WindowBackgroundAppearance::Blurred,
1008 }
1009 }
1010}
1011
1012#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq)]
1013#[serde(rename_all = "snake_case")]
1014pub enum FontStyleContent {
1015 Normal,
1016 Italic,
1017 Oblique,
1018}
1019
1020impl From<FontStyleContent> for FontStyle {
1021 fn from(value: FontStyleContent) -> Self {
1022 match value {
1023 FontStyleContent::Normal => FontStyle::Normal,
1024 FontStyleContent::Italic => FontStyle::Italic,
1025 FontStyleContent::Oblique => FontStyle::Oblique,
1026 }
1027 }
1028}
1029
1030#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, JsonSchema_repr, PartialEq)]
1031#[repr(u16)]
1032pub enum FontWeightContent {
1033 Thin = 100,
1034 ExtraLight = 200,
1035 Light = 300,
1036 Normal = 400,
1037 Medium = 500,
1038 Semibold = 600,
1039 Bold = 700,
1040 ExtraBold = 800,
1041 Black = 900,
1042}
1043
1044impl From<FontWeightContent> for FontWeight {
1045 fn from(value: FontWeightContent) -> Self {
1046 match value {
1047 FontWeightContent::Thin => FontWeight::THIN,
1048 FontWeightContent::ExtraLight => FontWeight::EXTRA_LIGHT,
1049 FontWeightContent::Light => FontWeight::LIGHT,
1050 FontWeightContent::Normal => FontWeight::NORMAL,
1051 FontWeightContent::Medium => FontWeight::MEDIUM,
1052 FontWeightContent::Semibold => FontWeight::SEMIBOLD,
1053 FontWeightContent::Bold => FontWeight::BOLD,
1054 FontWeightContent::ExtraBold => FontWeight::EXTRA_BOLD,
1055 FontWeightContent::Black => FontWeight::BLACK,
1056 }
1057 }
1058}
1059
1060#[cfg(test)]
1061mod tests {
1062 use super::*;
1063 use serde_json::json;
1064
1065 #[test]
1066 fn test_buffer_line_height_deserialize_valid() {
1067 assert_eq!(
1068 serde_json::from_value::<BufferLineHeight>(json!("comfortable")).unwrap(),
1069 BufferLineHeight::Comfortable
1070 );
1071 assert_eq!(
1072 serde_json::from_value::<BufferLineHeight>(json!("standard")).unwrap(),
1073 BufferLineHeight::Standard
1074 );
1075 assert_eq!(
1076 serde_json::from_value::<BufferLineHeight>(json!({"custom": 1.0})).unwrap(),
1077 BufferLineHeight::Custom(1.0)
1078 );
1079 assert_eq!(
1080 serde_json::from_value::<BufferLineHeight>(json!({"custom": 1.5})).unwrap(),
1081 BufferLineHeight::Custom(1.5)
1082 );
1083 }
1084
1085 #[test]
1086 fn test_buffer_line_height_deserialize_invalid() {
1087 assert!(
1088 serde_json::from_value::<BufferLineHeight>(json!({"custom": 0.99}))
1089 .err()
1090 .unwrap()
1091 .to_string()
1092 .contains("buffer_line_height.custom must be at least 1.0")
1093 );
1094 assert!(
1095 serde_json::from_value::<BufferLineHeight>(json!({"custom": 0.0}))
1096 .err()
1097 .unwrap()
1098 .to_string()
1099 .contains("buffer_line_height.custom must be at least 1.0")
1100 );
1101 assert!(
1102 serde_json::from_value::<BufferLineHeight>(json!({"custom": -1.0}))
1103 .err()
1104 .unwrap()
1105 .to_string()
1106 .contains("buffer_line_height.custom must be at least 1.0")
1107 );
1108 }
1109}