schema.rs

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