tuika-codeformatters 0.4.2

Tree-sitter syntax highlighting for tuika's CodeBlock and Markdown components — a ready-made Highlighter implementation.
Documentation

tuika-codeformatters

crates.io docs.rs

Tree-sitter syntax highlighting for tuika's CodeBlock and Markdown components.

tuika owns the presentation of code — framing, background, language label, wrapping — but deliberately depends on no grammar, so its dependency set stays small. This companion crate fills the gap: a ready-made tuika::Highlighter backed by tree-sitter grammars, mapping token classes onto the host Theme's code palette so highlighted code follows the theme.

use tuika::{CodeBlock, Theme};
use tuika_codeformatters::TreeSitterHighlighter;

let theme = Theme::default();
let hl = TreeSitterHighlighter::new();
let block = CodeBlock::new("rust", "fn main() {}").highlighter(&hl);
// `block` is a `View`; render it with `tuika::paint` or embed it in a `Flex`.
# let _ = (theme, block);

Examples

A runnable, interactive gallery of highlighted snippets across languages (←/→ or Tab to switch, q to quit):

cargo run -p tuika-codeformatters --example languages

To open a local source file in a scrollable highlighted viewer:

cargo run -p tuika-codeformatters --example highlight_file -- path/to/file.rs

The viewer detects the language from the file extension and falls back to plain code for unknown extensions. Use ↑/↓, j/k, Page Up/Page Down, Home/End, or the mouse wheel to scroll. Drag selects and copies rendered code; q or Esc quits.

Supported languages

Rust, Python, TypeScript/JavaScript, TSX/JSX, Go, Java, Ruby, CSS, HTML, C#, PHP, Zig, Scala, and SQL (with common aliases: rs, py, ts, js, rb, c#, …). Unknown languages — or source that fails to parse — return None, and the caller renders the block as plain, theme-colored code.

Compatibility

ratatui and tuika are part of this crate's public interface, so pin the same minor versions in your own crate and Cargo will deduplicate them.

License

MIT