diff options
author | sharkdp <davidpeter@web.de> | 2020-03-21 20:31:32 +0100 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2020-03-21 22:21:23 +0100 |
commit | 83dc13a86d4ddc00be23e22f81843bf025517c08 (patch) | |
tree | 32b0a004b5d0591dd89dfb344bfcd9b67bcf9577 /src/assets.rs | |
parent | 094c526a0e5264b509f55c0338970e2f9ed29e9f (diff) |
Add fallback theme, remove BAT_THEME_DEFAULT
Diffstat (limited to 'src/assets.rs')
-rw-r--r-- | src/assets.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/assets.rs b/src/assets.rs index 954bf615..203ae39b 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -11,15 +11,18 @@ use crate::errors::*; use crate::inputfile::{InputFile, InputFileReader}; use crate::syntax_mapping::SyntaxMapping; -pub const BAT_THEME_DEFAULT: &str = "Monokai Extended"; - #[derive(Debug)] pub struct HighlightingAssets { pub(crate) syntax_set: SyntaxSet, pub(crate) theme_set: ThemeSet, + fallback_theme: Option<&'static str>, } impl HighlightingAssets { + pub fn default_theme() -> &'static str { + "Monokai Extended" + } + pub fn from_files(source_dir: &Path, start_empty: bool) -> Result<Self> { let mut theme_set = if start_empty { ThemeSet { @@ -60,6 +63,7 @@ impl HighlightingAssets { Ok(HighlightingAssets { syntax_set: syntax_set_builder.build(), theme_set, + fallback_theme: None, }) } @@ -85,6 +89,7 @@ impl HighlightingAssets { Ok(HighlightingAssets { syntax_set, theme_set, + fallback_theme: None, }) } @@ -103,6 +108,7 @@ impl HighlightingAssets { HighlightingAssets { syntax_set, theme_set, + fallback_theme: None, } } @@ -138,6 +144,10 @@ impl HighlightingAssets { Ok(()) } + pub fn set_fallback_theme(&mut self, theme: &'static str) { + self.fallback_theme = Some(theme); + } + pub fn syntaxes(&self) -> &[SyntaxReference] { self.syntax_set.syntaxes() } @@ -156,7 +166,7 @@ impl HighlightingAssets { Yellow.paint("[bat warning]"), theme ); - &self.theme_set.themes[BAT_THEME_DEFAULT] + &self.theme_set.themes[self.fallback_theme.unwrap_or(Self::default_theme())] } } } |