@@ -16,6 +16,8 @@ lazy_static! {
1616 ProjectDirs::from("", "", crate_name!()).expect("Could not get home directory");
1717}
1818
19+pub const BAT_THEME_DEFAULT: &str = "Monokai Extended";
20+
1921pub struct HighlightingAssets {
2022 pub syntax_set: SyntaxSet,
2123 pub theme_set: ThemeSet,
@@ -50,11 +52,8 @@ impl HighlightingAssets {
5052
5153 let theme_dir = source_dir.join("themes");
5254
53− if let Ok(theme_set) = ThemeSet::load_from_folder(&theme_dir) {
54− // TODO: If syntect would support this, it would be great to
55− // load the new themes in addition to the ones in the binary.
56− assets.theme_set = theme_set;
57− } else {
55+ let res = extend_theme_set(&mut assets.theme_set, &theme_dir);
56+ if !res.is_ok() {
5857 println!(
5958 "No themes were found in '{}', using the default set",
6059 theme_dir.to_string_lossy()
@@ -160,7 +159,7 @@ impl HighlightingAssets {
160159 Yellow.paint("[bat warning]"),
161160 theme
162161 );
163− &self.theme_set.themes["Default"]
162+ &self.theme_set.themes[BAT_THEME_DEFAULT]
164163 }
165164 }
166165 }
@@ -194,6 +193,21 @@ impl HighlightingAssets {
194193 }
195194}
196195
196+// TODO: ideally, this function would be part of syntect's `ThemeSet`.
197+fn extend_theme_set<P: AsRef<Path>>(theme_set: &mut ThemeSet, folder: P) -> Result<()> {
198+ let paths = ThemeSet::discover_theme_paths(folder)?;
199+ for p in &paths {
200+ let theme = ThemeSet::get_theme(p)?;
201+ let basename = p
202+ .file_stem()
203+ .and_then(|x| x.to_str())
204+ .ok_or("Could not get theme basename")?;
205+ theme_set.themes.insert(basename.to_owned(), theme);
206+ }
207+
208+ Ok(())
209+}
210+
197211fn theme_set_path() -> PathBuf {
198212 PROJECT_DIRS.cache_dir().join("themes.bin")
199213}