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