schema.rs

   1use anyhow::Result;
   2use gpui::{FontStyle, FontWeight, HighlightStyle, Hsla, WindowBackgroundAppearance};
   3use indexmap::IndexMap;
   4use palette::FromColor;
   5use schemars::gen::SchemaGenerator;
   6use schemars::schema::{Schema, SchemaObject};
   7use schemars::JsonSchema;
   8use serde::{Deserialize, Deserializer, Serialize};
   9use serde_json::Value;
  10use serde_repr::{Deserialize_repr, Serialize_repr};
  11
  12use crate::{StatusColorsRefinement, ThemeColorsRefinement};
  13
  14pub(crate) fn try_parse_color(color: &str) -> Result<Hsla> {
  15    let rgba = gpui::Rgba::try_from(color)?;
  16    let rgba = palette::rgb::Srgba::from_components((rgba.r, rgba.g, rgba.b, rgba.a));
  17    let hsla = palette::Hsla::from_color(rgba);
  18
  19    let hsla = gpui::hsla(
  20        hsla.hue.into_positive_degrees() / 360.,
  21        hsla.saturation,
  22        hsla.lightness,
  23        hsla.alpha,
  24    );
  25
  26    Ok(hsla)
  27}
  28
  29#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
  30#[serde(rename_all = "snake_case")]
  31pub enum AppearanceContent {
  32    Light,
  33    Dark,
  34}
  35
  36/// The background appearance of the window.
  37#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
  38#[serde(rename_all = "snake_case")]
  39pub enum WindowBackgroundContent {
  40    Opaque,
  41    Transparent,
  42    Blurred,
  43}
  44
  45impl From<WindowBackgroundContent> for WindowBackgroundAppearance {
  46    fn from(value: WindowBackgroundContent) -> Self {
  47        match value {
  48            WindowBackgroundContent::Opaque => WindowBackgroundAppearance::Opaque,
  49            WindowBackgroundContent::Transparent => WindowBackgroundAppearance::Transparent,
  50            WindowBackgroundContent::Blurred => WindowBackgroundAppearance::Blurred,
  51        }
  52    }
  53}
  54
  55/// The content of a serialized theme family.
  56#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
  57pub struct ThemeFamilyContent {
  58    pub name: String,
  59    pub author: String,
  60    pub themes: Vec<ThemeContent>,
  61}
  62
  63/// The content of a serialized theme.
  64#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
  65pub struct ThemeContent {
  66    pub name: String,
  67    pub appearance: AppearanceContent,
  68    pub style: ThemeStyleContent,
  69}
  70
  71/// The content of a serialized theme.
  72#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
  73#[serde(default)]
  74pub struct ThemeStyleContent {
  75    #[serde(default, rename = "background.appearance")]
  76    pub window_background_appearance: Option<WindowBackgroundContent>,
  77
  78    #[serde(default)]
  79    pub accents: Vec<AccentContent>,
  80
  81    #[serde(flatten, default)]
  82    pub colors: ThemeColorsContent,
  83
  84    #[serde(flatten, default)]
  85    pub status: StatusColorsContent,
  86
  87    #[serde(default)]
  88    pub players: Vec<PlayerColorContent>,
  89
  90    /// The styles for syntax nodes.
  91    #[serde(default)]
  92    pub syntax: IndexMap<String, HighlightStyleContent>,
  93}
  94
  95impl ThemeStyleContent {
  96    /// Returns a [`ThemeColorsRefinement`] based on the colors in the [`ThemeContent`].
  97    #[inline(always)]
  98    pub fn theme_colors_refinement(&self) -> ThemeColorsRefinement {
  99        self.colors.theme_colors_refinement()
 100    }
 101
 102    /// Returns a [`StatusColorsRefinement`] based on the colors in the [`ThemeContent`].
 103    #[inline(always)]
 104    pub fn status_colors_refinement(&self) -> StatusColorsRefinement {
 105        self.status.status_colors_refinement()
 106    }
 107
 108    /// Returns the syntax style overrides in the [`ThemeContent`].
 109    pub fn syntax_overrides(&self) -> Vec<(String, HighlightStyle)> {
 110        self.syntax
 111            .iter()
 112            .map(|(key, style)| {
 113                (
 114                    key.clone(),
 115                    HighlightStyle {
 116                        color: style
 117                            .color
 118                            .as_ref()
 119                            .and_then(|color| try_parse_color(color).ok()),
 120                        background_color: style
 121                            .background_color
 122                            .as_ref()
 123                            .and_then(|color| try_parse_color(color).ok()),
 124                        font_style: style.font_style.map(FontStyle::from),
 125                        font_weight: style.font_weight.map(FontWeight::from),
 126                        ..Default::default()
 127                    },
 128                )
 129            })
 130            .collect()
 131    }
 132}
 133
 134#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
 135#[serde(default)]
 136pub struct ThemeColorsContent {
 137    /// Border color. Used for most borders, is usually a high contrast color.
 138    #[serde(rename = "border")]
 139    pub border: Option<String>,
 140
 141    /// Border color. Used for deemphasized borders, like a visual divider between two sections
 142    #[serde(rename = "border.variant")]
 143    pub border_variant: Option<String>,
 144
 145    /// Border color. Used for focused elements, like keyboard focused list item.
 146    #[serde(rename = "border.focused")]
 147    pub border_focused: Option<String>,
 148
 149    /// Border color. Used for selected elements, like an active search filter or selected checkbox.
 150    #[serde(rename = "border.selected")]
 151    pub border_selected: Option<String>,
 152
 153    /// Border color. Used for transparent borders. Used for placeholder borders when an element gains a border on state change.
 154    #[serde(rename = "border.transparent")]
 155    pub border_transparent: Option<String>,
 156
 157    /// Border color. Used for disabled elements, like a disabled input or button.
 158    #[serde(rename = "border.disabled")]
 159    pub border_disabled: Option<String>,
 160
 161    /// Background color. Used for elevated surfaces, like a context menu, popup, or dialog.
 162    #[serde(rename = "elevated_surface.background")]
 163    pub elevated_surface_background: Option<String>,
 164
 165    /// Background Color. Used for grounded surfaces like a panel or tab.
 166    #[serde(rename = "surface.background")]
 167    pub surface_background: Option<String>,
 168
 169    /// Background Color. Used for the app background and blank panels or windows.
 170    #[serde(rename = "background")]
 171    pub background: Option<String>,
 172
 173    /// Background Color. Used for the background of an element that should have a different background than the surface it's on.
 174    ///
 175    /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons...
 176    ///
 177    /// For an element that should have the same background as the surface it's on, use `ghost_element_background`.
 178    #[serde(rename = "element.background")]
 179    pub element_background: Option<String>,
 180
 181    /// Background Color. Used for the hover state of an element that should have a different background than the surface it's on.
 182    ///
 183    /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen.
 184    #[serde(rename = "element.hover")]
 185    pub element_hover: Option<String>,
 186
 187    /// Background Color. Used for the active state of an element that should have a different background than the surface it's on.
 188    ///
 189    /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd.
 190    #[serde(rename = "element.active")]
 191    pub element_active: Option<String>,
 192
 193    /// Background Color. Used for the selected state of an element that should have a different background than the surface it's on.
 194    ///
 195    /// Selected states are triggered by the element being selected (or "activated") by the user.
 196    ///
 197    /// This could include a selected checkbox, a toggleable button that is toggled on, etc.
 198    #[serde(rename = "element.selected")]
 199    pub element_selected: Option<String>,
 200
 201    /// Background Color. Used for the disabled state of an element that should have a different background than the surface it's on.
 202    ///
 203    /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input.
 204    #[serde(rename = "element.disabled")]
 205    pub element_disabled: Option<String>,
 206
 207    /// Background Color. Used for the area that shows where a dragged element will be dropped.
 208    #[serde(rename = "drop_target.background")]
 209    pub drop_target_background: Option<String>,
 210
 211    /// Used for the background of a ghost element that should have the same background as the surface it's on.
 212    ///
 213    /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons...
 214    ///
 215    /// For an element that should have a different background than the surface it's on, use `element_background`.
 216    #[serde(rename = "ghost_element.background")]
 217    pub ghost_element_background: Option<String>,
 218
 219    /// Background Color. Used for the hover state of a ghost element that should have the same background as the surface it's on.
 220    ///
 221    /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen.
 222    #[serde(rename = "ghost_element.hover")]
 223    pub ghost_element_hover: Option<String>,
 224
 225    /// Background Color. Used for the active state of a ghost element that should have the same background as the surface it's on.
 226    ///
 227    /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd.
 228    #[serde(rename = "ghost_element.active")]
 229    pub ghost_element_active: Option<String>,
 230
 231    /// Background Color. Used for the selected state of a ghost element that should have the same background as the surface it's on.
 232    ///
 233    /// Selected states are triggered by the element being selected (or "activated") by the user.
 234    ///
 235    /// This could include a selected checkbox, a toggleable button that is toggled on, etc.
 236    #[serde(rename = "ghost_element.selected")]
 237    pub ghost_element_selected: Option<String>,
 238
 239    /// Background Color. Used for the disabled state of a ghost element that should have the same background as the surface it's on.
 240    ///
 241    /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input.
 242    #[serde(rename = "ghost_element.disabled")]
 243    pub ghost_element_disabled: Option<String>,
 244
 245    /// Text Color. Default text color used for most text.
 246    #[serde(rename = "text")]
 247    pub text: Option<String>,
 248
 249    /// Text Color. Color of muted or deemphasized text. It is a subdued version of the standard text color.
 250    #[serde(rename = "text.muted")]
 251    pub text_muted: Option<String>,
 252
 253    /// Text Color. Color of the placeholder text typically shown in input fields to guide the user to enter valid data.
 254    #[serde(rename = "text.placeholder")]
 255    pub text_placeholder: Option<String>,
 256
 257    /// Text Color. Color used for text denoting disabled elements. Typically, the color is faded or grayed out to emphasize the disabled state.
 258    #[serde(rename = "text.disabled")]
 259    pub text_disabled: Option<String>,
 260
 261    /// Text Color. Color used for emphasis or highlighting certain text, like an active filter or a matched character in a search.
 262    #[serde(rename = "text.accent")]
 263    pub text_accent: Option<String>,
 264
 265    /// Fill Color. Used for the default fill color of an icon.
 266    #[serde(rename = "icon")]
 267    pub icon: Option<String>,
 268
 269    /// Fill Color. Used for the muted or deemphasized fill color of an icon.
 270    ///
 271    /// This might be used to show an icon in an inactive pane, or to demphasize a series of icons to give them less visual weight.
 272    #[serde(rename = "icon.muted")]
 273    pub icon_muted: Option<String>,
 274
 275    /// Fill Color. Used for the disabled fill color of an icon.
 276    ///
 277    /// Disabled states are shown when a user cannot interact with an element, like a icon button.
 278    #[serde(rename = "icon.disabled")]
 279    pub icon_disabled: Option<String>,
 280
 281    /// Fill Color. Used for the placeholder fill color of an icon.
 282    ///
 283    /// This might be used to show an icon in an input that disappears when the user enters text.
 284    #[serde(rename = "icon.placeholder")]
 285    pub icon_placeholder: Option<String>,
 286
 287    /// Fill Color. Used for the accent fill color of an icon.
 288    ///
 289    /// This might be used to show when a toggleable icon button is selected.
 290    #[serde(rename = "icon.accent")]
 291    pub icon_accent: Option<String>,
 292
 293    #[serde(rename = "status_bar.background")]
 294    pub status_bar_background: Option<String>,
 295
 296    #[serde(rename = "title_bar.background")]
 297    pub title_bar_background: Option<String>,
 298
 299    #[serde(rename = "title_bar.inactive_background")]
 300    pub title_bar_inactive_background: Option<String>,
 301
 302    #[serde(rename = "toolbar.background")]
 303    pub toolbar_background: Option<String>,
 304
 305    #[serde(rename = "tab_bar.background")]
 306    pub tab_bar_background: Option<String>,
 307
 308    #[serde(rename = "tab.inactive_background")]
 309    pub tab_inactive_background: Option<String>,
 310
 311    #[serde(rename = "tab.active_background")]
 312    pub tab_active_background: Option<String>,
 313
 314    #[serde(rename = "search.match_background")]
 315    pub search_match_background: Option<String>,
 316
 317    #[serde(rename = "panel.background")]
 318    pub panel_background: Option<String>,
 319
 320    #[serde(rename = "panel.focused_border")]
 321    pub panel_focused_border: Option<String>,
 322
 323    #[serde(rename = "pane.focused_border")]
 324    pub pane_focused_border: Option<String>,
 325
 326    #[serde(rename = "pane_group.border")]
 327    pub pane_group_border: Option<String>,
 328
 329    /// The deprecated version of `scrollbar.thumb.background`.
 330    ///
 331    /// Don't use this field.
 332    #[serde(rename = "scrollbar_thumb.background", skip_serializing)]
 333    #[schemars(skip)]
 334    pub deprecated_scrollbar_thumb_background: Option<String>,
 335
 336    /// The color of the scrollbar thumb.
 337    #[serde(rename = "scrollbar.thumb.background")]
 338    pub scrollbar_thumb_background: Option<String>,
 339
 340    /// The color of the scrollbar thumb when hovered over.
 341    #[serde(rename = "scrollbar.thumb.hover_background")]
 342    pub scrollbar_thumb_hover_background: Option<String>,
 343
 344    /// The border color of the scrollbar thumb.
 345    #[serde(rename = "scrollbar.thumb.border")]
 346    pub scrollbar_thumb_border: Option<String>,
 347
 348    /// The background color of the scrollbar track.
 349    #[serde(rename = "scrollbar.track.background")]
 350    pub scrollbar_track_background: Option<String>,
 351
 352    /// The border color of the scrollbar track.
 353    #[serde(rename = "scrollbar.track.border")]
 354    pub scrollbar_track_border: Option<String>,
 355
 356    #[serde(rename = "editor.foreground")]
 357    pub editor_foreground: Option<String>,
 358
 359    #[serde(rename = "editor.background")]
 360    pub editor_background: Option<String>,
 361
 362    #[serde(rename = "editor.gutter.background")]
 363    pub editor_gutter_background: Option<String>,
 364
 365    #[serde(rename = "editor.subheader.background")]
 366    pub editor_subheader_background: Option<String>,
 367
 368    #[serde(rename = "editor.active_line.background")]
 369    pub editor_active_line_background: Option<String>,
 370
 371    #[serde(rename = "editor.highlighted_line.background")]
 372    pub editor_highlighted_line_background: Option<String>,
 373
 374    /// Text Color. Used for the text of the line number in the editor gutter.
 375    #[serde(rename = "editor.line_number")]
 376    pub editor_line_number: Option<String>,
 377
 378    /// Text Color. Used for the text of the line number in the editor gutter when the line is highlighted.
 379    #[serde(rename = "editor.active_line_number")]
 380    pub editor_active_line_number: Option<String>,
 381
 382    /// Text Color. Used to mark invisible characters in the editor.
 383    ///
 384    /// Example: spaces, tabs, carriage returns, etc.
 385    #[serde(rename = "editor.invisible")]
 386    pub editor_invisible: Option<String>,
 387
 388    #[serde(rename = "editor.wrap_guide")]
 389    pub editor_wrap_guide: Option<String>,
 390
 391    #[serde(rename = "editor.active_wrap_guide")]
 392    pub editor_active_wrap_guide: Option<String>,
 393
 394    #[serde(rename = "editor.indent_guide")]
 395    pub editor_indent_guide: Option<String>,
 396
 397    #[serde(rename = "editor.indent_guide_active")]
 398    pub editor_indent_guide_active: Option<String>,
 399
 400    /// Read-access of a symbol, like reading a variable.
 401    ///
 402    /// A document highlight is a range inside a text document which deserves
 403    /// special attention. Usually a document highlight is visualized by changing
 404    /// the background color of its range.
 405    #[serde(rename = "editor.document_highlight.read_background")]
 406    pub editor_document_highlight_read_background: Option<String>,
 407
 408    /// Read-access of a symbol, like reading a variable.
 409    ///
 410    /// A document highlight is a range inside a text document which deserves
 411    /// special attention. Usually a document highlight is visualized by changing
 412    /// the background color of its range.
 413    #[serde(rename = "editor.document_highlight.write_background")]
 414    pub editor_document_highlight_write_background: Option<String>,
 415
 416    /// Highlighted brackets background color.
 417    ///
 418    /// Matching brackets in the cursor scope are highlighted with this background color.
 419    #[serde(rename = "editor.document_highlight.bracket_background")]
 420    pub editor_document_highlight_bracket_background: Option<String>,
 421
 422    /// Terminal background color.
 423    #[serde(rename = "terminal.background")]
 424    pub terminal_background: Option<String>,
 425
 426    /// Terminal foreground color.
 427    #[serde(rename = "terminal.foreground")]
 428    pub terminal_foreground: Option<String>,
 429
 430    /// Terminal ANSI background color.
 431    #[serde(rename = "terminal.ansi.background")]
 432    pub terminal_ansi_background: Option<String>,
 433
 434    /// Bright terminal foreground color.
 435    #[serde(rename = "terminal.bright_foreground")]
 436    pub terminal_bright_foreground: Option<String>,
 437
 438    /// Dim terminal foreground color.
 439    #[serde(rename = "terminal.dim_foreground")]
 440    pub terminal_dim_foreground: Option<String>,
 441
 442    /// Black ANSI terminal color.
 443    #[serde(rename = "terminal.ansi.black")]
 444    pub terminal_ansi_black: Option<String>,
 445
 446    /// Bright black ANSI terminal color.
 447    #[serde(rename = "terminal.ansi.bright_black")]
 448    pub terminal_ansi_bright_black: Option<String>,
 449
 450    /// Dim black ANSI terminal color.
 451    #[serde(rename = "terminal.ansi.dim_black")]
 452    pub terminal_ansi_dim_black: Option<String>,
 453
 454    /// Red ANSI terminal color.
 455    #[serde(rename = "terminal.ansi.red")]
 456    pub terminal_ansi_red: Option<String>,
 457
 458    /// Bright red ANSI terminal color.
 459    #[serde(rename = "terminal.ansi.bright_red")]
 460    pub terminal_ansi_bright_red: Option<String>,
 461
 462    /// Dim red ANSI terminal color.
 463    #[serde(rename = "terminal.ansi.dim_red")]
 464    pub terminal_ansi_dim_red: Option<String>,
 465
 466    /// Green ANSI terminal color.
 467    #[serde(rename = "terminal.ansi.green")]
 468    pub terminal_ansi_green: Option<String>,
 469
 470    /// Bright green ANSI terminal color.
 471    #[serde(rename = "terminal.ansi.bright_green")]
 472    pub terminal_ansi_bright_green: Option<String>,
 473
 474    /// Dim green ANSI terminal color.
 475    #[serde(rename = "terminal.ansi.dim_green")]
 476    pub terminal_ansi_dim_green: Option<String>,
 477
 478    /// Yellow ANSI terminal color.
 479    #[serde(rename = "terminal.ansi.yellow")]
 480    pub terminal_ansi_yellow: Option<String>,
 481
 482    /// Bright yellow ANSI terminal color.
 483    #[serde(rename = "terminal.ansi.bright_yellow")]
 484    pub terminal_ansi_bright_yellow: Option<String>,
 485
 486    /// Dim yellow ANSI terminal color.
 487    #[serde(rename = "terminal.ansi.dim_yellow")]
 488    pub terminal_ansi_dim_yellow: Option<String>,
 489
 490    /// Blue ANSI terminal color.
 491    #[serde(rename = "terminal.ansi.blue")]
 492    pub terminal_ansi_blue: Option<String>,
 493
 494    /// Bright blue ANSI terminal color.
 495    #[serde(rename = "terminal.ansi.bright_blue")]
 496    pub terminal_ansi_bright_blue: Option<String>,
 497
 498    /// Dim blue ANSI terminal color.
 499    #[serde(rename = "terminal.ansi.dim_blue")]
 500    pub terminal_ansi_dim_blue: Option<String>,
 501
 502    /// Magenta ANSI terminal color.
 503    #[serde(rename = "terminal.ansi.magenta")]
 504    pub terminal_ansi_magenta: Option<String>,
 505
 506    /// Bright magenta ANSI terminal color.
 507    #[serde(rename = "terminal.ansi.bright_magenta")]
 508    pub terminal_ansi_bright_magenta: Option<String>,
 509
 510    /// Dim magenta ANSI terminal color.
 511    #[serde(rename = "terminal.ansi.dim_magenta")]
 512    pub terminal_ansi_dim_magenta: Option<String>,
 513
 514    /// Cyan ANSI terminal color.
 515    #[serde(rename = "terminal.ansi.cyan")]
 516    pub terminal_ansi_cyan: Option<String>,
 517
 518    /// Bright cyan ANSI terminal color.
 519    #[serde(rename = "terminal.ansi.bright_cyan")]
 520    pub terminal_ansi_bright_cyan: Option<String>,
 521
 522    /// Dim cyan ANSI terminal color.
 523    #[serde(rename = "terminal.ansi.dim_cyan")]
 524    pub terminal_ansi_dim_cyan: Option<String>,
 525
 526    /// White ANSI terminal color.
 527    #[serde(rename = "terminal.ansi.white")]
 528    pub terminal_ansi_white: Option<String>,
 529
 530    /// Bright white ANSI terminal color.
 531    #[serde(rename = "terminal.ansi.bright_white")]
 532    pub terminal_ansi_bright_white: Option<String>,
 533
 534    /// Dim white ANSI terminal color.
 535    #[serde(rename = "terminal.ansi.dim_white")]
 536    pub terminal_ansi_dim_white: Option<String>,
 537
 538    #[serde(rename = "link_text.hover")]
 539    pub link_text_hover: Option<String>,
 540}
 541
 542impl ThemeColorsContent {
 543    /// Returns a [`ThemeColorsRefinement`] based on the colors in the [`ThemeColorsContent`].
 544    pub fn theme_colors_refinement(&self) -> ThemeColorsRefinement {
 545        let border = self
 546            .border
 547            .as_ref()
 548            .and_then(|color| try_parse_color(color).ok());
 549        let editor_document_highlight_read_background = self
 550            .editor_document_highlight_read_background
 551            .as_ref()
 552            .and_then(|color| try_parse_color(color).ok());
 553        ThemeColorsRefinement {
 554            border,
 555            border_variant: self
 556                .border_variant
 557                .as_ref()
 558                .and_then(|color| try_parse_color(color).ok()),
 559            border_focused: self
 560                .border_focused
 561                .as_ref()
 562                .and_then(|color| try_parse_color(color).ok()),
 563            border_selected: self
 564                .border_selected
 565                .as_ref()
 566                .and_then(|color| try_parse_color(color).ok()),
 567            border_transparent: self
 568                .border_transparent
 569                .as_ref()
 570                .and_then(|color| try_parse_color(color).ok()),
 571            border_disabled: self
 572                .border_disabled
 573                .as_ref()
 574                .and_then(|color| try_parse_color(color).ok()),
 575            elevated_surface_background: self
 576                .elevated_surface_background
 577                .as_ref()
 578                .and_then(|color| try_parse_color(color).ok()),
 579            surface_background: self
 580                .surface_background
 581                .as_ref()
 582                .and_then(|color| try_parse_color(color).ok()),
 583            background: self
 584                .background
 585                .as_ref()
 586                .and_then(|color| try_parse_color(color).ok()),
 587            element_background: self
 588                .element_background
 589                .as_ref()
 590                .and_then(|color| try_parse_color(color).ok()),
 591            element_hover: self
 592                .element_hover
 593                .as_ref()
 594                .and_then(|color| try_parse_color(color).ok()),
 595            element_active: self
 596                .element_active
 597                .as_ref()
 598                .and_then(|color| try_parse_color(color).ok()),
 599            element_selected: self
 600                .element_selected
 601                .as_ref()
 602                .and_then(|color| try_parse_color(color).ok()),
 603            element_disabled: self
 604                .element_disabled
 605                .as_ref()
 606                .and_then(|color| try_parse_color(color).ok()),
 607            drop_target_background: self
 608                .drop_target_background
 609                .as_ref()
 610                .and_then(|color| try_parse_color(color).ok()),
 611            ghost_element_background: self
 612                .ghost_element_background
 613                .as_ref()
 614                .and_then(|color| try_parse_color(color).ok()),
 615            ghost_element_hover: self
 616                .ghost_element_hover
 617                .as_ref()
 618                .and_then(|color| try_parse_color(color).ok()),
 619            ghost_element_active: self
 620                .ghost_element_active
 621                .as_ref()
 622                .and_then(|color| try_parse_color(color).ok()),
 623            ghost_element_selected: self
 624                .ghost_element_selected
 625                .as_ref()
 626                .and_then(|color| try_parse_color(color).ok()),
 627            ghost_element_disabled: self
 628                .ghost_element_disabled
 629                .as_ref()
 630                .and_then(|color| try_parse_color(color).ok()),
 631            text: self
 632                .text
 633                .as_ref()
 634                .and_then(|color| try_parse_color(color).ok()),
 635            text_muted: self
 636                .text_muted
 637                .as_ref()
 638                .and_then(|color| try_parse_color(color).ok()),
 639            text_placeholder: self
 640                .text_placeholder
 641                .as_ref()
 642                .and_then(|color| try_parse_color(color).ok()),
 643            text_disabled: self
 644                .text_disabled
 645                .as_ref()
 646                .and_then(|color| try_parse_color(color).ok()),
 647            text_accent: self
 648                .text_accent
 649                .as_ref()
 650                .and_then(|color| try_parse_color(color).ok()),
 651            icon: self
 652                .icon
 653                .as_ref()
 654                .and_then(|color| try_parse_color(color).ok()),
 655            icon_muted: self
 656                .icon_muted
 657                .as_ref()
 658                .and_then(|color| try_parse_color(color).ok()),
 659            icon_disabled: self
 660                .icon_disabled
 661                .as_ref()
 662                .and_then(|color| try_parse_color(color).ok()),
 663            icon_placeholder: self
 664                .icon_placeholder
 665                .as_ref()
 666                .and_then(|color| try_parse_color(color).ok()),
 667            icon_accent: self
 668                .icon_accent
 669                .as_ref()
 670                .and_then(|color| try_parse_color(color).ok()),
 671            status_bar_background: self
 672                .status_bar_background
 673                .as_ref()
 674                .and_then(|color| try_parse_color(color).ok()),
 675            title_bar_background: self
 676                .title_bar_background
 677                .as_ref()
 678                .and_then(|color| try_parse_color(color).ok()),
 679            title_bar_inactive_background: self
 680                .title_bar_inactive_background
 681                .as_ref()
 682                .and_then(|color| try_parse_color(color).ok()),
 683            toolbar_background: self
 684                .toolbar_background
 685                .as_ref()
 686                .and_then(|color| try_parse_color(color).ok()),
 687            tab_bar_background: self
 688                .tab_bar_background
 689                .as_ref()
 690                .and_then(|color| try_parse_color(color).ok()),
 691            tab_inactive_background: self
 692                .tab_inactive_background
 693                .as_ref()
 694                .and_then(|color| try_parse_color(color).ok()),
 695            tab_active_background: self
 696                .tab_active_background
 697                .as_ref()
 698                .and_then(|color| try_parse_color(color).ok()),
 699            search_match_background: self
 700                .search_match_background
 701                .as_ref()
 702                .and_then(|color| try_parse_color(color).ok()),
 703            panel_background: self
 704                .panel_background
 705                .as_ref()
 706                .and_then(|color| try_parse_color(color).ok()),
 707            panel_focused_border: self
 708                .panel_focused_border
 709                .as_ref()
 710                .and_then(|color| try_parse_color(color).ok()),
 711            pane_focused_border: self
 712                .pane_focused_border
 713                .as_ref()
 714                .and_then(|color| try_parse_color(color).ok()),
 715            pane_group_border: self
 716                .pane_group_border
 717                .as_ref()
 718                .and_then(|color| try_parse_color(color).ok())
 719                .or(border),
 720            scrollbar_thumb_background: self
 721                .scrollbar_thumb_background
 722                .as_ref()
 723                .and_then(|color| try_parse_color(color).ok())
 724                .or_else(|| {
 725                    self.deprecated_scrollbar_thumb_background
 726                        .as_ref()
 727                        .and_then(|color| try_parse_color(color).ok())
 728                }),
 729            scrollbar_thumb_hover_background: self
 730                .scrollbar_thumb_hover_background
 731                .as_ref()
 732                .and_then(|color| try_parse_color(color).ok()),
 733            scrollbar_thumb_border: self
 734                .scrollbar_thumb_border
 735                .as_ref()
 736                .and_then(|color| try_parse_color(color).ok()),
 737            scrollbar_track_background: self
 738                .scrollbar_track_background
 739                .as_ref()
 740                .and_then(|color| try_parse_color(color).ok()),
 741            scrollbar_track_border: self
 742                .scrollbar_track_border
 743                .as_ref()
 744                .and_then(|color| try_parse_color(color).ok()),
 745            editor_foreground: self
 746                .editor_foreground
 747                .as_ref()
 748                .and_then(|color| try_parse_color(color).ok()),
 749            editor_background: self
 750                .editor_background
 751                .as_ref()
 752                .and_then(|color| try_parse_color(color).ok()),
 753            editor_gutter_background: self
 754                .editor_gutter_background
 755                .as_ref()
 756                .and_then(|color| try_parse_color(color).ok()),
 757            editor_subheader_background: self
 758                .editor_subheader_background
 759                .as_ref()
 760                .and_then(|color| try_parse_color(color).ok()),
 761            editor_active_line_background: self
 762                .editor_active_line_background
 763                .as_ref()
 764                .and_then(|color| try_parse_color(color).ok()),
 765            editor_highlighted_line_background: self
 766                .editor_highlighted_line_background
 767                .as_ref()
 768                .and_then(|color| try_parse_color(color).ok()),
 769            editor_line_number: self
 770                .editor_line_number
 771                .as_ref()
 772                .and_then(|color| try_parse_color(color).ok()),
 773            editor_active_line_number: self
 774                .editor_active_line_number
 775                .as_ref()
 776                .and_then(|color| try_parse_color(color).ok()),
 777            editor_invisible: self
 778                .editor_invisible
 779                .as_ref()
 780                .and_then(|color| try_parse_color(color).ok()),
 781            editor_wrap_guide: self
 782                .editor_wrap_guide
 783                .as_ref()
 784                .and_then(|color| try_parse_color(color).ok()),
 785            editor_active_wrap_guide: self
 786                .editor_active_wrap_guide
 787                .as_ref()
 788                .and_then(|color| try_parse_color(color).ok()),
 789            editor_indent_guide: self
 790                .editor_indent_guide
 791                .as_ref()
 792                .and_then(|color| try_parse_color(color).ok()),
 793            editor_indent_guide_active: self
 794                .editor_indent_guide_active
 795                .as_ref()
 796                .and_then(|color| try_parse_color(color).ok()),
 797            editor_document_highlight_read_background,
 798            editor_document_highlight_write_background: self
 799                .editor_document_highlight_write_background
 800                .as_ref()
 801                .and_then(|color| try_parse_color(color).ok()),
 802            editor_document_highlight_bracket_background: self
 803                .editor_document_highlight_bracket_background
 804                .as_ref()
 805                .and_then(|color| try_parse_color(color).ok())
 806                // Fall back to `editor.document_highlight.read_background`, for backwards compatibility.
 807                .or(editor_document_highlight_read_background),
 808            terminal_background: self
 809                .terminal_background
 810                .as_ref()
 811                .and_then(|color| try_parse_color(color).ok()),
 812            terminal_ansi_background: self
 813                .terminal_ansi_background
 814                .as_ref()
 815                .and_then(|color| try_parse_color(color).ok()),
 816            terminal_foreground: self
 817                .terminal_foreground
 818                .as_ref()
 819                .and_then(|color| try_parse_color(color).ok()),
 820            terminal_bright_foreground: self
 821                .terminal_bright_foreground
 822                .as_ref()
 823                .and_then(|color| try_parse_color(color).ok()),
 824            terminal_dim_foreground: self
 825                .terminal_dim_foreground
 826                .as_ref()
 827                .and_then(|color| try_parse_color(color).ok()),
 828            terminal_ansi_black: self
 829                .terminal_ansi_black
 830                .as_ref()
 831                .and_then(|color| try_parse_color(color).ok()),
 832            terminal_ansi_bright_black: self
 833                .terminal_ansi_bright_black
 834                .as_ref()
 835                .and_then(|color| try_parse_color(color).ok()),
 836            terminal_ansi_dim_black: self
 837                .terminal_ansi_dim_black
 838                .as_ref()
 839                .and_then(|color| try_parse_color(color).ok()),
 840            terminal_ansi_red: self
 841                .terminal_ansi_red
 842                .as_ref()
 843                .and_then(|color| try_parse_color(color).ok()),
 844            terminal_ansi_bright_red: self
 845                .terminal_ansi_bright_red
 846                .as_ref()
 847                .and_then(|color| try_parse_color(color).ok()),
 848            terminal_ansi_dim_red: self
 849                .terminal_ansi_dim_red
 850                .as_ref()
 851                .and_then(|color| try_parse_color(color).ok()),
 852            terminal_ansi_green: self
 853                .terminal_ansi_green
 854                .as_ref()
 855                .and_then(|color| try_parse_color(color).ok()),
 856            terminal_ansi_bright_green: self
 857                .terminal_ansi_bright_green
 858                .as_ref()
 859                .and_then(|color| try_parse_color(color).ok()),
 860            terminal_ansi_dim_green: self
 861                .terminal_ansi_dim_green
 862                .as_ref()
 863                .and_then(|color| try_parse_color(color).ok()),
 864            terminal_ansi_yellow: self
 865                .terminal_ansi_yellow
 866                .as_ref()
 867                .and_then(|color| try_parse_color(color).ok()),
 868            terminal_ansi_bright_yellow: self
 869                .terminal_ansi_bright_yellow
 870                .as_ref()
 871                .and_then(|color| try_parse_color(color).ok()),
 872            terminal_ansi_dim_yellow: self
 873                .terminal_ansi_dim_yellow
 874                .as_ref()
 875                .and_then(|color| try_parse_color(color).ok()),
 876            terminal_ansi_blue: self
 877                .terminal_ansi_blue
 878                .as_ref()
 879                .and_then(|color| try_parse_color(color).ok()),
 880            terminal_ansi_bright_blue: self
 881                .terminal_ansi_bright_blue
 882                .as_ref()
 883                .and_then(|color| try_parse_color(color).ok()),
 884            terminal_ansi_dim_blue: self
 885                .terminal_ansi_dim_blue
 886                .as_ref()
 887                .and_then(|color| try_parse_color(color).ok()),
 888            terminal_ansi_magenta: self
 889                .terminal_ansi_magenta
 890                .as_ref()
 891                .and_then(|color| try_parse_color(color).ok()),
 892            terminal_ansi_bright_magenta: self
 893                .terminal_ansi_bright_magenta
 894                .as_ref()
 895                .and_then(|color| try_parse_color(color).ok()),
 896            terminal_ansi_dim_magenta: self
 897                .terminal_ansi_dim_magenta
 898                .as_ref()
 899                .and_then(|color| try_parse_color(color).ok()),
 900            terminal_ansi_cyan: self
 901                .terminal_ansi_cyan
 902                .as_ref()
 903                .and_then(|color| try_parse_color(color).ok()),
 904            terminal_ansi_bright_cyan: self
 905                .terminal_ansi_bright_cyan
 906                .as_ref()
 907                .and_then(|color| try_parse_color(color).ok()),
 908            terminal_ansi_dim_cyan: self
 909                .terminal_ansi_dim_cyan
 910                .as_ref()
 911                .and_then(|color| try_parse_color(color).ok()),
 912            terminal_ansi_white: self
 913                .terminal_ansi_white
 914                .as_ref()
 915                .and_then(|color| try_parse_color(color).ok()),
 916            terminal_ansi_bright_white: self
 917                .terminal_ansi_bright_white
 918                .as_ref()
 919                .and_then(|color| try_parse_color(color).ok()),
 920            terminal_ansi_dim_white: self
 921                .terminal_ansi_dim_white
 922                .as_ref()
 923                .and_then(|color| try_parse_color(color).ok()),
 924            link_text_hover: self
 925                .link_text_hover
 926                .as_ref()
 927                .and_then(|color| try_parse_color(color).ok()),
 928        }
 929    }
 930}
 931
 932#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
 933#[serde(default)]
 934pub struct StatusColorsContent {
 935    /// Indicates some kind of conflict, like a file changed on disk while it was open, or
 936    /// merge conflicts in a Git repository.
 937    #[serde(rename = "conflict")]
 938    pub conflict: Option<String>,
 939
 940    #[serde(rename = "conflict.background")]
 941    pub conflict_background: Option<String>,
 942
 943    #[serde(rename = "conflict.border")]
 944    pub conflict_border: Option<String>,
 945
 946    /// Indicates something new, like a new file added to a Git repository.
 947    #[serde(rename = "created")]
 948    pub created: Option<String>,
 949
 950    #[serde(rename = "created.background")]
 951    pub created_background: Option<String>,
 952
 953    #[serde(rename = "created.border")]
 954    pub created_border: Option<String>,
 955
 956    /// Indicates that something no longer exists, like a deleted file.
 957    #[serde(rename = "deleted")]
 958    pub deleted: Option<String>,
 959
 960    #[serde(rename = "deleted.background")]
 961    pub deleted_background: Option<String>,
 962
 963    #[serde(rename = "deleted.border")]
 964    pub deleted_border: Option<String>,
 965
 966    /// Indicates a system error, a failed operation or a diagnostic error.
 967    #[serde(rename = "error")]
 968    pub error: Option<String>,
 969
 970    #[serde(rename = "error.background")]
 971    pub error_background: Option<String>,
 972
 973    #[serde(rename = "error.border")]
 974    pub error_border: Option<String>,
 975
 976    /// Represents a hidden status, such as a file being hidden in a file tree.
 977    #[serde(rename = "hidden")]
 978    pub hidden: Option<String>,
 979
 980    #[serde(rename = "hidden.background")]
 981    pub hidden_background: Option<String>,
 982
 983    #[serde(rename = "hidden.border")]
 984    pub hidden_border: Option<String>,
 985
 986    /// Indicates a hint or some kind of additional information.
 987    #[serde(rename = "hint")]
 988    pub hint: Option<String>,
 989
 990    #[serde(rename = "hint.background")]
 991    pub hint_background: Option<String>,
 992
 993    #[serde(rename = "hint.border")]
 994    pub hint_border: Option<String>,
 995
 996    /// Indicates that something is deliberately ignored, such as a file or operation ignored by Git.
 997    #[serde(rename = "ignored")]
 998    pub ignored: Option<String>,
 999
1000    #[serde(rename = "ignored.background")]
1001    pub ignored_background: Option<String>,
1002
1003    #[serde(rename = "ignored.border")]
1004    pub ignored_border: Option<String>,
1005
1006    /// Represents informational status updates or messages.
1007    #[serde(rename = "info")]
1008    pub info: Option<String>,
1009
1010    #[serde(rename = "info.background")]
1011    pub info_background: Option<String>,
1012
1013    #[serde(rename = "info.border")]
1014    pub info_border: Option<String>,
1015
1016    /// Indicates a changed or altered status, like a file that has been edited.
1017    #[serde(rename = "modified")]
1018    pub modified: Option<String>,
1019
1020    #[serde(rename = "modified.background")]
1021    pub modified_background: Option<String>,
1022
1023    #[serde(rename = "modified.border")]
1024    pub modified_border: Option<String>,
1025
1026    /// Indicates something that is predicted, like automatic code completion, or generated code.
1027    #[serde(rename = "predictive")]
1028    pub predictive: Option<String>,
1029
1030    #[serde(rename = "predictive.background")]
1031    pub predictive_background: Option<String>,
1032
1033    #[serde(rename = "predictive.border")]
1034    pub predictive_border: Option<String>,
1035
1036    /// Represents a renamed status, such as a file that has been renamed.
1037    #[serde(rename = "renamed")]
1038    pub renamed: Option<String>,
1039
1040    #[serde(rename = "renamed.background")]
1041    pub renamed_background: Option<String>,
1042
1043    #[serde(rename = "renamed.border")]
1044    pub renamed_border: Option<String>,
1045
1046    /// Indicates a successful operation or task completion.
1047    #[serde(rename = "success")]
1048    pub success: Option<String>,
1049
1050    #[serde(rename = "success.background")]
1051    pub success_background: Option<String>,
1052
1053    #[serde(rename = "success.border")]
1054    pub success_border: Option<String>,
1055
1056    /// Indicates some kind of unreachable status, like a block of code that can never be reached.
1057    #[serde(rename = "unreachable")]
1058    pub unreachable: Option<String>,
1059
1060    #[serde(rename = "unreachable.background")]
1061    pub unreachable_background: Option<String>,
1062
1063    #[serde(rename = "unreachable.border")]
1064    pub unreachable_border: Option<String>,
1065
1066    /// Represents a warning status, like an operation that is about to fail.
1067    #[serde(rename = "warning")]
1068    pub warning: Option<String>,
1069
1070    #[serde(rename = "warning.background")]
1071    pub warning_background: Option<String>,
1072
1073    #[serde(rename = "warning.border")]
1074    pub warning_border: Option<String>,
1075}
1076
1077impl StatusColorsContent {
1078    /// Returns a [`StatusColorsRefinement`] based on the colors in the [`StatusColorsContent`].
1079    pub fn status_colors_refinement(&self) -> StatusColorsRefinement {
1080        StatusColorsRefinement {
1081            conflict: self
1082                .conflict
1083                .as_ref()
1084                .and_then(|color| try_parse_color(color).ok()),
1085            conflict_background: self
1086                .conflict_background
1087                .as_ref()
1088                .and_then(|color| try_parse_color(color).ok()),
1089            conflict_border: self
1090                .conflict_border
1091                .as_ref()
1092                .and_then(|color| try_parse_color(color).ok()),
1093            created: self
1094                .created
1095                .as_ref()
1096                .and_then(|color| try_parse_color(color).ok()),
1097            created_background: self
1098                .created_background
1099                .as_ref()
1100                .and_then(|color| try_parse_color(color).ok()),
1101            created_border: self
1102                .created_border
1103                .as_ref()
1104                .and_then(|color| try_parse_color(color).ok()),
1105            deleted: self
1106                .deleted
1107                .as_ref()
1108                .and_then(|color| try_parse_color(color).ok()),
1109            deleted_background: self
1110                .deleted_background
1111                .as_ref()
1112                .and_then(|color| try_parse_color(color).ok()),
1113            deleted_border: self
1114                .deleted_border
1115                .as_ref()
1116                .and_then(|color| try_parse_color(color).ok()),
1117            error: self
1118                .error
1119                .as_ref()
1120                .and_then(|color| try_parse_color(color).ok()),
1121            error_background: self
1122                .error_background
1123                .as_ref()
1124                .and_then(|color| try_parse_color(color).ok()),
1125            error_border: self
1126                .error_border
1127                .as_ref()
1128                .and_then(|color| try_parse_color(color).ok()),
1129            hidden: self
1130                .hidden
1131                .as_ref()
1132                .and_then(|color| try_parse_color(color).ok()),
1133            hidden_background: self
1134                .hidden_background
1135                .as_ref()
1136                .and_then(|color| try_parse_color(color).ok()),
1137            hidden_border: self
1138                .hidden_border
1139                .as_ref()
1140                .and_then(|color| try_parse_color(color).ok()),
1141            hint: self
1142                .hint
1143                .as_ref()
1144                .and_then(|color| try_parse_color(color).ok()),
1145            hint_background: self
1146                .hint_background
1147                .as_ref()
1148                .and_then(|color| try_parse_color(color).ok()),
1149            hint_border: self
1150                .hint_border
1151                .as_ref()
1152                .and_then(|color| try_parse_color(color).ok()),
1153            ignored: self
1154                .ignored
1155                .as_ref()
1156                .and_then(|color| try_parse_color(color).ok()),
1157            ignored_background: self
1158                .ignored_background
1159                .as_ref()
1160                .and_then(|color| try_parse_color(color).ok()),
1161            ignored_border: self
1162                .ignored_border
1163                .as_ref()
1164                .and_then(|color| try_parse_color(color).ok()),
1165            info: self
1166                .info
1167                .as_ref()
1168                .and_then(|color| try_parse_color(color).ok()),
1169            info_background: self
1170                .info_background
1171                .as_ref()
1172                .and_then(|color| try_parse_color(color).ok()),
1173            info_border: self
1174                .info_border
1175                .as_ref()
1176                .and_then(|color| try_parse_color(color).ok()),
1177            modified: self
1178                .modified
1179                .as_ref()
1180                .and_then(|color| try_parse_color(color).ok()),
1181            modified_background: self
1182                .modified_background
1183                .as_ref()
1184                .and_then(|color| try_parse_color(color).ok()),
1185            modified_border: self
1186                .modified_border
1187                .as_ref()
1188                .and_then(|color| try_parse_color(color).ok()),
1189            predictive: self
1190                .predictive
1191                .as_ref()
1192                .and_then(|color| try_parse_color(color).ok()),
1193            predictive_background: self
1194                .predictive_background
1195                .as_ref()
1196                .and_then(|color| try_parse_color(color).ok()),
1197            predictive_border: self
1198                .predictive_border
1199                .as_ref()
1200                .and_then(|color| try_parse_color(color).ok()),
1201            renamed: self
1202                .renamed
1203                .as_ref()
1204                .and_then(|color| try_parse_color(color).ok()),
1205            renamed_background: self
1206                .renamed_background
1207                .as_ref()
1208                .and_then(|color| try_parse_color(color).ok()),
1209            renamed_border: self
1210                .renamed_border
1211                .as_ref()
1212                .and_then(|color| try_parse_color(color).ok()),
1213            success: self
1214                .success
1215                .as_ref()
1216                .and_then(|color| try_parse_color(color).ok()),
1217            success_background: self
1218                .success_background
1219                .as_ref()
1220                .and_then(|color| try_parse_color(color).ok()),
1221            success_border: self
1222                .success_border
1223                .as_ref()
1224                .and_then(|color| try_parse_color(color).ok()),
1225            unreachable: self
1226                .unreachable
1227                .as_ref()
1228                .and_then(|color| try_parse_color(color).ok()),
1229            unreachable_background: self
1230                .unreachable_background
1231                .as_ref()
1232                .and_then(|color| try_parse_color(color).ok()),
1233            unreachable_border: self
1234                .unreachable_border
1235                .as_ref()
1236                .and_then(|color| try_parse_color(color).ok()),
1237            warning: self
1238                .warning
1239                .as_ref()
1240                .and_then(|color| try_parse_color(color).ok()),
1241            warning_background: self
1242                .warning_background
1243                .as_ref()
1244                .and_then(|color| try_parse_color(color).ok()),
1245            warning_border: self
1246                .warning_border
1247                .as_ref()
1248                .and_then(|color| try_parse_color(color).ok()),
1249        }
1250    }
1251}
1252
1253#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
1254pub struct AccentContent(pub Option<String>);
1255
1256#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
1257pub struct PlayerColorContent {
1258    pub cursor: Option<String>,
1259    pub background: Option<String>,
1260    pub selection: Option<String>,
1261}
1262
1263#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
1264#[serde(rename_all = "snake_case")]
1265pub enum FontStyleContent {
1266    Normal,
1267    Italic,
1268    Oblique,
1269}
1270
1271impl From<FontStyleContent> for FontStyle {
1272    fn from(value: FontStyleContent) -> Self {
1273        match value {
1274            FontStyleContent::Normal => FontStyle::Normal,
1275            FontStyleContent::Italic => FontStyle::Italic,
1276            FontStyleContent::Oblique => FontStyle::Oblique,
1277        }
1278    }
1279}
1280
1281#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr)]
1282#[repr(u16)]
1283pub enum FontWeightContent {
1284    Thin = 100,
1285    ExtraLight = 200,
1286    Light = 300,
1287    Normal = 400,
1288    Medium = 500,
1289    Semibold = 600,
1290    Bold = 700,
1291    ExtraBold = 800,
1292    Black = 900,
1293}
1294
1295impl JsonSchema for FontWeightContent {
1296    fn schema_name() -> String {
1297        "FontWeightContent".to_owned()
1298    }
1299
1300    fn is_referenceable() -> bool {
1301        false
1302    }
1303
1304    fn json_schema(_: &mut SchemaGenerator) -> Schema {
1305        SchemaObject {
1306            enum_values: Some(vec![
1307                100.into(),
1308                200.into(),
1309                300.into(),
1310                400.into(),
1311                500.into(),
1312                600.into(),
1313                700.into(),
1314                800.into(),
1315                900.into(),
1316            ]),
1317            ..Default::default()
1318        }
1319        .into()
1320    }
1321}
1322
1323impl From<FontWeightContent> for FontWeight {
1324    fn from(value: FontWeightContent) -> Self {
1325        match value {
1326            FontWeightContent::Thin => FontWeight::THIN,
1327            FontWeightContent::ExtraLight => FontWeight::EXTRA_LIGHT,
1328            FontWeightContent::Light => FontWeight::LIGHT,
1329            FontWeightContent::Normal => FontWeight::NORMAL,
1330            FontWeightContent::Medium => FontWeight::MEDIUM,
1331            FontWeightContent::Semibold => FontWeight::SEMIBOLD,
1332            FontWeightContent::Bold => FontWeight::BOLD,
1333            FontWeightContent::ExtraBold => FontWeight::EXTRA_BOLD,
1334            FontWeightContent::Black => FontWeight::BLACK,
1335        }
1336    }
1337}
1338
1339#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
1340#[serde(default)]
1341pub struct HighlightStyleContent {
1342    pub color: Option<String>,
1343
1344    #[serde(deserialize_with = "treat_error_as_none")]
1345    pub background_color: Option<String>,
1346
1347    #[serde(deserialize_with = "treat_error_as_none")]
1348    pub font_style: Option<FontStyleContent>,
1349
1350    #[serde(deserialize_with = "treat_error_as_none")]
1351    pub font_weight: Option<FontWeightContent>,
1352}
1353
1354impl HighlightStyleContent {
1355    pub fn is_empty(&self) -> bool {
1356        self.color.is_none()
1357            && self.background_color.is_none()
1358            && self.font_style.is_none()
1359            && self.font_weight.is_none()
1360    }
1361}
1362
1363fn treat_error_as_none<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
1364where
1365    T: Deserialize<'de>,
1366    D: Deserializer<'de>,
1367{
1368    let value: Value = Deserialize::deserialize(deserializer)?;
1369    Ok(T::deserialize(value).ok())
1370}