From e0f961af99e597b0cba8e51bc5bdd745331ca6a5 Mon Sep 17 00:00:00 2001 From: hunterliao29 Date: Mon, 19 Dec 2022 15:43:40 -0500 Subject: [PATCH 1/2] theme inherent for default theme --- helix-view/src/theme.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index b2c8a79f76aa..870224434fbf 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -14,15 +14,24 @@ use toml::{map::Map, Value}; use crate::graphics::UnderlineStyle; pub use crate::graphics::{Color, Modifier, Style}; +// store default theme in to byte array. +// const BASE16_DEFAULT_THEME_DATA: &[u8] = include_bytes!("../../base16_theme.toml"); +pub static DEFAULT_THEME_DATA: Lazy = Lazy::new(|| { + toml::from_slice(include_bytes!("../../theme.toml")).expect("Failed to parse default theme") +}); +pub static BASE16_DEFAULT_THEME_DATA: Lazy = Lazy::new(|| { + toml::from_slice(include_bytes!("../../base16_theme.toml")) + .expect("Failed to parse base 16 default theme") +}); + pub static DEFAULT_THEME: Lazy = Lazy::new(|| Theme { name: "default".into(), - ..toml::from_slice(include_bytes!("../../theme.toml")).expect("Failed to parse default theme") + ..Theme::from(DEFAULT_THEME_DATA.clone()) }); pub static BASE16_DEFAULT_THEME: Lazy = Lazy::new(|| Theme { - name: "base16_theme".into(), - ..toml::from_slice(include_bytes!("../../base16_theme.toml")) - .expect("Failed to parse base 16 default theme") + name: "base16_default".into(), + ..Theme::from(BASE16_DEFAULT_THEME_DATA.clone()) }); #[derive(Clone, Debug)] @@ -78,11 +87,16 @@ impl Loader { ) })?; - let parent_theme_toml = self.load_theme( - parent_theme_name, - base_them_name, - base_them_name == parent_theme_name, - )?; + let parent_theme_toml = match parent_theme_name { + // load default themes's toml from const. + "default" => DEFAULT_THEME_DATA.clone(), + "base16_default" => BASE16_DEFAULT_THEME_DATA.clone(), + _ => self.load_theme( + parent_theme_name, + base_them_name, + base_them_name == parent_theme_name, + )?, + }; self.merge_themes(parent_theme_toml, theme_toml) } else { From 69ce87b4abeff6a652b117f794c8b290e0480e59 Mon Sep 17 00:00:00 2001 From: hunterliao29 Date: Thu, 29 Dec 2022 11:18:32 -0500 Subject: [PATCH 2/2] theme inherent clean up --- helix-view/src/theme.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index 870224434fbf..cb0d3ac46d34 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -14,11 +14,10 @@ use toml::{map::Map, Value}; use crate::graphics::UnderlineStyle; pub use crate::graphics::{Color, Modifier, Style}; -// store default theme in to byte array. -// const BASE16_DEFAULT_THEME_DATA: &[u8] = include_bytes!("../../base16_theme.toml"); pub static DEFAULT_THEME_DATA: Lazy = Lazy::new(|| { toml::from_slice(include_bytes!("../../theme.toml")).expect("Failed to parse default theme") }); + pub static BASE16_DEFAULT_THEME_DATA: Lazy = Lazy::new(|| { toml::from_slice(include_bytes!("../../base16_theme.toml")) .expect("Failed to parse base 16 default theme")