Skip to content

Commit

Permalink
Expose syntect theme and syntax sets (#2030)
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Feb 8, 2022
1 parent 312c8ef commit 4e36a56
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

## `bat` as a library

- Exposed `get_syntax_set` and `get_theme` methods on `HighlightingAssets`. See #2030 (@dandavison)

# v0.19.0

Expand Down
6 changes: 4 additions & 2 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 4e36a56

Please sign in to comment.