@@ -14,19 +14,14 @@ use toml::{map::Map, Value};
14use crate::graphics::UnderlineStyle;
14use crate::graphics::UnderlineStyle;
15pub use crate::graphics::{Color, Modifier, Style};
15pub use crate::graphics::{Color, Modifier, Style};
17−pub static DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| {
17+pub static DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| Theme {
18− // let raw_theme: Value = toml::from_slice(include_bytes!("../../theme.toml"))
18+ name: "default".into(),
19− // .expect("Failed to parse default theme");
20− // Theme::from(raw_theme)
22− toml::from_slice(include_bytes!("../../theme.toml")).expect("Failed to parse default theme")
19+ ..toml::from_slice(include_bytes!("../../theme.toml")).expect("Failed to parse default theme")
24−pub static BASE16_DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| {
25− // let raw_theme: Value = toml::from_slice(include_bytes!("../../base16_theme.toml"))
26− // .expect("Failed to parse base 16 default theme");
27− // Theme::from(raw_theme)
22+pub static BASE16_DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| Theme {
23+ name: "base16_theme".into(),
29− toml::from_slice(include_bytes!("../../base16_theme.toml"))
24+ ..toml::from_slice(include_bytes!("../../base16_theme.toml"))
30 .expect("Failed to parse base 16 default theme")
25 .expect("Failed to parse base 16 default theme")
@@ -53,7 +48,12 @@ impl Loader {
53 return Ok(self.base16_default());
48 return Ok(self.base16_default());
56− self.load_theme(name, name, false).map(Theme::from)
51+ let theme = self.load_theme(name, name, false).map(Theme::from)?;
59 // load the theme and its parent recursively and merge them
59 // load the theme and its parent recursively and merge them
@@ -180,8 +180,10 @@ impl Loader {
183−#[derive(Clone, Debug)]
183+#[derive(Clone, Debug, Default)]
184pub struct Theme {
184pub struct Theme {
185 // UI styles are stored in a HashMap
187 // UI styles are stored in a HashMap
186 styles: HashMap<String, Style>,
188 styles: HashMap<String, Style>,
187 // tree-sitter highlight styles are stored in a Vec to optimize lookups
189 // tree-sitter highlight styles are stored in a Vec to optimize lookups
@@ -200,6 +202,7 @@ impl From<Value> for Theme {
202 highlights,
204 highlights,
205+ ..Default::default()
@@ -217,6 +220,7 @@ impl<'de> Deserialize<'de> for Theme {
219 highlights,
222 highlights,
223+ ..Default::default()
@@ -266,6 +270,10 @@ impl Theme {
266 self.highlights[index]
270 self.highlights[index]
273+ pub fn name(&self) -> &str {
269 pub fn get(&self, scope: &str) -> Style {
277 pub fn get(&self, scope: &str) -> Style {
270 self.try_get(scope).unwrap_or_default()
278 self.try_get(scope).unwrap_or_default()