@@ -11,15 +11,18 @@ use crate::errors::*;
1111use crate::inputfile::{InputFile, InputFileReader};
1212use crate::syntax_mapping::SyntaxMapping;
1313
14−pub const BAT_THEME_DEFAULT: &str = "Monokai Extended";
15−
1614#[derive(Debug)]
1715pub struct HighlightingAssets {
1816 pub(crate) syntax_set: SyntaxSet,
1917 pub(crate) theme_set: ThemeSet,
18+ fallback_theme: Option<&'static str>,
2019}
2120
2221impl HighlightingAssets {
22+ pub fn default_theme() -> &'static str {
23+ "Monokai Extended"
24+ }
25+
2326 pub fn from_files(source_dir: &Path, start_empty: bool) -> Result<Self> {
2427 let mut theme_set = if start_empty {
2528 ThemeSet {
@@ -60,6 +63,7 @@ impl HighlightingAssets {
6063 Ok(HighlightingAssets {
6164 syntax_set: syntax_set_builder.build(),
6265 theme_set,
66+ fallback_theme: None,
6367 })
6468 }
6569
@@ -85,6 +89,7 @@ impl HighlightingAssets {
8589 Ok(HighlightingAssets {
8690 syntax_set,
8791 theme_set,
92+ fallback_theme: None,
8893 })
8994 }
9095
@@ -103,6 +108,7 @@ impl HighlightingAssets {
103108 HighlightingAssets {
104109 syntax_set,
105110 theme_set,
111+ fallback_theme: None,
106112 }
107113 }
108114
@@ -138,6 +144,10 @@ impl HighlightingAssets {
138144 Ok(())
139145 }
140146
147+ pub fn set_fallback_theme(&mut self, theme: &'static str) {
148+ self.fallback_theme = Some(theme);
149+ }
150+
141151 pub fn syntaxes(&self) -> &[SyntaxReference] {
142152 self.syntax_set.syntaxes()
143153 }
@@ -156,7 +166,7 @@ impl HighlightingAssets {
156166 Yellow.paint("[bat warning]"),
157167 theme
158168 );
159− &self.theme_set.themes[BAT_THEME_DEFAULT]
169+ &self.theme_set.themes[self.fallback_theme.unwrap_or(Self::default_theme())]
160170 }
161171 }
162172 }