mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-27 23:22:00 +01:00
HighlightingAssets: Move out fn get_integrated_*set() to module scope
They are just a way to get access to data embedded in the binary, so they don't conceptually belong inside HighlightingAssets. This has the nice side effect of getting HighlightingAssets::from_cache() and ::from_binary(), that are highly related, next to each other.
This commit is contained in:
parent
b040efff79
commit
1bac3750df
@ -54,7 +54,7 @@ impl HighlightingAssets {
|
|||||||
|
|
||||||
pub fn from_files(source_dir: &Path, include_integrated_assets: bool) -> Result<Self> {
|
pub fn from_files(source_dir: &Path, include_integrated_assets: bool) -> Result<Self> {
|
||||||
let mut theme_set = if include_integrated_assets {
|
let mut theme_set = if include_integrated_assets {
|
||||||
Self::get_integrated_themeset()
|
get_integrated_themeset()
|
||||||
} else {
|
} else {
|
||||||
ThemeSet {
|
ThemeSet {
|
||||||
themes: BTreeMap::new(),
|
themes: BTreeMap::new(),
|
||||||
@ -83,7 +83,7 @@ impl HighlightingAssets {
|
|||||||
builder.add_plain_text_syntax();
|
builder.add_plain_text_syntax();
|
||||||
builder
|
builder
|
||||||
} else {
|
} else {
|
||||||
Self::get_integrated_syntaxset().into_builder()
|
get_integrated_syntaxset().into_builder()
|
||||||
};
|
};
|
||||||
|
|
||||||
let syntax_dir = source_dir.join("syntaxes");
|
let syntax_dir = source_dir.join("syntaxes");
|
||||||
@ -109,19 +109,8 @@ impl HighlightingAssets {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_integrated_syntaxset() -> SyntaxSet {
|
|
||||||
from_binary(include_bytes!("../assets/syntaxes.bin"))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_integrated_themeset() -> ThemeSet {
|
|
||||||
from_binary(include_bytes!("../assets/themes.bin"))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_binary() -> Self {
|
pub fn from_binary() -> Self {
|
||||||
HighlightingAssets::new(
|
HighlightingAssets::new(get_integrated_syntaxset(), get_integrated_themeset())
|
||||||
Self::get_integrated_syntaxset(),
|
|
||||||
Self::get_integrated_themeset(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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<()> {
|
||||||
@ -327,6 +316,14 @@ impl HighlightingAssets {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_integrated_syntaxset() -> SyntaxSet {
|
||||||
|
from_binary(include_bytes!("../assets/syntaxes.bin"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_integrated_themeset() -> ThemeSet {
|
||||||
|
from_binary(include_bytes!("../assets/themes.bin"))
|
||||||
|
}
|
||||||
|
|
||||||
fn asset_to_cache<T: serde::Serialize>(asset: &T, path: &Path, description: &str) -> Result<()> {
|
fn asset_to_cache<T: serde::Serialize>(asset: &T, path: &Path, description: &str) -> Result<()> {
|
||||||
print!("Writing {} to {} ... ", description, path.to_string_lossy());
|
print!("Writing {} to {} ... ", description, path.to_string_lossy());
|
||||||
dump_to_file(asset, &path).chain_err(|| {
|
dump_to_file(asset, &path).chain_err(|| {
|
||||||
|
Loading…
Reference in New Issue
Block a user