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    /// Terminal ANSI background color.
 425    #[serde(rename = "terminal.ansi.background")]
 426    pub terminal_ansi_background: 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_ansi_background: self
 800                .terminal_ansi_background
 801                .as_ref()
 802                .and_then(|color| try_parse_color(color).ok()),
 803            terminal_foreground: self
 804                .terminal_foreground
 805                .as_ref()
 806                .and_then(|color| try_parse_color(color).ok()),
 807            terminal_bright_foreground: self
 808                .terminal_bright_foreground
 809                .as_ref()
 810                .and_then(|color| try_parse_color(color).ok()),
 811            terminal_dim_foreground: self
 812                .terminal_dim_foreground
 813                .as_ref()
 814                .and_then(|color| try_parse_color(color).ok()),
 815            terminal_ansi_black: self
 816                .terminal_ansi_black
 817                .as_ref()
 818                .and_then(|color| try_parse_color(color).ok()),
 819            terminal_ansi_bright_black: self
 820                .terminal_ansi_bright_black
 821                .as_ref()
 822                .and_then(|color| try_parse_color(color).ok()),
 823            terminal_ansi_dim_black: self
 824                .terminal_ansi_dim_black
 825                .as_ref()
 826                .and_then(|color| try_parse_color(color).ok()),
 827            terminal_ansi_red: self
 828                .terminal_ansi_red
 829                .as_ref()
 830                .and_then(|color| try_parse_color(color).ok()),
 831            terminal_ansi_bright_red: self
 832                .terminal_ansi_bright_red
 833                .as_ref()
 834                .and_then(|color| try_parse_color(color).ok()),
 835            terminal_ansi_dim_red: self
 836                .terminal_ansi_dim_red
 837                .as_ref()
 838                .and_then(|color| try_parse_color(color).ok()),
 839            terminal_ansi_green: self
 840                .terminal_ansi_green
 841                .as_ref()
 842                .and_then(|color| try_parse_color(color).ok()),
 843            terminal_ansi_bright_green: self
 844                .terminal_ansi_bright_green
 845                .as_ref()
 846                .and_then(|color| try_parse_color(color).ok()),
 847            terminal_ansi_dim_green: self
 848                .terminal_ansi_dim_green
 849                .as_ref()
 850                .and_then(|color| try_parse_color(color).ok()),
 851            terminal_ansi_yellow: self
 852                .terminal_ansi_yellow
 853                .as_ref()
 854                .and_then(|color| try_parse_color(color).ok()),
 855            terminal_ansi_bright_yellow: self
 856                .terminal_ansi_bright_yellow
 857                .as_ref()
 858                .and_then(|color| try_parse_color(color).ok()),
 859            terminal_ansi_dim_yellow: self
 860                .terminal_ansi_dim_yellow
 861                .as_ref()
 862                .and_then(|color| try_parse_color(color).ok()),
 863            terminal_ansi_blue: self
 864                .terminal_ansi_blue
 865                .as_ref()
 866                .and_then(|color| try_parse_color(color).ok()),
 867            terminal_ansi_bright_blue: self
 868                .terminal_ansi_bright_blue
 869                .as_ref()
 870                .and_then(|color| try_parse_color(color).ok()),
 871            terminal_ansi_dim_blue: self
 872                .terminal_ansi_dim_blue
 873                .as_ref()
 874                .and_then(|color| try_parse_color(color).ok()),
 875            terminal_ansi_magenta: self
 876                .terminal_ansi_magenta
 877                .as_ref()
 878                .and_then(|color| try_parse_color(color).ok()),
 879            terminal_ansi_bright_magenta: self
 880                .terminal_ansi_bright_magenta
 881                .as_ref()
 882                .and_then(|color| try_parse_color(color).ok()),
 883            terminal_ansi_dim_magenta: self
 884                .terminal_ansi_dim_magenta
 885                .as_ref()
 886                .and_then(|color| try_parse_color(color).ok()),
 887            terminal_ansi_cyan: self
 888                .terminal_ansi_cyan
 889                .as_ref()
 890                .and_then(|color| try_parse_color(color).ok()),
 891            terminal_ansi_bright_cyan: self
 892                .terminal_ansi_bright_cyan
 893                .as_ref()
 894                .and_then(|color| try_parse_color(color).ok()),
 895            terminal_ansi_dim_cyan: self
 896                .terminal_ansi_dim_cyan
 897                .as_ref()
 898                .and_then(|color| try_parse_color(color).ok()),
 899            terminal_ansi_white: self
 900                .terminal_ansi_white
 901                .as_ref()
 902                .and_then(|color| try_parse_color(color).ok()),
 903            terminal_ansi_bright_white: self
 904                .terminal_ansi_bright_white
 905                .as_ref()
 906                .and_then(|color| try_parse_color(color).ok()),
 907            terminal_ansi_dim_white: self
 908                .terminal_ansi_dim_white
 909                .as_ref()
 910                .and_then(|color| try_parse_color(color).ok()),
 911            link_text_hover: self
 912                .link_text_hover
 913                .as_ref()
 914                .and_then(|color| try_parse_color(color).ok()),
 915        }
 916    }
 917}
 918
 919#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
 920#[serde(default)]
 921pub struct StatusColorsContent {
 922    /// Indicates some kind of conflict, like a file changed on disk while it was open, or
 923    /// merge conflicts in a Git repository.
 924    #[serde(rename = "conflict")]
 925    pub conflict: Option<String>,
 926
 927    #[serde(rename = "conflict.background")]
 928    pub conflict_background: Option<String>,
 929
 930    #[serde(rename = "conflict.border")]
 931    pub conflict_border: Option<String>,
 932
 933    /// Indicates something new, like a new file added to a Git repository.
 934    #[serde(rename = "created")]
 935    pub created: Option<String>,
 936
 937    #[serde(rename = "created.background")]
 938    pub created_background: Option<String>,
 939
 940    #[serde(rename = "created.border")]
 941    pub created_border: Option<String>,
 942
 943    /// Indicates that something no longer exists, like a deleted file.
 944    #[serde(rename = "deleted")]
 945    pub deleted: Option<String>,
 946
 947    #[serde(rename = "deleted.background")]
 948    pub deleted_background: Option<String>,
 949
 950    #[serde(rename = "deleted.border")]
 951    pub deleted_border: Option<String>,
 952
 953    /// Indicates a system error, a failed operation or a diagnostic error.
 954    #[serde(rename = "error")]
 955    pub error: Option<String>,
 956
 957    #[serde(rename = "error.background")]
 958    pub error_background: Option<String>,
 959
 960    #[serde(rename = "error.border")]
 961    pub error_border: Option<String>,
 962
 963    /// Represents a hidden status, such as a file being hidden in a file tree.
 964    #[serde(rename = "hidden")]
 965    pub hidden: Option<String>,
 966
 967    #[serde(rename = "hidden.background")]
 968    pub hidden_background: Option<String>,
 969
 970    #[serde(rename = "hidden.border")]
 971    pub hidden_border: Option<String>,
 972
 973    /// Indicates a hint or some kind of additional information.
 974    #[serde(rename = "hint")]
 975    pub hint: Option<String>,
 976
 977    #[serde(rename = "hint.background")]
 978    pub hint_background: Option<String>,
 979
 980    #[serde(rename = "hint.border")]
 981    pub hint_border: Option<String>,
 982
 983    /// Indicates that something is deliberately ignored, such as a file or operation ignored by Git.
 984    #[serde(rename = "ignored")]
 985    pub ignored: Option<String>,
 986
 987    #[serde(rename = "ignored.background")]
 988    pub ignored_background: Option<String>,
 989
 990    #[serde(rename = "ignored.border")]
 991    pub ignored_border: Option<String>,
 992
 993    /// Represents informational status updates or messages.
 994    #[serde(rename = "info")]
 995    pub info: Option<String>,
 996
 997    #[serde(rename = "info.background")]
 998    pub info_background: Option<String>,
 999
1000    #[serde(rename = "info.border")]
1001    pub info_border: Option<String>,
1002
1003    /// Indicates a changed or altered status, like a file that has been edited.
1004    #[serde(rename = "modified")]
1005    pub modified: Option<String>,
1006
1007    #[serde(rename = "modified.background")]
1008    pub modified_background: Option<String>,
1009
1010    #[serde(rename = "modified.border")]
1011    pub modified_border: Option<String>,
1012
1013    /// Indicates something that is predicted, like automatic code completion, or generated code.
1014    #[serde(rename = "predictive")]
1015    pub predictive: Option<String>,
1016
1017    #[serde(rename = "predictive.background")]
1018    pub predictive_background: Option<String>,
1019
1020    #[serde(rename = "predictive.border")]
1021    pub predictive_border: Option<String>,
1022
1023    /// Represents a renamed status, such as a file that has been renamed.
1024    #[serde(rename = "renamed")]
1025    pub renamed: Option<String>,
1026
1027    #[serde(rename = "renamed.background")]
1028    pub renamed_background: Option<String>,
1029
1030    #[serde(rename = "renamed.border")]
1031    pub renamed_border: Option<String>,
1032
1033    /// Indicates a successful operation or task completion.
1034    #[serde(rename = "success")]
1035    pub success: Option<String>,
1036
1037    #[serde(rename = "success.background")]
1038    pub success_background: Option<String>,
1039
1040    #[serde(rename = "success.border")]
1041    pub success_border: Option<String>,
1042
1043    /// Indicates some kind of unreachable status, like a block of code that can never be reached.
1044    #[serde(rename = "unreachable")]
1045    pub unreachable: Option<String>,
1046
1047    #[serde(rename = "unreachable.background")]
1048    pub unreachable_background: Option<String>,
1049
1050    #[serde(rename = "unreachable.border")]
1051    pub unreachable_border: Option<String>,
1052
1053    /// Represents a warning status, like an operation that is about to fail.
1054    #[serde(rename = "warning")]
1055    pub warning: Option<String>,
1056
1057    #[serde(rename = "warning.background")]
1058    pub warning_background: Option<String>,
1059
1060    #[serde(rename = "warning.border")]
1061    pub warning_border: Option<String>,
1062}
1063
1064impl StatusColorsContent {
1065    /// Returns a [`StatusColorsRefinement`] based on the colors in the [`StatusColorsContent`].
1066    pub fn status_colors_refinement(&self) -> StatusColorsRefinement {
1067        StatusColorsRefinement {
1068            conflict: self
1069                .conflict
1070                .as_ref()
1071                .and_then(|color| try_parse_color(color).ok()),
1072            conflict_background: self
1073                .conflict_background
1074                .as_ref()
1075                .and_then(|color| try_parse_color(color).ok()),
1076            conflict_border: self
1077                .conflict_border
1078                .as_ref()
1079                .and_then(|color| try_parse_color(color).ok()),
1080            created: self
1081                .created
1082                .as_ref()
1083                .and_then(|color| try_parse_color(color).ok()),
1084            created_background: self
1085                .created_background
1086                .as_ref()
1087                .and_then(|color| try_parse_color(color).ok()),
1088            created_border: self
1089                .created_border
1090                .as_ref()
1091                .and_then(|color| try_parse_color(color).ok()),
1092            deleted: self
1093                .deleted
1094                .as_ref()
1095                .and_then(|color| try_parse_color(color).ok()),
1096            deleted_background: self
1097                .deleted_background
1098                .as_ref()
1099                .and_then(|color| try_parse_color(color).ok()),
1100            deleted_border: self
1101                .deleted_border
1102                .as_ref()
1103                .and_then(|color| try_parse_color(color).ok()),
1104            error: self
1105                .error
1106                .as_ref()
1107                .and_then(|color| try_parse_color(color).ok()),
1108            error_background: self
1109                .error_background
1110                .as_ref()
1111                .and_then(|color| try_parse_color(color).ok()),
1112            error_border: self
1113                .error_border
1114                .as_ref()
1115                .and_then(|color| try_parse_color(color).ok()),
1116            hidden: self
1117                .hidden
1118                .as_ref()
1119                .and_then(|color| try_parse_color(color).ok()),
1120            hidden_background: self
1121                .hidden_background
1122                .as_ref()
1123                .and_then(|color| try_parse_color(color).ok()),
1124            hidden_border: self
1125                .hidden_border
1126                .as_ref()
1127                .and_then(|color| try_parse_color(color).ok()),
1128            hint: self
1129                .hint
1130                .as_ref()
1131                .and_then(|color| try_parse_color(color).ok()),
1132            hint_background: self
1133                .hint_background
1134                .as_ref()
1135                .and_then(|color| try_parse_color(color).ok()),
1136            hint_border: self
1137                .hint_border
1138                .as_ref()
1139                .and_then(|color| try_parse_color(color).ok()),
1140            ignored: self
1141                .ignored
1142                .as_ref()
1143                .and_then(|color| try_parse_color(color).ok()),
1144            ignored_background: self
1145                .ignored_background
1146                .as_ref()
1147                .and_then(|color| try_parse_color(color).ok()),
1148            ignored_border: self
1149                .ignored_border
1150                .as_ref()
1151                .and_then(|color| try_parse_color(color).ok()),
1152            info: self
1153                .info
1154                .as_ref()
1155                .and_then(|color| try_parse_color(color).ok()),
1156            info_background: self
1157                .info_background
1158                .as_ref()
1159                .and_then(|color| try_parse_color(color).ok()),
1160            info_border: self
1161                .info_border
1162                .as_ref()
1163                .and_then(|color| try_parse_color(color).ok()),
1164            modified: self
1165                .modified
1166                .as_ref()
1167                .and_then(|color| try_parse_color(color).ok()),
1168            modified_background: self
1169                .modified_background
1170                .as_ref()
1171                .and_then(|color| try_parse_color(color).ok()),
1172            modified_border: self
1173                .modified_border
1174                .as_ref()
1175                .and_then(|color| try_parse_color(color).ok()),
1176            predictive: self
1177                .predictive
1178                .as_ref()
1179                .and_then(|color| try_parse_color(color).ok()),
1180            predictive_background: self
1181                .predictive_background
1182                .as_ref()
1183                .and_then(|color| try_parse_color(color).ok()),
1184            predictive_border: self
1185                .predictive_border
1186                .as_ref()
1187                .and_then(|color| try_parse_color(color).ok()),
1188            renamed: self
1189                .renamed
1190                .as_ref()
1191                .and_then(|color| try_parse_color(color).ok()),
1192            renamed_background: self
1193                .renamed_background
1194                .as_ref()
1195                .and_then(|color| try_parse_color(color).ok()),
1196            renamed_border: self
1197                .renamed_border
1198                .as_ref()
1199                .and_then(|color| try_parse_color(color).ok()),
1200            success: self
1201                .success
1202                .as_ref()
1203                .and_then(|color| try_parse_color(color).ok()),
1204            success_background: self
1205                .success_background
1206                .as_ref()
1207                .and_then(|color| try_parse_color(color).ok()),
1208            success_border: self
1209                .success_border
1210                .as_ref()
1211                .and_then(|color| try_parse_color(color).ok()),
1212            unreachable: self
1213                .unreachable
1214                .as_ref()
1215                .and_then(|color| try_parse_color(color).ok()),
1216            unreachable_background: self
1217                .unreachable_background
1218                .as_ref()
1219                .and_then(|color| try_parse_color(color).ok()),
1220            unreachable_border: self
1221                .unreachable_border
1222                .as_ref()
1223                .and_then(|color| try_parse_color(color).ok()),
1224            warning: self
1225                .warning
1226                .as_ref()
1227                .and_then(|color| try_parse_color(color).ok()),
1228            warning_background: self
1229                .warning_background
1230                .as_ref()
1231                .and_then(|color| try_parse_color(color).ok()),
1232            warning_border: self
1233                .warning_border
1234                .as_ref()
1235                .and_then(|color| try_parse_color(color).ok()),
1236        }
1237    }
1238}
1239
1240#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
1241pub struct AccentContent(pub Option<String>);
1242
1243#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
1244pub struct PlayerColorContent {
1245    pub cursor: Option<String>,
1246    pub background: Option<String>,
1247    pub selection: Option<String>,
1248}
1249
1250#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
1251#[serde(rename_all = "snake_case")]
1252pub enum FontStyleContent {
1253    Normal,
1254    Italic,
1255    Oblique,
1256}
1257
1258impl From<FontStyleContent> for FontStyle {
1259    fn from(value: FontStyleContent) -> Self {
1260        match value {
1261            FontStyleContent::Normal => FontStyle::Normal,
1262            FontStyleContent::Italic => FontStyle::Italic,
1263            FontStyleContent::Oblique => FontStyle::Oblique,
1264        }
1265    }
1266}
1267
1268#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr)]
1269#[repr(u16)]
1270pub enum FontWeightContent {
1271    Thin = 100,
1272    ExtraLight = 200,
1273    Light = 300,
1274    Normal = 400,
1275    Medium = 500,
1276    Semibold = 600,
1277    Bold = 700,
1278    ExtraBold = 800,
1279    Black = 900,
1280}
1281
1282impl JsonSchema for FontWeightContent {
1283    fn schema_name() -> String {
1284        "FontWeightContent".to_owned()
1285    }
1286
1287    fn is_referenceable() -> bool {
1288        false
1289    }
1290
1291    fn json_schema(_: &mut SchemaGenerator) -> Schema {
1292        SchemaObject {
1293            enum_values: Some(vec![
1294                100.into(),
1295                200.into(),
1296                300.into(),
1297                400.into(),
1298                500.into(),
1299                600.into(),
1300                700.into(),
1301                800.into(),
1302                900.into(),
1303            ]),
1304            ..Default::default()
1305        }
1306        .into()
1307    }
1308}
1309
1310impl From<FontWeightContent> for FontWeight {
1311    fn from(value: FontWeightContent) -> Self {
1312        match value {
1313            FontWeightContent::Thin => FontWeight::THIN,
1314            FontWeightContent::ExtraLight => FontWeight::EXTRA_LIGHT,
1315            FontWeightContent::Light => FontWeight::LIGHT,
1316            FontWeightContent::Normal => FontWeight::NORMAL,
1317            FontWeightContent::Medium => FontWeight::MEDIUM,
1318            FontWeightContent::Semibold => FontWeight::SEMIBOLD,
1319            FontWeightContent::Bold => FontWeight::BOLD,
1320            FontWeightContent::ExtraBold => FontWeight::EXTRA_BOLD,
1321            FontWeightContent::Black => FontWeight::BLACK,
1322        }
1323    }
1324}
1325
1326#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
1327#[serde(default)]
1328pub struct HighlightStyleContent {
1329    pub color: Option<String>,
1330
1331    #[serde(deserialize_with = "treat_error_as_none")]
1332    pub background_color: Option<String>,
1333
1334    #[serde(deserialize_with = "treat_error_as_none")]
1335    pub font_style: Option<FontStyleContent>,
1336
1337    #[serde(deserialize_with = "treat_error_as_none")]
1338    pub font_weight: Option<FontWeightContent>,
1339}
1340
1341impl HighlightStyleContent {
1342    pub fn is_empty(&self) -> bool {
1343        self.color.is_none()
1344            && self.background_color.is_none()
1345            && self.font_style.is_none()
1346            && self.font_weight.is_none()
1347    }
1348}
1349
1350fn treat_error_as_none<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
1351where
1352    T: Deserialize<'de>,
1353    D: Deserializer<'de>,
1354{
1355    let value: Value = Deserialize::deserialize(deserializer)?;
1356    Ok(T::deserialize(value).ok())
1357}