Skip to main content
OpenTUI integrates with Tree-sitter to provide fast, accurate syntax highlighting for code. Tree-sitter is an incremental parsing library that powers syntax highlighting in VS Code, Neovim, and many other editors.

Quick Start

Highlight code with the built-in JavaScript/TypeScript support:

Tree-Sitter Client

Initialization

The Tree-sitter client manages parsers and performs highlighting:

One-Time Highlighting

Highlight code without creating a CodeRenderable:

Adding Custom Parsers

Extend language support by adding custom Tree-sitter parsers.

Global Default Parsers

Add parsers that all clients will use:

Per-Client Parsers

Add parsers to specific client instances:

Finding Parsers and Queries

Official Tree-Sitter Parsers

Most popular languages have official parsers on GitHub:

Pattern for Finding Parsers

Using Local Files

For better performance and offline support, bundle parsers with your app:

Automated Parser Management

Automate parser downloads and configuration:

Syntax Styles

Customize how syntax elements are colored:

CodeRenderable

The CodeRenderable component provides a full-featured code viewer:

Filetype Detection

Automatically detect filetype from file paths:
Built-in mappings include:
  • js, jsx → javascript
  • ts, tsx → typescript
  • py → python
  • rs → rust
  • go → go
  • rb → ruby
  • c, h → c
  • cpp, hpp, cc → cpp
  • html → html
  • css → css
  • And many more

Complete Example: Code Viewer

Caching

Parsers and queries are automatically cached to avoid re-downloading:
Cache directory structure:

Performance Tips

Initialize the Tree-sitter client once at app startup:
Bundle parsers to avoid network requests:
Only include parsers you need:

Troubleshooting

Make sure the parser is added before using:
Check that:
  1. Client is initialized: await client.initialize()
  2. Filetype is correct: filetype: "javascript" not "js"
  3. Parser is added for that filetype
If parsers fail to download:
  1. Check internet connection
  2. Verify URLs are correct
  3. Use local files instead of URLs

Next Steps

Building Your First App

Build a complete TUI application

Styling and Colors

Master colors and text styling