Skip to content

Commit

Permalink
theme inherent for default theme
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterliao29 committed Dec 19, 2022
1 parent 99b346a commit 5acd288
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions helix-view/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ use toml::{map::Map, Value};
use crate::graphics::UnderlineStyle;
pub use crate::graphics::{Color, Modifier, Style};

// store default theme in to byte array.
const DEFAULT_THEME_DATA: &[u8] = include_bytes!("../../theme.toml");
const BASE16_DEFAULT_THEME_DATA: &[u8] = include_bytes!("../../base16_theme.toml");

pub static DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| Theme {
name: "default".into(),
..toml::from_slice(include_bytes!("../../theme.toml")).expect("Failed to parse default theme")
..toml::from_slice(DEFAULT_THEME_DATA).expect("Failed to parse default theme")
});

pub static BASE16_DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| Theme {
name: "base16_theme".into(),
..toml::from_slice(include_bytes!("../../base16_theme.toml"))
.expect("Failed to parse base 16 default theme")
..toml::from_slice(BASE16_DEFAULT_THEME_DATA).expect("Failed to parse base 16 default theme")
});

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -78,11 +81,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" => toml::from_slice(DEFAULT_THEME_DATA)?,
"base16_default" => toml::from_slice(BASE16_DEFAULT_THEME_DATA)?,
_ => self.load_theme(
parent_theme_name,
base_them_name,
base_them_name == parent_theme_name,
)?,
};

self.merge_themes(parent_theme_toml, theme_toml)
} else {
Expand Down

0 comments on commit 5acd288

Please sign in to comment.