schema.rs

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