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