zed/crates/theme_importer/src/vscode.rs

83 lines
2.4 KiB
Rust
Raw Normal View History

use std::path::{Path, PathBuf};
use anyhow::Result;
use serde::Deserialize;
use theme::{default_color_scales, ColorScales, ThemeFamily};
#[derive(Deserialize, Debug)]
2023-11-02 22:00:55 +00:00
pub struct VsCodeTheme {
#[serde(rename = "$schema")]
2023-11-02 22:00:55 +00:00
pub schema: Option<String>,
pub name: Option<String>,
pub author: Option<String>,
pub maintainers: Option<Vec<String>>,
#[serde(rename = "semanticClass")]
2023-11-02 22:00:55 +00:00
pub semantic_class: Option<String>,
#[serde(rename = "semanticHighlighting")]
2023-11-02 22:00:55 +00:00
pub semantic_highlighting: Option<bool>,
pub colors: VsCodeColors,
}
#[derive(Debug, Deserialize)]
2023-11-02 22:00:55 +00:00
pub struct VsCodeColors {
#[serde(rename = "editor.foreground")]
text: String,
#[serde(rename = "editor.background")]
editor: String,
}
pub(crate) fn new_theme_family_from_vsc(path: &Path) -> Result<ThemeFamily> {
2023-11-02 22:00:55 +00:00
todo!()
2023-11-02 22:00:55 +00:00
// let path_str = path.to_str().unwrap();
// let family_name = path_str.split('/').last().unwrap();
2023-11-02 22:00:55 +00:00
// let mut json_files: Vec<String> = Vec::new();
// if path.is_dir() {
// for entry in std::fs::read_dir(path).unwrap() {
// let entry = entry.unwrap();
// let path = entry.path();
// if path.is_file() {
// if let Some(extension) = path.extension() {
// if extension == "json" {
// json_files.push(path.file_name().unwrap().to_str().unwrap().to_string());
// }
// }
// }
// }
// } else {
// anyhow::bail!("Path is not a directory");
// }
2023-11-02 22:00:55 +00:00
// let mut theme_family = ThemeFamily {
// id: uuid::Uuid::new_v4().to_string(),
// name: family_name.into(),
// author: "New Theme Family".into(),
// themes: Vec::new(),
// scales: default_color_scales(),
// };
2023-11-02 22:00:55 +00:00
// Ok(theme_family)
}
#[cfg(test)]
mod tests {
use super::*;
use std::path::PathBuf;
#[test]
fn test_deserialize_theme() {
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let root_dir = manifest_dir.parent().unwrap().parent().unwrap();
let mut d = root_dir.to_path_buf();
d.push("assets/themes/src/vsc/dracula/dracula.json");
let data = std::fs::read_to_string(d).expect("Unable to read file");
let result: Theme = serde_json::from_str(&data).unwrap();
println!("{:#?}", result);
}
}