Add serialized versions of themes (#6885)

This PR adds serialized versions of each of the themes that currently
ship with Zed.

In a future PR we'll be looking to make these the canonical
representations of the built-in themes.

Note that we're intentionally repurposing the `theme_importer` to do
this, so that crate is a bit rough-and-ready at the moment.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-01-27 13:35:43 -05:00 committed by GitHub
parent 9d6414b0cc
commit 0fe0683ef4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 13672 additions and 14 deletions

View file

@ -26,10 +26,33 @@ fn try_parse_color(color: &str) -> Result<Hsla> {
Ok(hsla)
}
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum AppearanceContent {
Light,
Dark,
}
/// The content of a serialized theme family.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct ThemeFamilyContent {
pub name: String,
pub author: String,
pub themes: Vec<ThemeContent>,
}
/// The content of a serialized theme.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct ThemeContent {
pub name: String,
pub appearance: AppearanceContent,
pub style: ThemeStyleContent,
}
/// The content of a serialized theme.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct ThemeContent {
pub struct ThemeStyleContent {
#[serde(flatten, default)]
pub colors: ThemeColorsContent,
@ -41,7 +64,7 @@ pub struct ThemeContent {
pub syntax: IndexMap<String, HighlightStyleContent>,
}
impl ThemeContent {
impl ThemeStyleContent {
/// Returns a [`ThemeColorsRefinement`] based on the colors in the [`ThemeContent`].
#[inline(always)]
pub fn theme_colors_refinement(&self) -> ThemeColorsRefinement {
@ -230,7 +253,7 @@ pub struct ThemeColorsContent {
/// 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 = "con.accent")]
#[serde(rename = "icon.accent")]
pub icon_accent: Option<String>,
#[serde(rename = "status_bar.background")]

View file

@ -1,5 +1,5 @@
use crate::one_themes::one_dark;
use crate::{SyntaxTheme, Theme, ThemeContent, ThemeRegistry};
use crate::{SyntaxTheme, Theme, ThemeRegistry, ThemeStyleContent};
use anyhow::Result;
use gpui::{
px, AppContext, Font, FontFeatures, FontStyle, FontWeight, Pixels, Subscription, ViewContext,
@ -27,7 +27,7 @@ pub struct ThemeSettings {
pub buffer_font_size: Pixels,
pub buffer_line_height: BufferLineHeight,
pub active_theme: Arc<Theme>,
pub theme_overrides: Option<ThemeContent>,
pub theme_overrides: Option<ThemeStyleContent>,
}
#[derive(Default)]
@ -56,7 +56,7 @@ pub struct ThemeSettingsContent {
///
/// These values will override the ones on the current theme specified in `theme`.
#[serde(rename = "experimental.theme_overrides", default)]
pub theme_overrides: Option<ThemeContent>,
pub theme_overrides: Option<ThemeStyleContent>,
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, JsonSchema, Default)]

View file

@ -23,7 +23,7 @@ pub use summercamp::*;
use crate::UserThemeFamily;
pub(crate) fn all_user_themes() -> Vec<UserThemeFamily> {
pub fn all_user_themes() -> Vec<UserThemeFamily> {
vec![
andromeda(),
atelier(),