mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-30 14:17:02 +00:00
Add theme loading
This commit is contained in:
parent
613973d2b1
commit
def67295e5
2 changed files with 30 additions and 8 deletions
|
@ -50,14 +50,7 @@ fn main() {
|
||||||
|
|
||||||
let story_selector = args.story.clone();
|
let story_selector = args.story.clone();
|
||||||
|
|
||||||
let theme = match args.theme.as_ref().map(|theme| theme.as_str()) {
|
let theme = themes::load_theme(args.theme);
|
||||||
Some("Rosé Pine") => themes::rose_pine(),
|
|
||||||
Some("Rosé Pine Dawn") => themes::rose_pine_dawn(),
|
|
||||||
Some(theme_name) => {
|
|
||||||
panic!("Only 'Rosé Pine' and 'Rosé Pine Dawn' are currently supported.")
|
|
||||||
}
|
|
||||||
None => themes::rose_pine_dawn(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let asset_source = Arc::new(Assets);
|
let asset_source = Arc::new(Assets);
|
||||||
gpui3::App::production(asset_source).run(move |cx| {
|
gpui3::App::production(asset_source).run(move |cx| {
|
||||||
|
|
|
@ -1,3 +1,32 @@
|
||||||
mod rose_pine;
|
mod rose_pine;
|
||||||
|
|
||||||
pub use rose_pine::*;
|
pub use rose_pine::*;
|
||||||
|
|
||||||
|
use gpui3::serde_json;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use ui::Theme;
|
||||||
|
|
||||||
|
use crate::assets::Assets;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct LegacyTheme {
|
||||||
|
pub base_theme: serde_json::Value,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_theme(override_theme_name: Option<String>) -> Theme {
|
||||||
|
let theme = if let Some(theme) = override_theme_name {
|
||||||
|
let theme_contents = Assets::get(&format!("themes/{theme}.json"))
|
||||||
|
.unwrap_or_else(|| panic!("failed to load theme: {theme}.json"));
|
||||||
|
|
||||||
|
let legacy_theme: LegacyTheme =
|
||||||
|
serde_json::from_str(std::str::from_utf8(&theme_contents.data).unwrap()).unwrap();
|
||||||
|
|
||||||
|
let new_theme: Theme = serde_json::from_value(legacy_theme.base_theme.clone()).unwrap();
|
||||||
|
|
||||||
|
new_theme
|
||||||
|
} else {
|
||||||
|
rose_pine_dawn()
|
||||||
|
};
|
||||||
|
|
||||||
|
theme
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue