Add additional themes, update theme importer

This commit is contained in:
Nate Butler 2023-11-06 14:54:21 -05:00
parent 3940e02a73
commit c47c64184c
13 changed files with 1479 additions and 1383 deletions

File diff suppressed because it is too large Load diff

View file

@ -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 anyhow::{anyhow, Result};
use gpui::SharedString; use gpui::SharedString;
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};
@ -42,7 +42,10 @@ impl Default for ThemeRegistry {
themes: HashMap::default(), 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 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

View file

@ -1,12 +1,23 @@
mod andromeda; mod andromeda;
mod ayu;
mod dracula; mod dracula;
mod gruvbox; mod nord;
mod notctis; mod notctis;
mod ayu;
mod gruvbox;
pub use andromeda::*; pub use andromeda::*;
pub use ayu::*;
pub use dracula::*; pub use dracula::*;
pub use gruvbox::*; pub use nord::*;
pub use notctis::*; 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()]
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -50,19 +50,42 @@ pub struct ThemeMetadata {
} }
fn main() -> Result<()> { 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"); SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
println!("Creating path: assets/themes/src/vscode/"); let themes_output_path = PathBuf::from_str(OUT_PATH)?;
let vscode_themes_path = PathBuf::from_str("assets/themes/src/vscode/")?;
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(); let mut theme_families = Vec::new();
for theme_family_dir in fs::read_dir(&vscode_themes_path)? { for theme_family_dir in fs::read_dir(&vscode_themes_path)? {
println!("Reading directory: {:?}", vscode_themes_path);
let theme_family_dir = theme_family_dir?; 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; continue;
} }
@ -72,12 +95,18 @@ fn main() -> Result<()> {
.ok_or(anyhow!("no file stem")) .ok_or(anyhow!("no file stem"))
.map(|stem| stem.to_string_lossy().to_string())?; .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")) 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) let family_metadata: FamilyMetadata = serde_json::from_reader(family_metadata_file)
.context(format!( .context(format!(
@ -118,8 +147,6 @@ fn main() -> Result<()> {
theme_families.push(theme_family); theme_families.push(theme_family);
} }
let themes_output_path = PathBuf::from_str("crates/theme2/src/themes")?;
let mut theme_modules = Vec::new(); let mut theme_modules = Vec::new();
for theme_family in theme_families { for theme_family in theme_families {
@ -153,17 +180,28 @@ fn main() -> Result<()> {
theme_modules.push(theme_family_slug); theme_modules.push(theme_family_slug);
} }
println!( let themes_vector_contents = format!(
"Creating file: {:?}", r#"
themes_output_path.join(format!("mod.rs")) 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!( let mod_rs_contents = format!(
r#" r#"
{mod_statements} {mod_statements}
{use_statements} {use_statements}
{themes_vector_contents}
"#, "#,
mod_statements = theme_modules mod_statements = theme_modules
.iter() .iter()
@ -174,7 +212,8 @@ fn main() -> Result<()> {
.iter() .iter()
.map(|module| format!("pub use {module}::*;")) .map(|module| format!("pub use {module}::*;"))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("\n") .join("\n"),
themes_vector_contents = themes_vector_contents
); );
mod_rs_file.write_all(mod_rs_contents.as_bytes())?; mod_rs_file.write_all(mod_rs_contents.as_bytes())?;

View file

@ -134,6 +134,8 @@ impl<'a> Debug for ThemeColorsPrinter<'a> {
.field("border", &HslaPrinter(self.0.border)) .field("border", &HslaPrinter(self.0.border))
.field("border_variant", &HslaPrinter(self.0.border_variant)) .field("border_variant", &HslaPrinter(self.0.border_variant))
.field("border_focused", &HslaPrinter(self.0.border_focused)) .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( .field(
"border_transparent", "border_transparent",
&HslaPrinter(self.0.border_transparent), &HslaPrinter(self.0.border_transparent),

View file

@ -456,6 +456,14 @@ impl VsCodeThemeConverter {
.panel_border .panel_border
.as_ref() .as_ref()
.traverse(|color| try_parse_color(&color))?, .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 border_transparent: vscode_colors
.panel_border .panel_border
.as_ref() .as_ref()