1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-02 19:32:25 +01:00

Major restructuring of theme/syntax handling

This commit is contained in:
sharkdp
2020-03-21 16:48:27 +01:00
committed by David Peter
parent b1b8addf7e
commit 06b7be7ee9
10 changed files with 84 additions and 72 deletions

37
src/bin/bat/assets.rs Normal file
View File

@@ -0,0 +1,37 @@
use std::borrow::Cow;
use std::fs;
use std::path::PathBuf;
use crate::directories::PROJECT_DIRS;
use bat::assets::HighlightingAssets;
fn theme_set_path() -> PathBuf {
PROJECT_DIRS.cache_dir().join("themes.bin")
}
fn syntax_set_path() -> PathBuf {
PROJECT_DIRS.cache_dir().join("syntaxes.bin")
}
pub fn config_dir() -> Cow<'static, str> {
PROJECT_DIRS.config_dir().to_string_lossy()
}
pub fn cache_dir() -> Cow<'static, str> {
PROJECT_DIRS.cache_dir().to_string_lossy()
}
pub fn clear_assets() {
print!("Clearing theme set cache ... ");
fs::remove_file(theme_set_path()).ok();
println!("okay");
print!("Clearing syntax set cache ... ");
fs::remove_file(syntax_set_path()).ok();
println!("okay");
}
pub fn assets_from_cache_or_binary() -> HighlightingAssets {
HighlightingAssets::from_cache(&theme_set_path(), &syntax_set_path()).unwrap_or(HighlightingAssets::from_binary())
}