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    /// Terminal background color.
 417    #[serde(rename = "terminal.background")]
 418    pub terminal_background: Option<String>,
 419
 420    /// Terminal foreground color.
 421    #[serde(rename = "terminal.foreground")]
 422    pub terminal_foreground: Option<String>,
 423
 424    /// Bright terminal foreground color.
 425    #[serde(rename = "terminal.bright_foreground")]
 426    pub terminal_bright_foreground: Option<String>,
 427
 428    /// Dim terminal foreground color.
 429    #[serde(rename = "terminal.dim_foreground")]
 430    pub terminal_dim_foreground: Option<String>,
 431
 432    /// Black ANSI terminal color.
 433    #[serde(rename = "terminal.ansi.black")]
 434    pub terminal_ansi_black: Option<String>,
 435
 436    /// Bright black ANSI terminal color.
 437    #[serde(rename = "terminal.ansi.bright_black")]
 438    pub terminal_ansi_bright_black: Option<String>,
 439
 440    /// Dim black ANSI terminal color.
 441    #[serde(rename = "terminal.ansi.dim_black")]
 442    pub terminal_ansi_dim_black: Option<String>,
 443
 444    /// Red ANSI terminal color.
 445    #[serde(rename = "terminal.ansi.red")]
 446    pub terminal_ansi_red: Option<String>,
 447
 448    /// Bright red ANSI terminal color.
 449    #[serde(rename = "terminal.ansi.bright_red")]
 450    pub terminal_ansi_bright_red: Option<String>,
 451
 452    /// Dim red ANSI terminal color.
 453    #[serde(rename = "terminal.ansi.dim_red")]
 454    pub terminal_ansi_dim_red: Option<String>,
 455
 456    /// Green ANSI terminal color.
 457    #[serde(rename = "terminal.ansi.green")]
 458    pub terminal_ansi_green: Option<String>,
 459
 460    /// Bright green ANSI terminal color.
 461    #[serde(rename = "terminal.ansi.bright_green")]
 462    pub terminal_ansi_bright_green: Option<String>,
 463
 464    /// Dim green ANSI terminal color.
 465    #[serde(rename = "terminal.ansi.dim_green")]
 466    pub terminal_ansi_dim_green: Option<String>,
 467
 468    /// Yellow ANSI terminal color.
 469    #[serde(rename = "terminal.ansi.yellow")]
 470    pub terminal_ansi_yellow: Option<String>,
 471
 472    /// Bright yellow ANSI terminal color.
 473    #[serde(rename = "terminal.ansi.bright_yellow")]
 474    pub terminal_ansi_bright_yellow: Option<String>,
 475
 476    /// Dim yellow ANSI terminal color.
 477    #[serde(rename = "terminal.ansi.dim_yellow")]
 478    pub terminal_ansi_dim_yellow: Option<String>,
 479
 480    /// Blue ANSI terminal color.
 481    #[serde(rename = "terminal.ansi.blue")]
 482    pub terminal_ansi_blue: Option<String>,
 483
 484    /// Bright blue ANSI terminal color.
 485    #[serde(rename = "terminal.ansi.bright_blue")]
 486    pub terminal_ansi_bright_blue: Option<String>,
 487
 488    /// Dim blue ANSI terminal color.
 489    #[serde(rename = "terminal.ansi.dim_blue")]
 490    pub terminal_ansi_dim_blue: Option<String>,
 491
 492    /// Magenta ANSI terminal color.
 493    #[serde(rename = "terminal.ansi.magenta")]
 494    pub terminal_ansi_magenta: Option<String>,
 495
 496    /// Bright magenta ANSI terminal color.
 497    #[serde(rename = "terminal.ansi.bright_magenta")]
 498    pub terminal_ansi_bright_magenta: Option<String>,
 499
 500    /// Dim magenta ANSI terminal color.
 501    #[serde(rename = "terminal.ansi.dim_magenta")]
 502    pub terminal_ansi_dim_magenta: Option<String>,
 503
 504    /// Cyan ANSI terminal color.
 505    #[serde(rename = "terminal.ansi.cyan")]
 506    pub terminal_ansi_cyan: Option<String>,
 507
 508    /// Bright cyan ANSI terminal color.
 509    #[serde(rename = "terminal.ansi.bright_cyan")]
 510    pub terminal_ansi_bright_cyan: Option<String>,
 511
 512    /// Dim cyan ANSI terminal color.
 513    #[serde(rename = "terminal.ansi.dim_cyan")]
 514    pub terminal_ansi_dim_cyan: Option<String>,
 515
 516    /// White ANSI terminal color.
 517    #[serde(rename = "terminal.ansi.white")]
 518    pub terminal_ansi_white: Option<String>,
 519
 520    /// Bright white ANSI terminal color.
 521    #[serde(rename = "terminal.ansi.bright_white")]
 522    pub terminal_ansi_bright_white: Option<String>,
 523
 524    /// Dim white ANSI terminal color.
 525    #[serde(rename = "terminal.ansi.dim_white")]
 526    pub terminal_ansi_dim_white: Option<String>,
 527
 528    #[serde(rename = "link_text.hover")]
 529    pub link_text_hover: Option<String>,
 530}
 531
 532impl ThemeColorsContent {
 533    /// Returns a [`ThemeColorsRefinement`] based on the colors in the [`ThemeColorsContent`].
 534    pub fn theme_colors_refinement(&self) -> ThemeColorsRefinement {
 535        let border = self
 536            .border
 537            .as_ref()
 538            .and_then(|color| try_parse_color(color).ok());
 539        ThemeColorsRefinement {
 540            border,
 541            border_variant: self
 542                .border_variant
 543                .as_ref()
 544                .and_then(|color| try_parse_color(color).ok()),
 545            border_focused: self
 546                .border_focused
 547                .as_ref()
 548                .and_then(|color| try_parse_color(color).ok()),
 549            border_selected: self
 550                .border_selected
 551                .as_ref()
 552                .and_then(|color| try_parse_color(color).ok()),
 553            border_transparent: self
 554                .border_transparent
 555                .as_ref()
 556                .and_then(|color| try_parse_color(color).ok()),
 557            border_disabled: self
 558                .border_disabled
 559                .as_ref()
 560                .and_then(|color| try_parse_color(color).ok()),
 561            elevated_surface_background: self
 562                .elevated_surface_background
 563                .as_ref()
 564                .and_then(|color| try_parse_color(color).ok()),
 565            surface_background: self
 566                .surface_background
 567                .as_ref()
 568                .and_then(|color| try_parse_color(color).ok()),
 569            background: self
 570                .background
 571                .as_ref()
 572                .and_then(|color| try_parse_color(color).ok()),
 573            element_background: self
 574                .element_background
 575                .as_ref()
 576                .and_then(|color| try_parse_color(color).ok()),
 577            element_hover: self
 578                .element_hover
 579                .as_ref()
 580                .and_then(|color| try_parse_color(color).ok()),
 581            element_active: self
 582                .element_active
 583                .as_ref()
 584                .and_then(|color| try_parse_color(color).ok()),
 585            element_selected: self
 586                .element_selected
 587                .as_ref()
 588                .and_then(|color| try_parse_color(color).ok()),
 589            element_disabled: self
 590                .element_disabled
 591                .as_ref()
 592                .and_then(|color| try_parse_color(color).ok()),
 593            drop_target_background: self
 594                .drop_target_background
 595                .as_ref()
 596                .and_then(|color| try_parse_color(color).ok()),
 597            ghost_element_background: self
 598                .ghost_element_background
 599                .as_ref()
 600                .and_then(|color| try_parse_color(color).ok()),
 601            ghost_element_hover: self
 602                .ghost_element_hover
 603                .as_ref()
 604                .and_then(|color| try_parse_color(color).ok()),
 605            ghost_element_active: self
 606                .ghost_element_active
 607                .as_ref()
 608                .and_then(|color| try_parse_color(color).ok()),
 609            ghost_element_selected: self
 610                .ghost_element_selected
 611                .as_ref()
 612                .and_then(|color| try_parse_color(color).ok()),
 613            ghost_element_disabled: self
 614                .ghost_element_disabled
 615                .as_ref()
 616                .and_then(|color| try_parse_color(color).ok()),
 617            text: self
 618                .text
 619                .as_ref()
 620                .and_then(|color| try_parse_color(color).ok()),
 621            text_muted: self
 622                .text_muted
 623                .as_ref()
 624                .and_then(|color| try_parse_color(color).ok()),
 625            text_placeholder: self
 626                .text_placeholder
 627                .as_ref()
 628                .and_then(|color| try_parse_color(color).ok()),
 629            text_disabled: self
 630                .text_disabled
 631                .as_ref()
 632                .and_then(|color| try_parse_color(color).ok()),
 633            text_accent: self
 634                .text_accent
 635                .as_ref()
 636                .and_then(|color| try_parse_color(color).ok()),
 637            icon: self
 638                .icon
 639                .as_ref()
 640                .and_then(|color| try_parse_color(color).ok()),
 641            icon_muted: self
 642                .icon_muted
 643                .as_ref()
 644                .and_then(|color| try_parse_color(color).ok()),
 645            icon_disabled: self
 646                .icon_disabled
 647                .as_ref()
 648                .and_then(|color| try_parse_color(color).ok()),
 649            icon_placeholder: self
 650                .icon_placeholder
 651                .as_ref()
 652                .and_then(|color| try_parse_color(color).ok()),
 653            icon_accent: self
 654                .icon_accent
 655                .as_ref()
 656                .and_then(|color| try_parse_color(color).ok()),
 657            status_bar_background: self
 658                .status_bar_background
 659                .as_ref()
 660                .and_then(|color| try_parse_color(color).ok()),
 661            title_bar_background: self
 662                .title_bar_background
 663                .as_ref()
 664                .and_then(|color| try_parse_color(color).ok()),
 665            title_bar_inactive_background: self
 666                .title_bar_inactive_background
 667                .as_ref()
 668                .and_then(|color| try_parse_color(color).ok()),
 669            toolbar_background: self
 670                .toolbar_background
 671                .as_ref()
 672                .and_then(|color| try_parse_color(color).ok()),
 673            tab_bar_background: self
 674                .tab_bar_background
 675                .as_ref()
 676                .and_then(|color| try_parse_color(color).ok()),
 677            tab_inactive_background: self
 678                .tab_inactive_background
 679                .as_ref()
 680                .and_then(|color| try_parse_color(color).ok()),
 681            tab_active_background: self
 682                .tab_active_background
 683                .as_ref()
 684                .and_then(|color| try_parse_color(color).ok()),
 685            search_match_background: self
 686                .search_match_background
 687                .as_ref()
 688                .and_then(|color| try_parse_color(color).ok()),
 689            panel_background: self
 690                .panel_background
 691                .as_ref()
 692                .and_then(|color| try_parse_color(color).ok()),
 693            panel_focused_border: self
 694                .panel_focused_border
 695                .as_ref()
 696                .and_then(|color| try_parse_color(color).ok()),
 697            pane_focused_border: self
 698                .pane_focused_border
 699                .as_ref()
 700                .and_then(|color| try_parse_color(color).ok()),
 701            pane_group_border: self
 702                .pane_group_border
 703                .as_ref()
 704                .and_then(|color| try_parse_color(color).ok())
 705                .or(border),
 706            scrollbar_thumb_background: self
 707                .scrollbar_thumb_background
 708                .as_ref()
 709                .and_then(|color| try_parse_color(color).ok())
 710                .or_else(|| {
 711                    self.deprecated_scrollbar_thumb_background
 712                        .as_ref()
 713                        .and_then(|color| try_parse_color(color).ok())
 714                }),
 715            scrollbar_thumb_hover_background: self
 716                .scrollbar_thumb_hover_background
 717                .as_ref()
 718                .and_then(|color| try_parse_color(color).ok()),
 719            scrollbar_thumb_border: self
 720                .scrollbar_thumb_border
 721                .as_ref()
 722                .and_then(|color| try_parse_color(color).ok()),
 723            scrollbar_track_background: self
 724                .scrollbar_track_background
 725                .as_ref()
 726                .and_then(|color| try_parse_color(color).ok()),
 727            scrollbar_track_border: self
 728                .scrollbar_track_border
 729                .as_ref()
 730                .and_then(|color| try_parse_color(color).ok()),
 731            editor_foreground: self
 732                .editor_foreground
 733                .as_ref()
 734                .and_then(|color| try_parse_color(color).ok()),
 735            editor_background: self
 736                .editor_background
 737                .as_ref()
 738                .and_then(|color| try_parse_color(color).ok()),
 739            editor_gutter_background: self
 740                .editor_gutter_background
 741                .as_ref()
 742                .and_then(|color| try_parse_color(color).ok()),
 743            editor_subheader_background: self
 744                .editor_subheader_background
 745                .as_ref()
 746                .and_then(|color| try_parse_color(color).ok()),
 747            editor_active_line_background: self
 748                .editor_active_line_background
 749                .as_ref()
 750                .and_then(|color| try_parse_color(color).ok()),
 751            editor_highlighted_line_background: self
 752                .editor_highlighted_line_background
 753                .as_ref()
 754                .and_then(|color| try_parse_color(color).ok()),
 755            editor_line_number: self
 756                .editor_line_number
 757                .as_ref()
 758                .and_then(|color| try_parse_color(color).ok()),
 759            editor_active_line_number: self
 760                .editor_active_line_number
 761                .as_ref()
 762                .and_then(|color| try_parse_color(color).ok()),
 763            editor_invisible: self
 764                .editor_invisible
 765                .as_ref()
 766                .and_then(|color| try_parse_color(color).ok()),
 767            editor_wrap_guide: self
 768                .editor_wrap_guide
 769                .as_ref()
 770                .and_then(|color| try_parse_color(color).ok()),
 771            editor_active_wrap_guide: self
 772                .editor_active_wrap_guide
 773                .as_ref()
 774                .and_then(|color| try_parse_color(color).ok()),
 775            editor_indent_guide: self
 776                .editor_indent_guide
 777                .as_ref()
 778                .and_then(|color| try_parse_color(color).ok()),
 779            editor_indent_guide_active: self
 780                .editor_indent_guide_active
 781                .as_ref()
 782                .and_then(|color| try_parse_color(color).ok()),
 783            editor_document_highlight_read_background: self
 784                .editor_document_highlight_read_background
 785                .as_ref()
 786                .and_then(|color| try_parse_color(color).ok()),
 787            editor_document_highlight_write_background: self
 788                .editor_document_highlight_write_background
 789                .as_ref()
 790                .and_then(|color| try_parse_color(color).ok()),
 791            terminal_background: self
 792                .terminal_background
 793                .as_ref()
 794                .and_then(|color| try_parse_color(color).ok()),
 795            terminal_foreground: self
 796                .terminal_foreground
 797                .as_ref()
 798                .and_then(|color| try_parse_color(color).ok()),
 799            terminal_bright_foreground: self
 800                .terminal_bright_foreground
 801                .as_ref()
 802                .and_then(|color| try_parse_color(color).ok()),
 803            terminal_dim_foreground: self
 804                .terminal_dim_foreground
 805                .as_ref()
 806                .and_then(|color| try_parse_color(color).ok()),
 807            terminal_ansi_black: self
 808                .terminal_ansi_black
 809                .as_ref()
 810                .and_then(|color| try_parse_color(color).ok()),
 811            terminal_ansi_bright_black: self
 812                .terminal_ansi_bright_black
 813                .as_ref()
 814                .and_then(|color| try_parse_color(color).ok()),
 815            terminal_ansi_dim_black: self
 816                .terminal_ansi_dim_black
 817                .as_ref()
 818                .and_then(|color| try_parse_color(color).ok()),
 819            terminal_ansi_red: self
 820                .terminal_ansi_red
 821                .as_ref()
 822                .and_then(|color| try_parse_color(color).ok()),
 823            terminal_ansi_bright_red: self
 824                .terminal_ansi_bright_red
 825                .as_ref()
 826                .and_then(|color| try_parse_color(color).ok()),
 827            terminal_ansi_dim_red: self
 828                .terminal_ansi_dim_red
 829                .as_ref()
 830                .and_then(|color| try_parse_color(color).ok()),
 831            terminal_ansi_green: self
 832                .terminal_ansi_green
 833                .as_ref()
 834                .and_then(|color| try_parse_color(color).ok()),
 835            terminal_ansi_bright_green: self
 836                .terminal_ansi_bright_green
 837                .as_ref()
 838                .and_then(|color| try_parse_color(color).ok()),
 839            terminal_ansi_dim_green: self
 840                .terminal_ansi_dim_green
 841                .as_ref()
 842                .and_then(|color| try_parse_color(color).ok()),
 843            terminal_ansi_yellow: self
 844                .terminal_ansi_yellow
 845                .as_ref()
 846                .and_then(|color| try_parse_color(color).ok()),
 847            terminal_ansi_bright_yellow: self
 848                .terminal_ansi_bright_yellow
 849                .as_ref()
 850                .and_then(|color| try_parse_color(color).ok()),
 851            terminal_ansi_dim_yellow: self
 852                .terminal_ansi_dim_yellow
 853                .as_ref()
 854                .and_then(|color| try_parse_color(color).ok()),
 855            terminal_ansi_blue: self
 856                .terminal_ansi_blue
 857                .as_ref()
 858                .and_then(|color| try_parse_color(color).ok()),
 859            terminal_ansi_bright_blue: self
 860                .terminal_ansi_bright_blue
 861                .as_ref()
 862                .and_then(|color| try_parse_color(color).ok()),
 863            terminal_ansi_dim_blue: self
 864                .terminal_ansi_dim_blue
 865                .as_ref()
 866                .and_then(|color| try_parse_color(color).ok()),
 867            terminal_ansi_magenta: self
 868                .terminal_ansi_magenta
 869                .as_ref()
 870                .and_then(|color| try_parse_color(color).ok()),
 871            terminal_ansi_bright_magenta: self
 872                .terminal_ansi_bright_magenta
 873                .as_ref()
 874                .and_then(|color| try_parse_color(color).ok()),
 875            terminal_ansi_dim_magenta: self
 876                .terminal_ansi_dim_magenta
 877                .as_ref()
 878                .and_then(|color| try_parse_color(color).ok()),
 879            terminal_ansi_cyan: self
 880                .terminal_ansi_cyan
 881                .as_ref()
 882                .and_then(|color| try_parse_color(color).ok()),
 883            terminal_ansi_bright_cyan: self
 884                .terminal_ansi_bright_cyan
 885                .as_ref()
 886                .and_then(|color| try_parse_color(color).ok()),
 887            terminal_ansi_dim_cyan: self
 888                .terminal_ansi_dim_cyan
 889                .as_ref()
 890                .and_then(|color| try_parse_color(color).ok()),
 891            terminal_ansi_white: self
 892                .terminal_ansi_white
 893                .as_ref()
 894                .and_then(|color| try_parse_color(color).ok()),
 895            terminal_ansi_bright_white: self
 896                .terminal_ansi_bright_white
 897                .as_ref()
 898                .and_then(|color| try_parse_color(color).ok()),
 899            terminal_ansi_dim_white: self
 900                .terminal_ansi_dim_white
 901                .as_ref()
 902                .and_then(|color| try_parse_color(color).ok()),
 903            link_text_hover: self
 904                .link_text_hover
 905                .as_ref()
 906                .and_then(|color| try_parse_color(color).ok()),
 907        }
 908    }
 909}
 910
 911#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
 912#[serde(default)]
 913pub struct StatusColorsContent {
 914    /// Indicates some kind of conflict, like a file changed on disk while it was open, or
 915    /// merge conflicts in a Git repository.
 916    #[serde(rename = "conflict")]
 917    pub conflict: Option<String>,
 918
 919    #[serde(rename = "conflict.background")]
 920    pub conflict_background: Option<String>,
 921
 922    #[serde(rename = "conflict.border")]
 923    pub conflict_border: Option<String>,
 924
 925    /// Indicates something new, like a new file added to a Git repository.
 926    #[serde(rename = "created")]
 927    pub created: Option<String>,
 928
 929    #[serde(rename = "created.background")]
 930    pub created_background: Option<String>,
 931
 932    #[serde(rename = "created.border")]
 933    pub created_border: Option<String>,
 934
 935    /// Indicates that something no longer exists, like a deleted file.
 936    #[serde(rename = "deleted")]
 937    pub deleted: Option<String>,
 938
 939    #[serde(rename = "deleted.background")]
 940    pub deleted_background: Option<String>,
 941
 942    #[serde(rename = "deleted.border")]
 943    pub deleted_border: Option<String>,
 944
 945    /// Indicates a system error, a failed operation or a diagnostic error.
 946    #[serde(rename = "error")]
 947    pub error: Option<String>,
 948
 949    #[serde(rename = "error.background")]
 950    pub error_background: Option<String>,
 951
 952    #[serde(rename = "error.border")]
 953    pub error_border: Option<String>,
 954
 955    /// Represents a hidden status, such as a file being hidden in a file tree.
 956    #[serde(rename = "hidden")]
 957    pub hidden: Option<String>,
 958
 959    #[serde(rename = "hidden.background")]
 960    pub hidden_background: Option<String>,
 961
 962    #[serde(rename = "hidden.border")]
 963    pub hidden_border: Option<String>,
 964
 965    /// Indicates a hint or some kind of additional information.
 966    #[serde(rename = "hint")]
 967    pub hint: Option<String>,
 968
 969    #[serde(rename = "hint.background")]
 970    pub hint_background: Option<String>,
 971
 972    #[serde(rename = "hint.border")]
 973    pub hint_border: Option<String>,
 974
 975    /// Indicates that something is deliberately ignored, such as a file or operation ignored by Git.
 976    #[serde(rename = "ignored")]
 977    pub ignored: Option<String>,
 978
 979    #[serde(rename = "ignored.background")]
 980    pub ignored_background: Option<String>,
 981
 982    #[serde(rename = "ignored.border")]
 983    pub ignored_border: Option<String>,
 984
 985    /// Represents informational status updates or messages.
 986    #[serde(rename = "info")]
 987    pub info: Option<String>,
 988
 989    #[serde(rename = "info.background")]
 990    pub info_background: Option<String>,
 991
 992    #[serde(rename = "info.border")]
 993    pub info_border: Option<String>,
 994
 995    /// Indicates a changed or altered status, like a file that has been edited.
 996    #[serde(rename = "modified")]
 997    pub modified: Option<String>,
 998
 999    #[serde(rename = "modified.background")]
1000    pub modified_background: Option<String>,
1001
1002    #[serde(rename = "modified.border")]
1003    pub modified_border: Option<String>,
1004
1005    /// Indicates something that is predicted, like automatic code completion, or generated code.
1006    #[serde(rename = "predictive")]
1007    pub predictive: Option<String>,
1008
1009    #[serde(rename = "predictive.background")]
1010    pub predictive_background: Option<String>,
1011
1012    #[serde(rename = "predictive.border")]
1013    pub predictive_border: Option<String>,
1014
1015    /// Represents a renamed status, such as a file that has been renamed.
1016    #[serde(rename = "renamed")]
1017    pub renamed: Option<String>,
1018
1019    #[serde(rename = "renamed.background")]
1020    pub renamed_background: Option<String>,
1021
1022    #[serde(rename = "renamed.border")]
1023    pub renamed_border: Option<String>,
1024
1025    /// Indicates a successful operation or task completion.
1026    #[serde(rename = "success")]
1027    pub success: Option<String>,
1028
1029    #[serde(rename = "success.background")]
1030    pub success_background: Option<String>,
1031
1032    #[serde(rename = "success.border")]
1033    pub success_border: Option<String>,
1034
1035    /// Indicates some kind of unreachable status, like a block of code that can never be reached.
1036    #[serde(rename = "unreachable")]
1037    pub unreachable: Option<String>,
1038
1039    #[serde(rename = "unreachable.background")]
1040    pub unreachable_background: Option<String>,
1041
1042    #[serde(rename = "unreachable.border")]
1043    pub unreachable_border: Option<String>,
1044
1045    /// Represents a warning status, like an operation that is about to fail.
1046    #[serde(rename = "warning")]
1047    pub warning: Option<String>,
1048
1049    #[serde(rename = "warning.background")]
1050    pub warning_background: Option<String>,
1051
1052    #[serde(rename = "warning.border")]
1053    pub warning_border: Option<String>,
1054}
1055
1056impl StatusColorsContent {
1057    /// Returns a [`StatusColorsRefinement`] based on the colors in the [`StatusColorsContent`].
1058    pub fn status_colors_refinement(&self) -> StatusColorsRefinement {
1059        StatusColorsRefinement {
1060            conflict: self
1061                .conflict
1062                .as_ref()
1063                .and_then(|color| try_parse_color(color).ok()),
1064            conflict_background: self
1065                .conflict_background
1066                .as_ref()
1067                .and_then(|color| try_parse_color(color).ok()),
1068            conflict_border: self
1069                .conflict_border
1070                .as_ref()
1071                .and_then(|color| try_parse_color(color).ok()),
1072            created: self
1073                .created
1074                .as_ref()
1075                .and_then(|color| try_parse_color(color).ok()),
1076            created_background: self
1077                .created_background
1078                .as_ref()
1079                .and_then(|color| try_parse_color(color).ok()),
1080            created_border: self
1081                .created_border
1082                .as_ref()
1083                .and_then(|color| try_parse_color(color).ok()),
1084            deleted: self
1085                .deleted
1086                .as_ref()
1087                .and_then(|color| try_parse_color(color).ok()),
1088            deleted_background: self
1089                .deleted_background
1090                .as_ref()
1091                .and_then(|color| try_parse_color(color).ok()),
1092            deleted_border: self
1093                .deleted_border
1094                .as_ref()
1095                .and_then(|color| try_parse_color(color).ok()),
1096            error: self
1097                .error
1098                .as_ref()
1099                .and_then(|color| try_parse_color(color).ok()),
1100            error_background: self
1101                .error_background
1102                .as_ref()
1103                .and_then(|color| try_parse_color(color).ok()),
1104            error_border: self
1105                .error_border
1106                .as_ref()
1107                .and_then(|color| try_parse_color(color).ok()),
1108            hidden: self
1109                .hidden
1110                .as_ref()
1111                .and_then(|color| try_parse_color(color).ok()),
1112            hidden_background: self
1113                .hidden_background
1114                .as_ref()
1115                .and_then(|color| try_parse_color(color).ok()),
1116            hidden_border: self
1117                .hidden_border
1118                .as_ref()
1119                .and_then(|color| try_parse_color(color).ok()),
1120            hint: self
1121                .hint
1122                .as_ref()
1123                .and_then(|color| try_parse_color(color).ok()),
1124            hint_background: self
1125                .hint_background
1126                .as_ref()
1127                .and_then(|color| try_parse_color(color).ok()),
1128            hint_border: self
1129                .hint_border
1130                .as_ref()
1131                .and_then(|color| try_parse_color(color).ok()),
1132            ignored: self
1133                .ignored
1134                .as_ref()
1135                .and_then(|color| try_parse_color(color).ok()),
1136            ignored_background: self
1137                .ignored_background
1138                .as_ref()
1139                .and_then(|color| try_parse_color(color).ok()),
1140            ignored_border: self
1141                .ignored_border
1142                .as_ref()
1143                .and_then(|color| try_parse_color(color).ok()),
1144            info: self
1145                .info
1146                .as_ref()
1147                .and_then(|color| try_parse_color(color).ok()),
1148            info_background: self
1149                .info_background
1150                .as_ref()
1151                .and_then(|color| try_parse_color(color).ok()),
1152            info_border: self
1153                .info_border
1154                .as_ref()
1155                .and_then(|color| try_parse_color(color).ok()),
1156            modified: self
1157                .modified
1158                .as_ref()
1159                .and_then(|color| try_parse_color(color).ok()),
1160            modified_background: self
1161                .modified_background
1162                .as_ref()
1163                .and_then(|color| try_parse_color(color).ok()),
1164            modified_border: self
1165                .modified_border
1166                .as_ref()
1167                .and_then(|color| try_parse_color(color).ok()),
1168            predictive: self
1169                .predictive
1170                .as_ref()
1171                .and_then(|color| try_parse_color(color).ok()),
1172            predictive_background: self
1173                .predictive_background
1174                .as_ref()
1175                .and_then(|color| try_parse_color(color).ok()),
1176            predictive_border: self
1177                .predictive_border
1178                .as_ref()
1179                .and_then(|color| try_parse_color(color).ok()),
1180            renamed: self
1181                .renamed
1182                .as_ref()
1183                .and_then(|color| try_parse_color(color).ok()),
1184            renamed_background: self
1185                .renamed_background
1186                .as_ref()
1187                .and_then(|color| try_parse_color(color).ok()),
1188            renamed_border: self
1189                .renamed_border
1190                .as_ref()
1191                .and_then(|color| try_parse_color(color).ok()),
1192            success: self
1193                .success
1194                .as_ref()
1195                .and_then(|color| try_parse_color(color).ok()),
1196            success_background: self
1197                .success_background
1198                .as_ref()
1199                .and_then(|color| try_parse_color(color).ok()),
1200            success_border: self
1201                .success_border
1202                .as_ref()
1203                .and_then(|color| try_parse_color(color).ok()),
1204            unreachable: self
1205                .unreachable
1206                .as_ref()
1207                .and_then(|color| try_parse_color(color).ok()),
1208            unreachable_background: self
1209                .unreachable_background
1210                .as_ref()
1211                .and_then(|color| try_parse_color(color).ok()),
1212            unreachable_border: self
1213                .unreachable_border
1214                .as_ref()
1215                .and_then(|color| try_parse_color(color).ok()),
1216            warning: self
1217                .warning
1218                .as_ref()
1219                .and_then(|color| try_parse_color(color).ok()),
1220            warning_background: self
1221                .warning_background
1222                .as_ref()
1223                .and_then(|color| try_parse_color(color).ok()),
1224            warning_border: self
1225                .warning_border
1226                .as_ref()
1227                .and_then(|color| try_parse_color(color).ok()),
1228        }
1229    }
1230}
1231
1232#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
1233pub struct AccentContent(pub Option<String>);
1234
1235#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
1236pub struct PlayerColorContent {
1237    pub cursor: Option<String>,
1238    pub background: Option<String>,
1239    pub selection: Option<String>,
1240}
1241
1242#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
1243#[serde(rename_all = "snake_case")]
1244pub enum FontStyleContent {
1245    Normal,
1246    Italic,
1247    Oblique,
1248}
1249
1250impl From<FontStyleContent> for FontStyle {
1251    fn from(value: FontStyleContent) -> Self {
1252        match value {
1253            FontStyleContent::Normal => FontStyle::Normal,
1254            FontStyleContent::Italic => FontStyle::Italic,
1255            FontStyleContent::Oblique => FontStyle::Oblique,
1256        }
1257    }
1258}
1259
1260#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr)]
1261#[repr(u16)]
1262pub enum FontWeightContent {
1263    Thin = 100,
1264    ExtraLight = 200,
1265    Light = 300,
1266    Normal = 400,
1267    Medium = 500,
1268    Semibold = 600,
1269    Bold = 700,
1270    ExtraBold = 800,
1271    Black = 900,
1272}
1273
1274impl JsonSchema for FontWeightContent {
1275    fn schema_name() -> String {
1276        "FontWeightContent".to_owned()
1277    }
1278
1279    fn is_referenceable() -> bool {
1280        false
1281    }
1282
1283    fn json_schema(_: &mut SchemaGenerator) -> Schema {
1284        SchemaObject {
1285            enum_values: Some(vec![
1286                100.into(),
1287                200.into(),
1288                300.into(),
1289                400.into(),
1290                500.into(),
1291                600.into(),
1292                700.into(),
1293                800.into(),
1294                900.into(),
1295            ]),
1296            ..Default::default()
1297        }
1298        .into()
1299    }
1300}
1301
1302impl From<FontWeightContent> for FontWeight {
1303    fn from(value: FontWeightContent) -> Self {
1304        match value {
1305            FontWeightContent::Thin => FontWeight::THIN,
1306            FontWeightContent::ExtraLight => FontWeight::EXTRA_LIGHT,
1307            FontWeightContent::Light => FontWeight::LIGHT,
1308            FontWeightContent::Normal => FontWeight::NORMAL,
1309            FontWeightContent::Medium => FontWeight::MEDIUM,
1310            FontWeightContent::Semibold => FontWeight::SEMIBOLD,
1311            FontWeightContent::Bold => FontWeight::BOLD,
1312            FontWeightContent::ExtraBold => FontWeight::EXTRA_BOLD,
1313            FontWeightContent::Black => FontWeight::BLACK,
1314        }
1315    }
1316}
1317
1318#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
1319#[serde(default)]
1320pub struct HighlightStyleContent {
1321    pub color: Option<String>,
1322
1323    #[serde(deserialize_with = "treat_error_as_none")]
1324    pub background_color: Option<String>,
1325
1326    #[serde(deserialize_with = "treat_error_as_none")]
1327    pub font_style: Option<FontStyleContent>,
1328
1329    #[serde(deserialize_with = "treat_error_as_none")]
1330    pub font_weight: Option<FontWeightContent>,
1331}
1332
1333impl HighlightStyleContent {
1334    pub fn is_empty(&self) -> bool {
1335        self.color.is_none()
1336            && self.background_color.is_none()
1337            && self.font_style.is_none()
1338            && self.font_weight.is_none()
1339    }
1340}
1341
1342fn treat_error_as_none<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
1343where
1344    T: Deserialize<'de>,
1345    D: Deserializer<'de>,
1346{
1347    let value: Value = Deserialize::deserialize(deserializer)?;
1348    Ok(T::deserialize(value).ok())
1349}