mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Decouple theme_importer
from old GPUI 1 crates (#3866)
This PR decouples the `theme_importer` from the `theme` and `gpui` crates. We achieve this by inlining all of the relevant bits needed to deserialize Zed1 themes. This will allow us to continue to import Zed1 themes after we land #3862. Release Notes: - N/A
This commit is contained in:
parent
53bdf6beb3
commit
6cb913d8af
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -8582,17 +8582,16 @@ dependencies = [
|
||||
"anyhow",
|
||||
"clap 4.4.4",
|
||||
"convert_case 0.6.0",
|
||||
"gpui",
|
||||
"gpui2",
|
||||
"indexmap 1.9.3",
|
||||
"json_comments",
|
||||
"log",
|
||||
"palette",
|
||||
"pathfinder_color",
|
||||
"rust-embed",
|
||||
"serde",
|
||||
"simplelog",
|
||||
"strum",
|
||||
"theme",
|
||||
"theme2",
|
||||
"uuid 1.4.1",
|
||||
]
|
||||
|
@ -9,16 +9,15 @@ any_ascii = "0.3.2"
|
||||
anyhow.workspace = true
|
||||
clap = { version = "4.4", features = ["derive"] }
|
||||
convert_case = "0.6.0"
|
||||
gpui = { package = "gpui2", path = "../gpui2", features = ["allow-multiple-gpui-versions"] }
|
||||
gpui1 = { package = "gpui", path = "../gpui" }
|
||||
gpui = { package = "gpui2", path = "../gpui2" }
|
||||
indexmap = { version = "1.6.2", features = ["serde"] }
|
||||
json_comments = "0.2.2"
|
||||
log.workspace = true
|
||||
palette = { version = "0.7.3", default-features = false, features = ["std"] }
|
||||
pathfinder_color = "0.5"
|
||||
rust-embed.workspace = true
|
||||
serde.workspace = true
|
||||
simplelog = "0.9"
|
||||
strum = { version = "0.25.0", features = ["derive"] }
|
||||
theme = { package = "theme2", path = "../theme2", features = ["importing-themes"] }
|
||||
theme1 = { package = "theme", path = "../theme" }
|
||||
uuid.workspace = true
|
||||
|
@ -11,25 +11,23 @@ use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use any_ascii::any_ascii;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use clap::Parser;
|
||||
use convert_case::{Case, Casing};
|
||||
use gpui::{serde_json, AssetSource};
|
||||
use gpui::serde_json;
|
||||
use indexmap::IndexMap;
|
||||
use json_comments::StripComments;
|
||||
use log::LevelFilter;
|
||||
use serde::Deserialize;
|
||||
use simplelog::{TermLogger, TerminalMode};
|
||||
use theme::{Appearance, UserTheme, UserThemeFamily};
|
||||
use theme1::Theme as Zed1Theme;
|
||||
|
||||
use crate::assets::Assets;
|
||||
use crate::theme_printer::UserThemeFamilyPrinter;
|
||||
use crate::vscode::VsCodeTheme;
|
||||
use crate::vscode::VsCodeThemeConverter;
|
||||
use crate::zed1::theme::Theme as Zed1Theme;
|
||||
use crate::zed1::Zed1ThemeConverter;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@ -210,19 +208,6 @@ fn main() -> Result<()> {
|
||||
.map(|family| (family.to_string(), Vec::new())),
|
||||
);
|
||||
|
||||
let platform = gpui1::platform::current::platform();
|
||||
let zed1_font_cache = Arc::new(gpui1::FontCache::new(platform.fonts()));
|
||||
|
||||
let mut embedded_fonts = Vec::new();
|
||||
for font_path in Assets.list("fonts")? {
|
||||
if font_path.ends_with(".ttf") {
|
||||
let font_bytes = Assets.load(&font_path)?.to_vec();
|
||||
embedded_fonts.push(Arc::from(font_bytes));
|
||||
}
|
||||
}
|
||||
|
||||
platform.fonts().add_fonts(&embedded_fonts)?;
|
||||
|
||||
for entry in fs::read_dir(&zed1_themes_path)? {
|
||||
let entry = entry?;
|
||||
|
||||
@ -251,10 +236,8 @@ fn main() -> Result<()> {
|
||||
|
||||
let theme_without_comments = StripComments::new(theme_file);
|
||||
|
||||
let zed1_theme: Zed1Theme = gpui1::fonts::with_font_cache(zed1_font_cache.clone(), || {
|
||||
serde_json::from_reader(theme_without_comments)
|
||||
.context(format!("failed to parse theme {theme_file_path:?}"))
|
||||
})?;
|
||||
let zed1_theme: Zed1Theme = serde_json::from_reader(theme_without_comments)
|
||||
.context(format!("failed to parse theme {theme_file_path:?}"))?;
|
||||
|
||||
let theme_name = zed1_theme.meta.name.clone();
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
mod converter;
|
||||
pub mod theme;
|
||||
|
||||
pub use converter::*;
|
||||
|
@ -1,13 +1,15 @@
|
||||
use anyhow::{Context, Result};
|
||||
use gpui::{serde_json, Hsla, Rgba};
|
||||
use gpui1::color::Color as Zed1Color;
|
||||
use gpui1::fonts::HighlightStyle as Zed1HighlightStyle;
|
||||
use theme::{
|
||||
color_alpha, Appearance, PlayerColor, PlayerColors, StatusColorsRefinement,
|
||||
ThemeColorsRefinement, UserFontStyle, UserFontWeight, UserHighlightStyle, UserSyntaxTheme,
|
||||
UserTheme, UserThemeStylesRefinement,
|
||||
};
|
||||
use theme1::{ColorScheme, Theme as Zed1Theme};
|
||||
|
||||
use crate::zed1::theme::{
|
||||
Color as Zed1Color, ColorScheme, HighlightStyle as Zed1HighlightStyle, Theme as Zed1Theme,
|
||||
Weight,
|
||||
};
|
||||
|
||||
fn zed1_color_to_hsla(color: Zed1Color) -> Hsla {
|
||||
let r = color.r as f32 / 255.;
|
||||
@ -30,7 +32,17 @@ fn zed1_highlight_style_to_user_highlight_style(
|
||||
UserFontStyle::Normal
|
||||
}
|
||||
}),
|
||||
font_weight: highlight.weight.map(|weight| UserFontWeight(weight.0)),
|
||||
font_weight: highlight.weight.map(|weight| match weight {
|
||||
Weight::thin => UserFontWeight::THIN,
|
||||
Weight::extra_light => UserFontWeight::EXTRA_LIGHT,
|
||||
Weight::light => UserFontWeight::LIGHT,
|
||||
Weight::normal => UserFontWeight::NORMAL,
|
||||
Weight::medium => UserFontWeight::MEDIUM,
|
||||
Weight::semibold => UserFontWeight::SEMIBOLD,
|
||||
Weight::bold => UserFontWeight::BOLD,
|
||||
Weight::extra_bold => UserFontWeight::EXTRA_BOLD,
|
||||
Weight::black => UserFontWeight::BLACK,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
1518
crates/theme_importer/src/zed1/theme.rs
Normal file
1518
crates/theme_importer/src/zed1/theme.rs
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user