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",
|
"anyhow",
|
||||||
"clap 4.4.4",
|
"clap 4.4.4",
|
||||||
"convert_case 0.6.0",
|
"convert_case 0.6.0",
|
||||||
"gpui",
|
|
||||||
"gpui2",
|
"gpui2",
|
||||||
"indexmap 1.9.3",
|
"indexmap 1.9.3",
|
||||||
"json_comments",
|
"json_comments",
|
||||||
"log",
|
"log",
|
||||||
"palette",
|
"palette",
|
||||||
|
"pathfinder_color",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
"serde",
|
"serde",
|
||||||
"simplelog",
|
"simplelog",
|
||||||
"strum",
|
"strum",
|
||||||
"theme",
|
|
||||||
"theme2",
|
"theme2",
|
||||||
"uuid 1.4.1",
|
"uuid 1.4.1",
|
||||||
]
|
]
|
||||||
|
@ -9,16 +9,15 @@ any_ascii = "0.3.2"
|
|||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
clap = { version = "4.4", features = ["derive"] }
|
clap = { version = "4.4", features = ["derive"] }
|
||||||
convert_case = "0.6.0"
|
convert_case = "0.6.0"
|
||||||
gpui = { package = "gpui2", path = "../gpui2", features = ["allow-multiple-gpui-versions"] }
|
gpui = { package = "gpui2", path = "../gpui2" }
|
||||||
gpui1 = { package = "gpui", path = "../gpui" }
|
|
||||||
indexmap = { version = "1.6.2", features = ["serde"] }
|
indexmap = { version = "1.6.2", features = ["serde"] }
|
||||||
json_comments = "0.2.2"
|
json_comments = "0.2.2"
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
palette = { version = "0.7.3", default-features = false, features = ["std"] }
|
palette = { version = "0.7.3", default-features = false, features = ["std"] }
|
||||||
|
pathfinder_color = "0.5"
|
||||||
rust-embed.workspace = true
|
rust-embed.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
simplelog = "0.9"
|
simplelog = "0.9"
|
||||||
strum = { version = "0.25.0", features = ["derive"] }
|
strum = { version = "0.25.0", features = ["derive"] }
|
||||||
theme = { package = "theme2", path = "../theme2", features = ["importing-themes"] }
|
theme = { package = "theme2", path = "../theme2", features = ["importing-themes"] }
|
||||||
theme1 = { package = "theme", path = "../theme" }
|
|
||||||
uuid.workspace = true
|
uuid.workspace = true
|
||||||
|
@ -11,25 +11,23 @@ use std::io::Write;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use any_ascii::any_ascii;
|
use any_ascii::any_ascii;
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use convert_case::{Case, Casing};
|
use convert_case::{Case, Casing};
|
||||||
use gpui::{serde_json, AssetSource};
|
use gpui::serde_json;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use json_comments::StripComments;
|
use json_comments::StripComments;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use simplelog::{TermLogger, TerminalMode};
|
use simplelog::{TermLogger, TerminalMode};
|
||||||
use theme::{Appearance, UserTheme, UserThemeFamily};
|
use theme::{Appearance, UserTheme, UserThemeFamily};
|
||||||
use theme1::Theme as Zed1Theme;
|
|
||||||
|
|
||||||
use crate::assets::Assets;
|
|
||||||
use crate::theme_printer::UserThemeFamilyPrinter;
|
use crate::theme_printer::UserThemeFamilyPrinter;
|
||||||
use crate::vscode::VsCodeTheme;
|
use crate::vscode::VsCodeTheme;
|
||||||
use crate::vscode::VsCodeThemeConverter;
|
use crate::vscode::VsCodeThemeConverter;
|
||||||
|
use crate::zed1::theme::Theme as Zed1Theme;
|
||||||
use crate::zed1::Zed1ThemeConverter;
|
use crate::zed1::Zed1ThemeConverter;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
@ -210,19 +208,6 @@ fn main() -> Result<()> {
|
|||||||
.map(|family| (family.to_string(), Vec::new())),
|
.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)? {
|
for entry in fs::read_dir(&zed1_themes_path)? {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
|
|
||||||
@ -251,10 +236,8 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
let theme_without_comments = StripComments::new(theme_file);
|
let theme_without_comments = StripComments::new(theme_file);
|
||||||
|
|
||||||
let zed1_theme: Zed1Theme = gpui1::fonts::with_font_cache(zed1_font_cache.clone(), || {
|
let zed1_theme: Zed1Theme = serde_json::from_reader(theme_without_comments)
|
||||||
serde_json::from_reader(theme_without_comments)
|
.context(format!("failed to parse theme {theme_file_path:?}"))?;
|
||||||
.context(format!("failed to parse theme {theme_file_path:?}"))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let theme_name = zed1_theme.meta.name.clone();
|
let theme_name = zed1_theme.meta.name.clone();
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
mod converter;
|
mod converter;
|
||||||
|
pub mod theme;
|
||||||
|
|
||||||
pub use converter::*;
|
pub use converter::*;
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use gpui::{serde_json, Hsla, Rgba};
|
use gpui::{serde_json, Hsla, Rgba};
|
||||||
use gpui1::color::Color as Zed1Color;
|
|
||||||
use gpui1::fonts::HighlightStyle as Zed1HighlightStyle;
|
|
||||||
use theme::{
|
use theme::{
|
||||||
color_alpha, Appearance, PlayerColor, PlayerColors, StatusColorsRefinement,
|
color_alpha, Appearance, PlayerColor, PlayerColors, StatusColorsRefinement,
|
||||||
ThemeColorsRefinement, UserFontStyle, UserFontWeight, UserHighlightStyle, UserSyntaxTheme,
|
ThemeColorsRefinement, UserFontStyle, UserFontWeight, UserHighlightStyle, UserSyntaxTheme,
|
||||||
UserTheme, UserThemeStylesRefinement,
|
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 {
|
fn zed1_color_to_hsla(color: Zed1Color) -> Hsla {
|
||||||
let r = color.r as f32 / 255.;
|
let r = color.r as f32 / 255.;
|
||||||
@ -30,7 +32,17 @@ fn zed1_highlight_style_to_user_highlight_style(
|
|||||||
UserFontStyle::Normal
|
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