1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! `hjkl-bonsai` — generic tree-sitter syntax highlighting for the hjkl editor stack.
//!
//! Grammars are loaded at runtime via the [`runtime`] module: the loader
//! resolves `<name>.so` from a system / user / cache lookup chain, falling
//! back to a clone + compile-on-demand path. Pair a [`runtime::Grammar`] with
//! a [`Highlighter`] to drive parsing.
//!
//! # Quick start
//!
//! ```no_run
//! use std::sync::Arc;
//! use hjkl_bonsai::{Highlighter, DotFallbackTheme, Theme};
//! use hjkl_bonsai::runtime::{Grammar, GrammarLoader, GrammarRegistry};
//!
//! let registry = GrammarRegistry::embedded()?;
//! let loader = GrammarLoader::user_default(registry.meta())?;
//!
//! let spec = registry.by_name("rust").unwrap();
//! let grammar = Arc::new(Grammar::load("rust", spec, &loader, registry.meta())?);
//! let mut highlighter = Highlighter::new(grammar)?;
//! let spans = highlighter.highlight(b"fn main() {}");
//!
//! let theme = DotFallbackTheme::dark();
//! for span in &spans {
//! if let Some(_style) = theme.style(span.capture()) {
//! // apply style to byte_range in your renderer
//! }
//! }
//! # Ok::<(), anyhow::Error>(())
//! ```
// Flat re-exports for the primary public API surface.
pub use ;
pub use ;
pub use ;
pub use ;