Expose syntect theme and syntax sets (#2030)

Fixes #2026
Ref https://github.com/dandavison/delta/issues/895
This commit is contained in:
Dan Davison 2022-02-08 02:00:12 -05:00 committed by GitHub
parent 312c8ef01f
commit 4e36a56014
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -18,6 +18,7 @@
## `bat` as a library
- Exposed `get_syntax_set` and `get_theme` methods on `HighlightingAssets`. See #2030 (@dandavison)
# v0.19.0

View File

@ -90,7 +90,8 @@ impl HighlightingAssets {
self.fallback_theme = Some(theme);
}
fn get_syntax_set(&self) -> Result<&SyntaxSet> {
/// Return the collection of syntect syntax definitions.
pub fn get_syntax_set(&self) -> Result<&SyntaxSet> {
self.syntax_set_cell
.get_or_try_init(|| self.serialized_syntax_set.deserialize())
}
@ -186,7 +187,8 @@ impl HighlightingAssets {
}
}
pub(crate) fn get_theme(&self, theme: &str) -> &Theme {
/// Look up a syntect theme by name.
pub fn get_theme(&self, theme: &str) -> &Theme {
match self.get_theme_set().get(theme) {
Some(theme) => theme,
None => {