limit-tui
Terminal UI components with Virtual DOM rendering for Rust applications.
Build rich terminal interfaces with a React-like component model, powered by Ratatui. Features declarative rendering, diff-based updates, and built-in syntax highlighting.
Part of the Limit ecosystem.
Why This Exists
Building terminal UIs in Rust shouldn't require imperative rendering code. limit-tui brings a React-like Virtual DOM to the terminal, enabling declarative UI components with efficient diff-based updates.
Features
- Virtual DOM: React-like component model with diff-based rendering
- Pre-built components: Chat views, inputs, spinners, progress bars, select menus
- Flexbox layout: CSS Flexbox-inspired layout system
- Syntax highlighting: Built-in support for 150+ languages via Syntect
- Event handling: Keyboard, mouse, and resize events
- Zero-cost abstractions: Efficient rendering with minimal allocations
Installation
Add to your Cargo.toml:
[]
= "0.0.27"
Requirements: Rust 1.70+, Unix-like OS (Linux, macOS)
Quick Start
Basic Application
use RatatuiBackend;
use ;
use ;
use ;
use ;
Virtual DOM
Build UIs declaratively with VNode:
use VNode;
use ;
let ui = div
.style
.children;
Diff-Based Updates
The Virtual DOM efficiently computes minimal changes:
use ;
let old_tree = text;
let new_tree = text;
let patches = diff;
// patches = [Patch::SetText(0, "Hello, World!")]
apply?;
Components
ChatView
Display conversation messages with role-based styling:
use ;
let chat = new;
InputPrompt
Interactive text input with placeholder:
use InputPrompt;
let input = new
.prefix
.show_cursor;
SelectPrompt
Single/multi-select menus:
use ;
let menu = new
.title;
match menu.result
Spinner & ProgressBar
Loading indicators:
use ;
let spinner = new.label;
let progress = new.label;
Layout System
Flexbox-inspired layout:
use ;
let layout = new
.direction
.justify_content
.align_items
.gap;
Layout Properties
| Property | Values | Description |
|---|---|---|
direction |
Row, Column |
Main axis direction |
justify_content |
Start, Center, End, SpaceBetween, SpaceAround |
Main axis alignment |
align_items |
Start, Center, End, Stretch |
Cross axis alignment |
gap |
u16 |
Spacing between children |
wrap |
bool |
Enable flex wrapping |
Syntax Highlighting
use SyntaxHighlighter;
let highlighter = new?;
let code = highlighter.highlight;
// Returns styled text with syntax colors
Supported Languages
Built-in support for 150+ languages including:
- Rust, Go, Python, JavaScript, TypeScript
- Java, C, C++, C#
- HTML, CSS, SCSS
- JSON, YAML, TOML, XML
- Markdown, SQL, Shell
API Reference
| Module | Description |
|---|---|
vdom |
Virtual DOM types and diff algorithm |
components |
Pre-built UI components |
layout |
Flexbox layout system |
syntax |
Syntax highlighting |
backend |
Ratatui integration |
Examples
# Run examples
License
MIT © Mário Idival