tui
A lightweight, composable terminal UI library for building full-screen CLI apps in Rust.
Your app owns its event loop and state machine. The library provides composable building blocks: a [Component] trait for widgets, a diff-based [Renderer], and RAII terminal management.
Table of Contents
Minimal app
A complete TUI app has four parts: a [TerminalSession] (raw mode guard), a [Renderer] (output), an event source, and a loop that wires them together.
use io;
use ;
// 1. Define your root component
// 2. Set up terminal, renderer, and event source
async
Dropping _session automatically restores the terminal (disables raw mode, bracketed paste, and mouse capture).
How it works
crossterm::Event ──→ Event::try_from ──→ Component::on_event ──→ Vec<Message>
│ │
▼ ▼
Component::render parent handles messages
│
▼
Renderer::render_frame (diff → ANSI)
- [
spawn_terminal_event_task()] reads raw crossterm events in a blocking tokio task. - [
Event::try_from] filters key releases and normalizes resize events. - [
Component::on_event] returnsNone(ignored),Some(vec![])(consumed), orSome(vec![msg])(messages for the parent). - [
Component::render] returns a [Frame] (lines + cursor) given a [ViewContext] (size + theme). - [
Renderer::render_frame] diffs against the previous frame and emits only changed ANSI sequences.
Composing components
Nest components by owning them in your parent and delegating events:
use ;
Use [FocusRing] to track which child receives events and [Layout] to stack frames vertically.
Built-in widgets
| Widget | Description |
|---|---|
[TextField] |
Single-line text input |
[NumberField] |
Numeric input (integer or float) |
[Checkbox] |
Boolean toggle [x] / [ ] |
[RadioSelect] |
Single-select radio buttons |
[MultiSelect] |
Multi-select checkboxes |
[SelectList] |
Scrollable list with selection |
[Form] |
Multi-field tabbed form |
[Panel] |
Bordered container |
[Spinner] |
Animated progress indicator |
[Combobox] |
Fuzzy-searchable picker (feature: picker) |
Feature flags
| Feature | Description | Default |
|---|---|---|
syntax |
Syntax highlighting, markdown rendering, diff previews via syntect | yes |
picker |
Fuzzy combobox picker via nucleo | yes |
testing |
Test utilities (TestTerminal, render_component, assert_buffer_eq) |
no |
Disable defaults for a smaller dependency tree:
[]
= { = "0.1", = false }
License
MIT