1318 lines · 44.3 KB · Rust
RawDownload
use collections::{HashMap, IndexMap};use gpui::{FontFallbacks, FontFeatures, FontStyle, FontWeight, Pixels, 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.    pub ui_font_size: Option<FontSize>,    /// The name of a font to use for rendering in the UI.    pub ui_font_family: Option<FontFamilyName>,    /// The font fallbacks to use for rendering in the UI.    #[schemars(default = "default_font_fallbacks")]    #[schemars(extend("uniqueItems" = true))]    pub ui_font_fallbacks: Option<Vec<FontFamilyName>>,    /// The OpenType features to enable for text in the UI.    #[schemars(default = "default_font_features")]    pub ui_font_features: Option<FontFeatures>,    /// The weight of the UI font in CSS units from 100 to 900.    #[schemars(default = "default_buffer_font_weight")]    pub ui_font_weight: Option<FontWeight>,    /// The name of a font to use for rendering in text buffers.    pub buffer_font_family: Option<FontFamilyName>,    /// The font fallbacks to use for rendering in text buffers.    #[schemars(extend("uniqueItems" = true))]    pub buffer_font_fallbacks: Option<Vec<FontFamilyName>>,    /// The default font size for rendering in text buffers.    pub buffer_font_size: Option<FontSize>,    /// The weight of the editor font in CSS units from 100 to 900.    #[schemars(default = "default_buffer_font_weight")]    pub buffer_font_weight: Option<FontWeight>,    /// The buffer's line height.    pub buffer_line_height: Option<BufferLineHeight>,    /// The OpenType features to enable for rendering in text buffers.    #[schemars(default = "default_font_features")]    pub buffer_font_features: Option<FontFeatures>,    /// The font size for agent responses in the agent panel. Falls back to the UI font size if unset.    pub agent_ui_font_size: Option<FontSize>,    /// The font size for user messages in the agent panel.    pub agent_buffer_font_size: Option<FontSize>,    /// The name of the Zed theme to use.    pub theme: Option<ThemeSelection>,    /// The name of the icon theme to use.    pub icon_theme: Option<IconThemeSelection>,     /// UNSTABLE: Expect many elements to be broken.    ///    // Controls the density of the UI.    #[serde(rename = "unstable.ui_density")]    pub ui_density: Option<UiDensity>,     /// How much to fade out unused code.    #[schemars(range(min = 0.0, max = 0.9))]    pub unnecessary_code_fade: Option<CodeFade>,     /// 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<ThemeStyleContent>,     /// Overrides per theme    ///    /// These values will override the ones on the specified theme    #[serde(default)]    pub theme_overrides: HashMap<String, ThemeStyleContent>,} /// A font size value in pixels, wrapping around `f32` for custom settings UI rendering.#[derive(    Clone,    Copy,    Debug,    Serialize,    Deserialize,    JsonSchema,    MergeFrom,    PartialEq,    PartialOrd,    derive_more::FromStr,)]#[serde(transparent)]pub struct FontSize(#[serde(serialize_with = "serialize_f32_with_two_decimal_places")] pub f32); impl Display for FontSize {    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {        write!(f, "{:.2}", self.0)    }} impl From<f32> for FontSize {    fn from(value: f32) -> Self {        Self(value)    }} impl From<FontSize> for Pixels {    fn from(value: FontSize) -> Self {        value.0.into()    }} impl From<Pixels> for FontSize {    fn from(value: Pixels) -> Self {        Self(value.into())    }} #[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<f32> for CodeFade {    fn from(x: f32) -> Self {        Self(x)    }} fn default_font_features() -> Option<FontFeatures> {    Some(FontFeatures::default())} fn default_font_fallbacks() -> Option<FontFallbacks> {    Some(FontFallbacks::default())} fn default_buffer_font_weight() -> Option<FontWeight> {    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,    },} pub const DEFAULT_LIGHT_THEME: &'static str = "One Light";pub const DEFAULT_DARK_THEME: &'static str = "One Dark"; impl Default for ThemeSelection {    fn default() -> Self {        Self::Dynamic {            mode: ThemeAppearanceMode::default(),            light: ThemeName(DEFAULT_LIGHT_THEME.into()),            dark: ThemeName(DEFAULT_DARK_THEME.into()),        }    }} /// 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<str>); impl AsRef<str> for FontFamilyName {    fn as_ref(&self) -> &str {        &self.0    }} impl From<SharedString> for FontFamilyName {    fn from(value: SharedString) -> Self {        Self(Arc::from(value))    }} impl From<FontFamilyName> for SharedString {    fn from(value: FontFamilyName) -> Self {        SharedString::new(value.0)    }} impl From<String> for FontFamilyName {    fn from(value: String) -> Self {        Self(Arc::from(value))    }} impl From<FontFamilyName> 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<f32, D::Error>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<WindowBackgroundContent>,     #[serde(default)]    pub accents: Vec<AccentContent>,     #[serde(flatten, default)]    pub colors: ThemeColorsContent,     #[serde(flatten, default)]    pub status: StatusColorsContent,     #[serde(default)]    pub players: Vec<PlayerColorContent>,     /// The styles for syntax nodes.    #[serde(default)]    pub syntax: IndexMap<String, HighlightStyleContent>,} #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]pub struct AccentContent(pub Option<SharedString>); #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]pub struct PlayerColorContent {    pub cursor: Option<String>,    pub background: Option<String>,    pub selection: Option<String>,} /// Theme name.#[with_fallible_options]#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]#[serde(transparent)]pub struct ThemeName(pub Arc<str>); /// Icon Theme Name#[with_fallible_options]#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]#[serde(transparent)]pub struct IconThemeName(pub Arc<str>); #[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<String>,     /// Border color. Used for deemphasized borders, like a visual divider between two sections    #[serde(rename = "border.variant")]    pub border_variant: Option<String>,     /// Border color. Used for focused elements, like keyboard focused list item.    #[serde(rename = "border.focused")]    pub border_focused: Option<String>,     /// Border color. Used for selected elements, like an active search filter or selected checkbox.    #[serde(rename = "border.selected")]    pub border_selected: Option<String>,     /// 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<String>,     /// Border color. Used for disabled elements, like a disabled input or button.    #[serde(rename = "border.disabled")]    pub border_disabled: Option<String>,     /// Background color. Used for elevated surfaces, like a context menu, popup, or dialog.    #[serde(rename = "elevated_surface.background")]    pub elevated_surface_background: Option<String>,     /// Background Color. Used for grounded surfaces like a panel or tab.    #[serde(rename = "surface.background")]    pub surface_background: Option<String>,     /// Background Color. Used for the app background and blank panels or windows.    #[serde(rename = "background")]    pub background: Option<String>,     /// 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<String>,     /// 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<String>,     /// 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<String>,     /// 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<String>,     /// 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<String>,     /// Background Color. Used for the background of selections in a UI element.    #[serde(rename = "element.selection_background")]

Lines 1–500 of 1318.