Skip to main content

Crate hjkl_bonsai

Crate hjkl_bonsai 

Source
Expand description

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

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
    }
}

Re-exports§

pub use comment_markers::CommentMarkerPass;
pub use comment_markers::MarkerWord;
pub use comment_markers::default_markers;
pub use highlighter::HighlightSpan;
pub use highlighter::Highlighter;
pub use highlighter::ParseError;
pub use highlighter::Syntax;
pub use theme::DotFallbackTheme;
pub use theme::Style;
pub use theme::Theme;

Modules§

comment_markers
CommentMarkerPass — TODO/FIXME/NOTE/WARN comment-marker overlay.
highlighter
Stateful syntax highlighter built on top of a runtime-loaded Grammar.
runtime
Runtime grammar loader (Phase 2.x).
theme

Structs§

InputEdit
A summary of a change to a text document.
Point
A position in a multi-line text document, in terms of rows and columns.