theme.rs

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