mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 02:17:35 +03:00
Add additional themes, update theme importer
This commit is contained in:
parent
3940e02a73
commit
c47c64184c
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
use crate::{zed_pro_family, ThemeFamily, ThemeVariant};
|
||||
use crate::{all_imported_themes, zed_pro_family, ThemeFamily, ThemeVariant};
|
||||
use anyhow::{anyhow, Result};
|
||||
use gpui::SharedString;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
@ -42,7 +42,10 @@ impl Default for ThemeRegistry {
|
||||
themes: HashMap::default(),
|
||||
};
|
||||
|
||||
this.insert_theme_families([zed_pro_family()]);
|
||||
let mut all_themes = vec![zed_pro_family()];
|
||||
all_themes.extend(all_imported_themes());
|
||||
|
||||
this.insert_theme_families(all_themes);
|
||||
|
||||
this
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,12 +1,23 @@
|
||||
|
||||
mod andromeda;
|
||||
mod ayu;
|
||||
mod andromeda;
|
||||
mod dracula;
|
||||
mod gruvbox;
|
||||
mod nord;
|
||||
mod notctis;
|
||||
mod ayu;
|
||||
mod gruvbox;
|
||||
|
||||
pub use andromeda::*;
|
||||
pub use ayu::*;
|
||||
pub use andromeda::*;
|
||||
pub use dracula::*;
|
||||
pub use gruvbox::*;
|
||||
pub use nord::*;
|
||||
pub use notctis::*;
|
||||
pub use ayu::*;
|
||||
pub use gruvbox::*;
|
||||
|
||||
|
||||
use crate::ThemeFamily;
|
||||
|
||||
pub(crate) fn all_imported_themes() -> Vec<ThemeFamily> {
|
||||
vec![andromeda(), dracula(), nord(), notctis(), ayu(), gruvbox()]
|
||||
}
|
||||
|
||||
|
18
crates/theme2/src/themes/nord.rs
Normal file
18
crates/theme2/src/themes/nord.rs
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -50,19 +50,42 @@ pub struct ThemeMetadata {
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
const SOURCE_PATH: &str = "assets/themes/src/vscode";
|
||||
const OUT_PATH: &str = "crates/theme2/src/themes";
|
||||
|
||||
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
||||
|
||||
println!("Creating path: assets/themes/src/vscode/");
|
||||
let vscode_themes_path = PathBuf::from_str("assets/themes/src/vscode/")?;
|
||||
let themes_output_path = PathBuf::from_str(OUT_PATH)?;
|
||||
|
||||
if !themes_output_path.exists() {
|
||||
println!("Creating directory: {:?}", themes_output_path);
|
||||
fs::create_dir_all(&themes_output_path)?;
|
||||
}
|
||||
|
||||
// We create mod.rs at the beginning to prevent `mod themes;`/`pub use themes::*;` from being
|
||||
// invalid in the theme crate root.
|
||||
println!(
|
||||
"Creating file: {:?}",
|
||||
themes_output_path.join(format!("mod.rs"))
|
||||
);
|
||||
|
||||
let mut mod_rs_file = File::create(themes_output_path.join(format!("mod.rs")))?;
|
||||
|
||||
println!("Loading themes source...");
|
||||
let vscode_themes_path = PathBuf::from_str(SOURCE_PATH)?;
|
||||
if !vscode_themes_path.exists() {
|
||||
return Err(anyhow!(format!(
|
||||
"Couldn't find {}, make sure it exists",
|
||||
SOURCE_PATH
|
||||
)));
|
||||
}
|
||||
|
||||
let mut theme_families = Vec::new();
|
||||
|
||||
for theme_family_dir in fs::read_dir(&vscode_themes_path)? {
|
||||
println!("Reading directory: {:?}", vscode_themes_path);
|
||||
|
||||
let theme_family_dir = theme_family_dir?;
|
||||
|
||||
if theme_family_dir.file_name().to_str() == Some(".DS_Store") {
|
||||
if !theme_family_dir.file_type()?.is_dir() {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -72,12 +95,18 @@ fn main() -> Result<()> {
|
||||
.ok_or(anyhow!("no file stem"))
|
||||
.map(|stem| stem.to_string_lossy().to_string())?;
|
||||
|
||||
println!(
|
||||
"Opening file: {:?}",
|
||||
theme_family_dir.path().join("family.json")
|
||||
);
|
||||
let family_metadata_file = File::open(theme_family_dir.path().join("family.json"))
|
||||
.context(format!("no `family.json` found for '{theme_family_slug}'"))?;
|
||||
.context(format!(
|
||||
"no `family.json` found for '{}'",
|
||||
theme_family_slug
|
||||
))?;
|
||||
|
||||
let license_file_path = theme_family_dir.path().join("LICENSE");
|
||||
|
||||
if !license_file_path.exists() {
|
||||
println!("Skipping theme family '{}' because it does not have a LICENSE file. This theme will only be imported once a LICENSE file is provided.", theme_family_slug);
|
||||
continue;
|
||||
}
|
||||
|
||||
let family_metadata: FamilyMetadata = serde_json::from_reader(family_metadata_file)
|
||||
.context(format!(
|
||||
@ -118,8 +147,6 @@ fn main() -> Result<()> {
|
||||
theme_families.push(theme_family);
|
||||
}
|
||||
|
||||
let themes_output_path = PathBuf::from_str("crates/theme2/src/themes")?;
|
||||
|
||||
let mut theme_modules = Vec::new();
|
||||
|
||||
for theme_family in theme_families {
|
||||
@ -153,17 +180,28 @@ fn main() -> Result<()> {
|
||||
theme_modules.push(theme_family_slug);
|
||||
}
|
||||
|
||||
println!(
|
||||
"Creating file: {:?}",
|
||||
themes_output_path.join(format!("mod.rs"))
|
||||
let themes_vector_contents = format!(
|
||||
r#"
|
||||
use crate::ThemeFamily;
|
||||
|
||||
pub(crate) fn all_imported_themes() -> Vec<ThemeFamily> {{
|
||||
vec![{all_themes}]
|
||||
}}
|
||||
"#,
|
||||
all_themes = theme_modules
|
||||
.iter()
|
||||
.map(|module| format!("{}()", module))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
);
|
||||
let mut mod_rs_file = File::create(themes_output_path.join(format!("mod.rs")))?;
|
||||
|
||||
let mod_rs_contents = format!(
|
||||
r#"
|
||||
{mod_statements}
|
||||
|
||||
{use_statements}
|
||||
|
||||
{themes_vector_contents}
|
||||
"#,
|
||||
mod_statements = theme_modules
|
||||
.iter()
|
||||
@ -174,7 +212,8 @@ fn main() -> Result<()> {
|
||||
.iter()
|
||||
.map(|module| format!("pub use {module}::*;"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
.join("\n"),
|
||||
themes_vector_contents = themes_vector_contents
|
||||
);
|
||||
|
||||
mod_rs_file.write_all(mod_rs_contents.as_bytes())?;
|
||||
|
@ -134,6 +134,8 @@ impl<'a> Debug for ThemeColorsPrinter<'a> {
|
||||
.field("border", &HslaPrinter(self.0.border))
|
||||
.field("border_variant", &HslaPrinter(self.0.border_variant))
|
||||
.field("border_focused", &HslaPrinter(self.0.border_focused))
|
||||
.field("border_disabled", &HslaPrinter(self.0.border_disabled))
|
||||
.field("border_selected", &HslaPrinter(self.0.border_selected))
|
||||
.field(
|
||||
"border_transparent",
|
||||
&HslaPrinter(self.0.border_transparent),
|
||||
|
@ -456,6 +456,14 @@ impl VsCodeThemeConverter {
|
||||
.panel_border
|
||||
.as_ref()
|
||||
.traverse(|color| try_parse_color(&color))?,
|
||||
border_disabled: vscode_colors
|
||||
.panel_border
|
||||
.as_ref()
|
||||
.traverse(|color| try_parse_color(&color))?,
|
||||
border_selected: vscode_colors
|
||||
.panel_border
|
||||
.as_ref()
|
||||
.traverse(|color| try_parse_color(&color))?,
|
||||
border_transparent: vscode_colors
|
||||
.panel_border
|
||||
.as_ref()
|
||||
|
Loading…
Reference in New Issue
Block a user