1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-01-19 04:21:06 +00:00

HighlightingAssets: Introduce private fn new() helper

It already now reduces code duplication slightly, but will become even more
useful in the future when we add more complicated logic such as lazy-loading.
This commit is contained in:
Martin Nordholts 2021-07-19 05:41:40 +02:00
parent 375d55aa5d
commit f6fc826dc6

View File

@ -41,6 +41,14 @@ const IGNORED_SUFFIXES: [&str; 10] = [
]; ];
impl HighlightingAssets { impl HighlightingAssets {
fn new(syntax_set: SyntaxSet, theme_set: ThemeSet) -> Self {
HighlightingAssets {
syntax_set,
theme_set,
fallback_theme: None,
}
}
pub fn default_theme() -> &'static str { pub fn default_theme() -> &'static str {
"Monokai Extended" "Monokai Extended"
} }
@ -89,19 +97,17 @@ impl HighlightingAssets {
); );
} }
Ok(HighlightingAssets { Ok(HighlightingAssets::new(
syntax_set: syntax_set_builder.build(), syntax_set_builder.build(),
theme_set, theme_set,
fallback_theme: None, ))
})
} }
pub fn from_cache(cache_path: &Path) -> Result<Self> { pub fn from_cache(cache_path: &Path) -> Result<Self> {
Ok(HighlightingAssets { Ok(HighlightingAssets::new(
syntax_set: asset_from_cache(&cache_path.join("syntaxes.bin"), "syntax set")?, asset_from_cache(&cache_path.join("syntaxes.bin"), "syntax set")?,
theme_set: asset_from_cache(&cache_path.join("themes.bin"), "theme set")?, asset_from_cache(&cache_path.join("themes.bin"), "theme set")?,
fallback_theme: None, ))
})
} }
fn get_integrated_syntaxset() -> SyntaxSet { fn get_integrated_syntaxset() -> SyntaxSet {
@ -113,14 +119,10 @@ impl HighlightingAssets {
} }
pub fn from_binary() -> Self { pub fn from_binary() -> Self {
let syntax_set = Self::get_integrated_syntaxset(); HighlightingAssets::new(
let theme_set = Self::get_integrated_themeset(); Self::get_integrated_syntaxset(),
Self::get_integrated_themeset(),
HighlightingAssets { )
syntax_set,
theme_set,
fallback_theme: None,
}
} }
pub fn save_to_cache(&self, target_dir: &Path, current_version: &str) -> Result<()> { pub fn save_to_cache(&self, target_dir: &Path, current_version: &str) -> Result<()> {