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