use collections::{HashMap, IndexMap}; use gpui::{FontFallbacks, FontFeatures, FontStyle, FontWeight, SharedString}; use schemars::{JsonSchema, JsonSchema_repr}; use serde::{Deserialize, Deserializer, Serialize}; use serde_json::Value; use serde_repr::{Deserialize_repr, Serialize_repr}; use settings_macros::{MergeFrom, with_fallible_options}; use std::{fmt::Display, sync::Arc}; use crate::serialize_f32_with_two_decimal_places; /// Settings for rendering text in UI and text buffers. #[with_fallible_options] #[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom)] pub struct ThemeSettingsContent { /// The default font size for text in the UI. #[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")] pub ui_font_size: Option, /// The name of a font to use for rendering in the UI. pub ui_font_family: Option, /// The font fallbacks to use for rendering in the UI. #[schemars(default = "default_font_fallbacks")] #[schemars(extend("uniqueItems" = true))] pub ui_font_fallbacks: Option>, /// The OpenType features to enable for text in the UI. #[schemars(default = "default_font_features")] pub ui_font_features: Option, /// The weight of the UI font in CSS units from 100 to 900. #[schemars(default = "default_buffer_font_weight")] pub ui_font_weight: Option, /// The name of a font to use for rendering in text buffers. pub buffer_font_family: Option, /// The font fallbacks to use for rendering in text buffers. #[schemars(extend("uniqueItems" = true))] pub buffer_font_fallbacks: Option>, /// The default font size for rendering in text buffers. #[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")] pub buffer_font_size: Option, /// The weight of the editor font in CSS units from 100 to 900. #[schemars(default = "default_buffer_font_weight")] pub buffer_font_weight: Option, /// The buffer's line height. pub buffer_line_height: Option, /// The OpenType features to enable for rendering in text buffers. #[schemars(default = "default_font_features")] pub buffer_font_features: Option, /// The font size for agent responses in the agent panel. Falls back to the UI font size if unset. #[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")] pub agent_ui_font_size: Option, /// The font size for user messages in the agent panel. #[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")] pub agent_buffer_font_size: Option, /// The name of the Zed theme to use. pub theme: Option, /// The name of the icon theme to use. pub icon_theme: Option, /// UNSTABLE: Expect many elements to be broken. /// // Controls the density of the UI. #[serde(rename = "unstable.ui_density")] pub ui_density: Option, /// How much to fade out unused code. #[schemars(range(min = 0.0, max = 0.9))] pub unnecessary_code_fade: Option, /// EXPERIMENTAL: Overrides for the current theme. /// /// These values will override the ones on the current theme specified in `theme`. #[serde(rename = "experimental.theme_overrides")] pub experimental_theme_overrides: Option, /// Overrides per theme /// /// These values will override the ones on the specified theme #[serde(default)] pub theme_overrides: HashMap, } #[derive( Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, PartialOrd, derive_more::FromStr, )] #[serde(transparent)] pub struct CodeFade(#[serde(serialize_with = "serialize_f32_with_two_decimal_places")] pub f32); impl Display for CodeFade { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:.2}", self.0) } } impl From for CodeFade { fn from(x: f32) -> Self { Self(x) } } fn default_font_features() -> Option { Some(FontFeatures::default()) } fn default_font_fallbacks() -> Option { Some(FontFallbacks::default()) } fn default_buffer_font_weight() -> Option { Some(FontWeight::default()) } /// Represents the selection of a theme, which can be either static or dynamic. #[derive( Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq, strum::EnumDiscriminants, )] #[strum_discriminants(derive(strum::VariantArray, strum::VariantNames, strum::FromRepr))] #[serde(untagged)] pub enum ThemeSelection { /// A static theme selection, represented by a single theme name. Static(ThemeName), /// A dynamic theme selection, which can change based the [ThemeMode]. Dynamic { /// The mode used to determine which theme to use. #[serde(default)] mode: ThemeAppearanceMode, /// The theme to use for light mode. light: ThemeName, /// The theme to use for dark mode. dark: ThemeName, }, } /// Represents the selection of an icon theme, which can be either static or dynamic. #[derive( Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq, strum::EnumDiscriminants, )] #[strum_discriminants(derive(strum::VariantArray, strum::VariantNames, strum::FromRepr))] #[serde(untagged)] pub enum IconThemeSelection { /// A static icon theme selection, represented by a single icon theme name. Static(IconThemeName), /// A dynamic icon theme selection, which can change based on the [`ThemeMode`]. Dynamic { /// The mode used to determine which theme to use. #[serde(default)] mode: ThemeAppearanceMode, /// The icon theme to use for light mode. light: IconThemeName, /// The icon theme to use for dark mode. dark: IconThemeName, }, } /// The mode use to select a theme. /// /// `Light` and `Dark` will select their respective themes. /// /// `System` will select the theme based on the system's appearance. #[derive( Debug, PartialEq, Eq, Clone, Copy, Default, Serialize, Deserialize, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum ThemeAppearanceMode { /// Use the specified `light` theme. Light, /// Use the specified `dark` theme. Dark, /// Use the theme based on the system's appearance. #[default] System, } /// Specifies the density of the UI. /// Note: This setting is still experimental. See [this tracking issue](https://github.com/zed-industries/zed/issues/18078) #[derive( Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Serialize, Deserialize, JsonSchema, MergeFrom, )] #[serde(rename_all = "snake_case")] pub enum UiDensity { /// A denser UI with tighter spacing and smaller elements. #[serde(alias = "compact")] Compact, #[default] #[serde(alias = "default")] /// The default UI density. Default, #[serde(alias = "comfortable")] /// A looser UI with more spacing and larger elements. Comfortable, } impl UiDensity { /// The spacing ratio of a given density. /// TODO: Standardize usage throughout the app or remove pub fn spacing_ratio(self) -> f32 { match self { UiDensity::Compact => 0.75, UiDensity::Default => 1.0, UiDensity::Comfortable => 1.25, } } } /// Font family name. #[with_fallible_options] #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)] #[serde(transparent)] pub struct FontFamilyName(pub Arc); impl AsRef for FontFamilyName { fn as_ref(&self) -> &str { &self.0 } } impl From for FontFamilyName { fn from(value: SharedString) -> Self { Self(Arc::from(value)) } } impl From for SharedString { fn from(value: FontFamilyName) -> Self { SharedString::new(value.0) } } impl From for FontFamilyName { fn from(value: String) -> Self { Self(Arc::from(value)) } } impl From for String { fn from(value: FontFamilyName) -> Self { value.0.to_string() } } /// The buffer's line height. #[derive( Clone, Copy, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom, Default, strum::EnumDiscriminants, )] #[strum_discriminants(derive(strum::VariantArray, strum::VariantNames, strum::FromRepr))] #[serde(rename_all = "snake_case")] pub enum BufferLineHeight { /// A less dense line height. #[default] Comfortable, /// The default line height. Standard, /// A custom line height, where 1.0 is the font's height. Must be at least 1.0. Custom(#[serde(deserialize_with = "deserialize_line_height")] f32), } fn deserialize_line_height<'de, D>(deserializer: D) -> Result where D: serde::Deserializer<'de>, { let value = f32::deserialize(deserializer)?; if value < 1.0 { return Err(serde::de::Error::custom( "buffer_line_height.custom must be at least 1.0", )); } Ok(value) } /// The content of a serialized theme. #[with_fallible_options] #[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)] #[serde(default)] pub struct ThemeStyleContent { #[serde(rename = "background.appearance")] pub window_background_appearance: Option, #[serde(default)] pub accents: Vec, #[serde(flatten, default)] pub colors: ThemeColorsContent, #[serde(flatten, default)] pub status: StatusColorsContent, #[serde(default)] pub players: Vec, /// The styles for syntax nodes. #[serde(default)] pub syntax: IndexMap, } #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)] pub struct AccentContent(pub Option); #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)] pub struct PlayerColorContent { pub cursor: Option, pub background: Option, pub selection: Option, } /// Theme name. #[with_fallible_options] #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)] #[serde(transparent)] pub struct ThemeName(pub Arc); /// Icon Theme Name #[with_fallible_options] #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)] #[serde(transparent)] pub struct IconThemeName(pub Arc); #[with_fallible_options] #[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)] #[serde(default)] pub struct ThemeColorsContent { /// Border color. Used for most borders, is usually a high contrast color. #[serde(rename = "border")] pub border: Option, /// Border color. Used for deemphasized borders, like a visual divider between two sections #[serde(rename = "border.variant")] pub border_variant: Option, /// Border color. Used for focused elements, like keyboard focused list item. #[serde(rename = "border.focused")] pub border_focused: Option, /// Border color. Used for selected elements, like an active search filter or selected checkbox. #[serde(rename = "border.selected")] pub border_selected: Option, /// Border color. Used for transparent borders. Used for placeholder borders when an element gains a border on state change. #[serde(rename = "border.transparent")] pub border_transparent: Option, /// Border color. Used for disabled elements, like a disabled input or button. #[serde(rename = "border.disabled")] pub border_disabled: Option, /// Background color. Used for elevated surfaces, like a context menu, popup, or dialog. #[serde(rename = "elevated_surface.background")] pub elevated_surface_background: Option, /// Background Color. Used for grounded surfaces like a panel or tab. #[serde(rename = "surface.background")] pub surface_background: Option, /// Background Color. Used for the app background and blank panels or windows. #[serde(rename = "background")] pub background: Option, /// Background Color. Used for the background of an element that should have a different background than the surface it's on. /// /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons... /// /// For an element that should have the same background as the surface it's on, use `ghost_element_background`. #[serde(rename = "element.background")] pub element_background: Option, /// Background Color. Used for the hover state of an element that should have a different background than the surface it's on. /// /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen. #[serde(rename = "element.hover")] pub element_hover: Option, /// Background Color. Used for the active state of an element that should have a different background than the surface it's on. /// /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressed. #[serde(rename = "element.active")] pub element_active: Option, /// Background Color. Used for the selected state of an element that should have a different background than the surface it's on. /// /// Selected states are triggered by the element being selected (or "activated") by the user. /// /// This could include a selected checkbox, a toggleable button that is toggled on, etc. #[serde(rename = "element.selected")] pub element_selected: Option, /// Background Color. Used for the disabled state of an element that should have a different background than the surface it's on. /// /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input. #[serde(rename = "element.disabled")] pub element_disabled: Option, /// Background Color. Used for the background of selections in a UI element. #[serde(rename = "element.selection_background")] pub element_selection_background: Option, /// Background Color. Used for the area that shows where a dragged element will be dropped. #[serde(rename = "drop_target.background")] pub drop_target_background: Option, /// Border Color. Used for the border that shows where a dragged element will be dropped. #[serde(rename = "drop_target.border")] pub drop_target_border: Option, /// Used for the background of a ghost element that should have the same background as the surface it's on. /// /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons... /// /// For an element that should have a different background than the surface it's on, use `element_background`. #[serde(rename = "ghost_element.background")] pub ghost_element_background: Option, /// Background Color. Used for the hover state of a ghost element that should have the same background as the surface it's on. /// /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen. #[serde(rename = "ghost_element.hover")] pub ghost_element_hover: Option, /// Background Color. Used for the active state of a ghost element that should have the same background as the surface it's on. /// /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressed. #[serde(rename = "ghost_element.active")] pub ghost_element_active: Option, /// Background Color. Used for the selected state of a ghost element that should have the same background as the surface it's on. /// /// Selected states are triggered by the element being selected (or "activated") by the user. /// /// This could include a selected checkbox, a toggleable button that is toggled on, etc. #[serde(rename = "ghost_element.selected")] pub ghost_element_selected: Option, /// Background Color. Used for the disabled state of a ghost element that should have the same background as the surface it's on. /// /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input. #[serde(rename = "ghost_element.disabled")] pub ghost_element_disabled: Option, /// Text Color. Default text color used for most text. #[serde(rename = "text")] pub text: Option, /// Text Color. Color of muted or deemphasized text. It is a subdued version of the standard text color. #[serde(rename = "text.muted")] pub text_muted: Option, /// Text Color. Color of the placeholder text typically shown in input fields to guide the user to enter valid data. #[serde(rename = "text.placeholder")] pub text_placeholder: Option, /// Text Color. Color used for text denoting disabled elements. Typically, the color is faded or grayed out to emphasize the disabled state. #[serde(rename = "text.disabled")] pub text_disabled: Option, /// Text Color. Color used for emphasis or highlighting certain text, like an active filter or a matched character in a search. #[serde(rename = "text.accent")] pub text_accent: Option, /// Fill Color. Used for the default fill color of an icon. #[serde(rename = "icon")] pub icon: Option, /// Fill Color. Used for the muted or deemphasized fill color of an icon. /// /// 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. #[serde(rename = "icon.muted")] pub icon_muted: Option, /// Fill Color. Used for the disabled fill color of an icon. /// /// Disabled states are shown when a user cannot interact with an element, like a icon button. #[serde(rename = "icon.disabled")] pub icon_disabled: Option, /// Fill Color. Used for the placeholder fill color of an icon. /// /// This might be used to show an icon in an input that disappears when the user enters text. #[serde(rename = "icon.placeholder")] pub icon_placeholder: Option, /// Fill Color. Used for the accent fill color of an icon. /// /// This might be used to show when a toggleable icon button is selected. #[serde(rename = "icon.accent")] pub icon_accent: Option, /// Color used to accent some of the debuggers elements /// Only accent breakpoint & breakpoint related symbols right now #[serde(rename = "debugger.accent")] pub debugger_accent: Option, #[serde(rename = "status_bar.background")] pub status_bar_background: Option, #[serde(rename = "title_bar.background")] pub title_bar_background: Option, #[serde(rename = "title_bar.inactive_background")] pub title_bar_inactive_background: Option, #[serde(rename = "toolbar.background")] pub toolbar_background: Option, #[serde(rename = "tab_bar.background")] pub tab_bar_background: Option, #[serde(rename = "tab.inactive_background")] pub tab_inactive_background: Option, #[serde(rename = "tab.active_background")] pub tab_active_background: Option, #[serde(rename = "search.match_background")] pub search_match_background: Option, #[serde(rename = "panel.background")] pub panel_background: Option, #[serde(rename = "panel.focused_border")] pub panel_focused_border: Option, #[serde(rename = "panel.indent_guide")] pub panel_indent_guide: Option, #[serde(rename = "panel.indent_guide_hover")] pub panel_indent_guide_hover: Option, #[serde(rename = "panel.indent_guide_active")] pub panel_indent_guide_active: Option, #[serde(rename = "panel.overlay_background")] pub panel_overlay_background: Option, #[serde(rename = "panel.overlay_hover")] pub panel_overlay_hover: Option, #[serde(rename = "pane.focused_border")] pub pane_focused_border: Option, #[serde(rename = "pane_group.border")] pub pane_group_border: Option, /// The deprecated version of `scrollbar.thumb.background`. /// /// Don't use this field. #[serde(rename = "scrollbar_thumb.background", skip_serializing)] #[schemars(skip)] pub deprecated_scrollbar_thumb_background: Option, /// The color of the scrollbar thumb. #[serde(rename = "scrollbar.thumb.background")] pub scrollbar_thumb_background: Option, /// The color of the scrollbar thumb when hovered over. #[serde(rename = "scrollbar.thumb.hover_background")] pub scrollbar_thumb_hover_background: Option, /// The color of the scrollbar thumb whilst being actively dragged. #[serde(rename = "scrollbar.thumb.active_background")] pub scrollbar_thumb_active_background: Option, /// The border color of the scrollbar thumb. #[serde(rename = "scrollbar.thumb.border")] pub scrollbar_thumb_border: Option, /// The background color of the scrollbar track. #[serde(rename = "scrollbar.track.background")] pub scrollbar_track_background: Option, /// The border color of the scrollbar track. #[serde(rename = "scrollbar.track.border")] pub scrollbar_track_border: Option, /// The color of the minimap thumb. #[serde(rename = "minimap.thumb.background")] pub minimap_thumb_background: Option, /// The color of the minimap thumb when hovered over. #[serde(rename = "minimap.thumb.hover_background")] pub minimap_thumb_hover_background: Option, /// The color of the minimap thumb whilst being actively dragged. #[serde(rename = "minimap.thumb.active_background")] pub minimap_thumb_active_background: Option, /// The border color of the minimap thumb. #[serde(rename = "minimap.thumb.border")] pub minimap_thumb_border: Option, #[serde(rename = "editor.foreground")] pub editor_foreground: Option, #[serde(rename = "editor.background")] pub editor_background: Option, #[serde(rename = "editor.gutter.background")] pub editor_gutter_background: Option, #[serde(rename = "editor.subheader.background")] pub editor_subheader_background: Option, #[serde(rename = "editor.active_line.background")] pub editor_active_line_background: Option, #[serde(rename = "editor.highlighted_line.background")] pub editor_highlighted_line_background: Option, /// Background of active line of debugger #[serde(rename = "editor.debugger_active_line.background")] pub editor_debugger_active_line_background: Option, /// Text Color. Used for the text of the line number in the editor gutter. #[serde(rename = "editor.line_number")] pub editor_line_number: Option, /// Text Color. Used for the text of the line number in the editor gutter when the line is highlighted. #[serde(rename = "editor.active_line_number")] pub editor_active_line_number: Option, /// Text Color. Used for the text of the line number in the editor gutter when the line is hovered over. #[serde(rename = "editor.hover_line_number")] pub editor_hover_line_number: Option, /// Text Color. Used to mark invisible characters in the editor. /// /// Example: spaces, tabs, carriage returns, etc. #[serde(rename = "editor.invisible")] pub editor_invisible: Option, #[serde(rename = "editor.wrap_guide")] pub editor_wrap_guide: Option, #[serde(rename = "editor.active_wrap_guide")] pub editor_active_wrap_guide: Option, #[serde(rename = "editor.indent_guide")] pub editor_indent_guide: Option, #[serde(rename = "editor.indent_guide_active")] pub editor_indent_guide_active: Option, /// Read-access of a symbol, like reading a variable. /// /// A document highlight is a range inside a text document which deserves /// special attention. Usually a document highlight is visualized by changing /// the background color of its range. #[serde(rename = "editor.document_highlight.read_background")] pub editor_document_highlight_read_background: Option, /// Read-access of a symbol, like reading a variable. /// /// A document highlight is a range inside a text document which deserves /// special attention. Usually a document highlight is visualized by changing /// the background color of its range. #[serde(rename = "editor.document_highlight.write_background")] pub editor_document_highlight_write_background: Option, /// Highlighted brackets background color. /// /// Matching brackets in the cursor scope are highlighted with this background color. #[serde(rename = "editor.document_highlight.bracket_background")] pub editor_document_highlight_bracket_background: Option, /// Terminal background color. #[serde(rename = "terminal.background")] pub terminal_background: Option, /// Terminal foreground color. #[serde(rename = "terminal.foreground")] pub terminal_foreground: Option, /// Terminal ANSI background color. #[serde(rename = "terminal.ansi.background")] pub terminal_ansi_background: Option, /// Bright terminal foreground color. #[serde(rename = "terminal.bright_foreground")] pub terminal_bright_foreground: Option, /// Dim terminal foreground color. #[serde(rename = "terminal.dim_foreground")] pub terminal_dim_foreground: Option, /// Black ANSI terminal color. #[serde(rename = "terminal.ansi.black")] pub terminal_ansi_black: Option, /// Bright black ANSI terminal color. #[serde(rename = "terminal.ansi.bright_black")] pub terminal_ansi_bright_black: Option, /// Dim black ANSI terminal color. #[serde(rename = "terminal.ansi.dim_black")] pub terminal_ansi_dim_black: Option, /// Red ANSI terminal color. #[serde(rename = "terminal.ansi.red")] pub terminal_ansi_red: Option, /// Bright red ANSI terminal color. #[serde(rename = "terminal.ansi.bright_red")] pub terminal_ansi_bright_red: Option, /// Dim red ANSI terminal color. #[serde(rename = "terminal.ansi.dim_red")] pub terminal_ansi_dim_red: Option, /// Green ANSI terminal color. #[serde(rename = "terminal.ansi.green")] pub terminal_ansi_green: Option, /// Bright green ANSI terminal color. #[serde(rename = "terminal.ansi.bright_green")] pub terminal_ansi_bright_green: Option, /// Dim green ANSI terminal color. #[serde(rename = "terminal.ansi.dim_green")] pub terminal_ansi_dim_green: Option, /// Yellow ANSI terminal color. #[serde(rename = "terminal.ansi.yellow")] pub terminal_ansi_yellow: Option, /// Bright yellow ANSI terminal color. #[serde(rename = "terminal.ansi.bright_yellow")] pub terminal_ansi_bright_yellow: Option, /// Dim yellow ANSI terminal color. #[serde(rename = "terminal.ansi.dim_yellow")] pub terminal_ansi_dim_yellow: Option, /// Blue ANSI terminal color. #[serde(rename = "terminal.ansi.blue")] pub terminal_ansi_blue: Option, /// Bright blue ANSI terminal color. #[serde(rename = "terminal.ansi.bright_blue")] pub terminal_ansi_bright_blue: Option, /// Dim blue ANSI terminal color. #[serde(rename = "terminal.ansi.dim_blue")] pub terminal_ansi_dim_blue: Option, /// Magenta ANSI terminal color. #[serde(rename = "terminal.ansi.magenta")] pub terminal_ansi_magenta: Option, /// Bright magenta ANSI terminal color. #[serde(rename = "terminal.ansi.bright_magenta")] pub terminal_ansi_bright_magenta: Option, /// Dim magenta ANSI terminal color. #[serde(rename = "terminal.ansi.dim_magenta")] pub terminal_ansi_dim_magenta: Option, /// Cyan ANSI terminal color. #[serde(rename = "terminal.ansi.cyan")] pub terminal_ansi_cyan: Option, /// Bright cyan ANSI terminal color. #[serde(rename = "terminal.ansi.bright_cyan")] pub terminal_ansi_bright_cyan: Option, /// Dim cyan ANSI terminal color. #[serde(rename = "terminal.ansi.dim_cyan")] pub terminal_ansi_dim_cyan: Option, /// White ANSI terminal color. #[serde(rename = "terminal.ansi.white")] pub terminal_ansi_white: Option, /// Bright white ANSI terminal color. #[serde(rename = "terminal.ansi.bright_white")] pub terminal_ansi_bright_white: Option, /// Dim white ANSI terminal color. #[serde(rename = "terminal.ansi.dim_white")] pub terminal_ansi_dim_white: Option, #[serde(rename = "link_text.hover")] pub link_text_hover: Option, /// Added version control color. #[serde(rename = "version_control.added")] pub version_control_added: Option, /// Deleted version control color. #[serde(rename = "version_control.deleted")] pub version_control_deleted: Option, /// Modified version control color. #[serde(rename = "version_control.modified")] pub version_control_modified: Option, /// Renamed version control color. #[serde(rename = "version_control.renamed")] pub version_control_renamed: Option, /// Conflict version control color. #[serde(rename = "version_control.conflict")] pub version_control_conflict: Option, /// Ignored version control color. #[serde(rename = "version_control.ignored")] pub version_control_ignored: Option, /// Background color for row highlights of "ours" regions in merge conflicts. #[serde(rename = "version_control.conflict_marker.ours")] pub version_control_conflict_marker_ours: Option, /// Background color for row highlights of "theirs" regions in merge conflicts. #[serde(rename = "version_control.conflict_marker.theirs")] pub version_control_conflict_marker_theirs: Option, /// Deprecated in favor of `version_control_conflict_marker_ours`. #[deprecated] pub version_control_conflict_ours_background: Option, /// Deprecated in favor of `version_control_conflict_marker_theirs`. #[deprecated] pub version_control_conflict_theirs_background: Option, /// Background color for Vim Normal mode indicator. #[serde(rename = "vim.normal.background")] pub vim_normal_background: Option, /// Background color for Vim Insert mode indicator. #[serde(rename = "vim.insert.background")] pub vim_insert_background: Option, /// Background color for Vim Replace mode indicator. #[serde(rename = "vim.replace.background")] pub vim_replace_background: Option, /// Background color for Vim Visual mode indicator. #[serde(rename = "vim.visual.background")] pub vim_visual_background: Option, /// Background color for Vim Visual Line mode indicator. #[serde(rename = "vim.visual_line.background")] pub vim_visual_line_background: Option, /// Background color for Vim Visual Block mode indicator. #[serde(rename = "vim.visual_block.background")] pub vim_visual_block_background: Option, /// Background color for Vim Helix Normal mode indicator. #[serde(rename = "vim.helix_normal.background")] pub vim_helix_normal_background: Option, /// Background color for Vim Helix Select mode indicator. #[serde(rename = "vim.helix_select.background")] pub vim_helix_select_background: Option, /// Text color for Vim mode indicator label. #[serde(rename = "vim.mode.text")] pub vim_mode_text: Option, } #[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)] #[serde(default)] pub struct HighlightStyleContent { pub color: Option, #[serde( skip_serializing_if = "Option::is_none", deserialize_with = "treat_error_as_none" )] pub background_color: Option, #[serde( skip_serializing_if = "Option::is_none", deserialize_with = "treat_error_as_none" )] pub font_style: Option, #[serde( skip_serializing_if = "Option::is_none", deserialize_with = "treat_error_as_none" )] pub font_weight: Option, } impl HighlightStyleContent { pub fn is_empty(&self) -> bool { self.color.is_none() && self.background_color.is_none() && self.font_style.is_none() && self.font_weight.is_none() } } fn treat_error_as_none<'de, T, D>(deserializer: D) -> Result, D::Error> where T: Deserialize<'de>, D: Deserializer<'de>, { let value: Value = Deserialize::deserialize(deserializer)?; Ok(T::deserialize(value).ok()) } #[with_fallible_options] #[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)] #[serde(default)] pub struct StatusColorsContent { /// Indicates some kind of conflict, like a file changed on disk while it was open, or /// merge conflicts in a Git repository. #[serde(rename = "conflict")] pub conflict: Option, #[serde(rename = "conflict.background")] pub conflict_background: Option, #[serde(rename = "conflict.border")] pub conflict_border: Option, /// Indicates something new, like a new file added to a Git repository. #[serde(rename = "created")] pub created: Option, #[serde(rename = "created.background")] pub created_background: Option, #[serde(rename = "created.border")] pub created_border: Option, /// Indicates that something no longer exists, like a deleted file. #[serde(rename = "deleted")] pub deleted: Option, #[serde(rename = "deleted.background")] pub deleted_background: Option, #[serde(rename = "deleted.border")] pub deleted_border: Option, /// Indicates a system error, a failed operation or a diagnostic error. #[serde(rename = "error")] pub error: Option, #[serde(rename = "error.background")] pub error_background: Option, #[serde(rename = "error.border")] pub error_border: Option, /// Represents a hidden status, such as a file being hidden in a file tree. #[serde(rename = "hidden")] pub hidden: Option, #[serde(rename = "hidden.background")] pub hidden_background: Option, #[serde(rename = "hidden.border")] pub hidden_border: Option, /// Indicates a hint or some kind of additional information. #[serde(rename = "hint")] pub hint: Option, #[serde(rename = "hint.background")] pub hint_background: Option, #[serde(rename = "hint.border")] pub hint_border: Option, /// Indicates that something is deliberately ignored, such as a file or operation ignored by Git. #[serde(rename = "ignored")] pub ignored: Option, #[serde(rename = "ignored.background")] pub ignored_background: Option, #[serde(rename = "ignored.border")] pub ignored_border: Option, /// Represents informational status updates or messages. #[serde(rename = "info")] pub info: Option, #[serde(rename = "info.background")] pub info_background: Option, #[serde(rename = "info.border")] pub info_border: Option, /// Indicates a changed or altered status, like a file that has been edited. #[serde(rename = "modified")] pub modified: Option, #[serde(rename = "modified.background")] pub modified_background: Option, #[serde(rename = "modified.border")] pub modified_border: Option, /// Indicates something that is predicted, like automatic code completion, or generated code. #[serde(rename = "predictive")] pub predictive: Option, #[serde(rename = "predictive.background")] pub predictive_background: Option, #[serde(rename = "predictive.border")] pub predictive_border: Option, /// Represents a renamed status, such as a file that has been renamed. #[serde(rename = "renamed")] pub renamed: Option, #[serde(rename = "renamed.background")] pub renamed_background: Option, #[serde(rename = "renamed.border")] pub renamed_border: Option, /// Indicates a successful operation or task completion. #[serde(rename = "success")] pub success: Option, #[serde(rename = "success.background")] pub success_background: Option, #[serde(rename = "success.border")] pub success_border: Option, /// Indicates some kind of unreachable status, like a block of code that can never be reached. #[serde(rename = "unreachable")] pub unreachable: Option, #[serde(rename = "unreachable.background")] pub unreachable_background: Option, #[serde(rename = "unreachable.border")] pub unreachable_border: Option, /// Represents a warning status, like an operation that is about to fail. #[serde(rename = "warning")] pub warning: Option, #[serde(rename = "warning.background")] pub warning_background: Option, #[serde(rename = "warning.border")] pub warning_border: Option, } /// The background appearance of the window. #[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, JsonSchema, MergeFrom)] #[serde(rename_all = "snake_case")] pub enum WindowBackgroundContent { Opaque, Transparent, Blurred, } impl Into for WindowBackgroundContent { fn into(self) -> gpui::WindowBackgroundAppearance { match self { WindowBackgroundContent::Opaque => gpui::WindowBackgroundAppearance::Opaque, WindowBackgroundContent::Transparent => gpui::WindowBackgroundAppearance::Transparent, WindowBackgroundContent::Blurred => gpui::WindowBackgroundAppearance::Blurred, } } } #[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)] #[serde(rename_all = "snake_case")] pub enum FontStyleContent { Normal, Italic, Oblique, } impl From for FontStyle { fn from(value: FontStyleContent) -> Self { match value { FontStyleContent::Normal => FontStyle::Normal, FontStyleContent::Italic => FontStyle::Italic, FontStyleContent::Oblique => FontStyle::Oblique, } } } #[derive( Debug, Clone, Copy, Serialize_repr, Deserialize_repr, JsonSchema_repr, PartialEq, MergeFrom, )] #[repr(u16)] pub enum FontWeightContent { Thin = 100, ExtraLight = 200, Light = 300, Normal = 400, Medium = 500, Semibold = 600, Bold = 700, ExtraBold = 800, Black = 900, } impl From for FontWeight { fn from(value: FontWeightContent) -> Self { match value { FontWeightContent::Thin => FontWeight::THIN, FontWeightContent::ExtraLight => FontWeight::EXTRA_LIGHT, FontWeightContent::Light => FontWeight::LIGHT, FontWeightContent::Normal => FontWeight::NORMAL, FontWeightContent::Medium => FontWeight::MEDIUM, FontWeightContent::Semibold => FontWeight::SEMIBOLD, FontWeightContent::Bold => FontWeight::BOLD, FontWeightContent::ExtraBold => FontWeight::EXTRA_BOLD, FontWeightContent::Black => FontWeight::BLACK, } } } #[cfg(test)] mod tests { use super::*; use serde_json::json; #[test] fn test_buffer_line_height_deserialize_valid() { assert_eq!( serde_json::from_value::(json!("comfortable")).unwrap(), BufferLineHeight::Comfortable ); assert_eq!( serde_json::from_value::(json!("standard")).unwrap(), BufferLineHeight::Standard ); assert_eq!( serde_json::from_value::(json!({"custom": 1.0})).unwrap(), BufferLineHeight::Custom(1.0) ); assert_eq!( serde_json::from_value::(json!({"custom": 1.5})).unwrap(), BufferLineHeight::Custom(1.5) ); } #[test] fn test_buffer_line_height_deserialize_invalid() { assert!( serde_json::from_value::(json!({"custom": 0.99})) .err() .unwrap() .to_string() .contains("buffer_line_height.custom must be at least 1.0") ); assert!( serde_json::from_value::(json!({"custom": 0.0})) .err() .unwrap() .to_string() .contains("buffer_line_height.custom must be at least 1.0") ); assert!( serde_json::from_value::(json!({"custom": -1.0})) .err() .unwrap() .to_string() .contains("buffer_line_height.custom must be at least 1.0") ); } #[test] fn test_buffer_font_weight_schema_has_default() { use schemars::schema_for; let schema = schema_for!(ThemeSettingsContent); let schema_value = serde_json::to_value(&schema).unwrap(); let properties = &schema_value["properties"]; let buffer_font_weight = &properties["buffer_font_weight"]; assert!( buffer_font_weight.get("default").is_some(), "buffer_font_weight should have a default value in the schema" ); let default_value = &buffer_font_weight["default"]; assert_eq!( default_value.as_f64(), Some(FontWeight::NORMAL.0 as f64), "buffer_font_weight default should be 400.0 (FontWeight::NORMAL)" ); let defs = &schema_value["$defs"]; let font_weight_def = &defs["FontWeight"]; assert_eq!( font_weight_def["minimum"].as_f64(), Some(FontWeight::THIN.0 as f64), "FontWeight should have minimum of 100.0" ); assert_eq!( font_weight_def["maximum"].as_f64(), Some(FontWeight::BLACK.0 as f64), "FontWeight should have maximum of 900.0" ); assert_eq!( font_weight_def["default"].as_f64(), Some(FontWeight::NORMAL.0 as f64), "FontWeight should have default of 400.0" ); } }