SuperLightTUI
Superfast to write. Superlight to run.
Crate · Docs · Examples · Contributing
Showcase
Getting Started
5 lines. No App struct. No Model/Update/View. No event loop. Ctrl+C just works.
A Real App
use ;
State lives in your closure. Layout is row() and col(). Styling chains. That's it.
Why SLT
Your closure IS the app — No framework state. No message passing. No trait implementations. You write a function, SLT calls it every frame.
Everything auto-wires — Focus cycles with Tab. Scroll works with mouse wheel. Containers report clicks and hovers. Widgets consume their own events.
Layout like CSS, syntax like Tailwind — Flexbox with row(), col(), grow(), gap(), spacer(). Tailwind shorthand: .p(), .px(), .py(), .m(), .mx(), .my(), .w(), .h(), .min_w(), .max_w().
ui.container
.border
.p.mx.grow.max_w
.col;
Two core dependencies — crossterm for terminal I/O. unicode-width for character measurement. Optional: tokio for async, serde for serialization, image for image loading. Zero unsafe code.
Widgets
50+ built-in widgets, zero boilerplate:
ui.text_input; // single-line input
ui.textarea; // multi-line editor
if ui.button // button returns bool
ui.checkbox; // toggle checkbox
ui.toggle; // on/off switch
ui.tabs; // tab navigation
ui.list; // selectable list
ui.select; // dropdown select
ui.radio; // radio button group
ui.multi_select; // multi-select checkboxes
ui.tree; // expandable tree view
ui.virtual_list; // virtualized list
ui.table; // data table
ui.spinner; // loading animation
ui.progress; // progress bar
ui.scrollable.col; // scroll container
ui.toast; // notifications
ui.separator; // horizontal line
ui.help; // key hints
ui.link; // clickable hyperlink (OSC 8)
ui.modal; // modal with dim backdrop
ui.overlay; // overlay without backdrop
ui.command_palette; // searchable command palette
ui.markdown; // markdown rendering
ui.form_field; // labeled input with validation
ui.chart; // line/scatter/bar chart
ui.scatter; // standalone scatter plot
ui.histogram; // auto-binned histogram
ui.bar_chart; // horizontal bars
ui.sparkline; // trend line ▁▂▃▅▇
ui.canvas; // braille canvas
ui.grid; // grid layout
// v0.9 additions
ui.divider_text; // labeled horizontal divider
ui.alert; // inline alert banner
ui.breadcrumb; // navigation breadcrumb
ui.accordion; // collapsible section
ui.badge; // inline status badge
ui.key_hint; // single key hint chip
ui.stat; // metric with trend indicator
ui.definition_list; // term/value pairs
ui.empty_state; // empty placeholder
ui.code_block; // syntax-highlighted code
ui.code_block_numbered; // code with line numbers
ui.streaming_text; // AI streaming text with cursor
ui.tool_approval; // approve/reject tool call
ui.context_bar; // context window token bar
ui.image; // half-block image rendering
ui.stat_colored; // colored metric card
ui.stat_trend; // metric with trend arrow
ui.badge_colored; // colored status badge
ui.empty_state_action; // empty state with button
// v0.10 additions
ui.consume_key; // explicit event consumption
ui.consume_key_code; // consume special keys
Every widget handles its own keyboard events, focus state, and mouse interaction.
Custom Widgets
Implement the Widget trait to build your own:
use ;
// Usage: ui.widget(&mut rating);
Focus, events, theming, layout — all accessible through Context. One trait, one method.
Features
| Feature | API |
|---|---|
| Vertical stack | ui.col(|ui| { }) |
| Horizontal stack | ui.row(|ui| { }) |
| Grid layout | ui.grid(3, |ui| { }) |
| Gap between children | .gap(1) |
| Flex grow | .grow(1) |
| Push to end | ui.spacer() |
| Alignment | .align(Align::Center) |
| Padding | .p(1), .px(2), .py(1) |
| Margin | .m(1), .mx(2), .my(1) |
| Fixed size | .w(20), .h(10) |
| Constraints | .min_w(10), .max_w(60) |
| Percentage sizing | .w_pct(50), .h_pct(80) |
| Justify | .space_between(), .space_around(), .space_evenly() |
| Text wrapping | ui.text_wrap("long text...") |
| Borders with titles | .border(Border::Rounded).title("Panel") |
| Per-side borders | .border_top(false), .border_sides(BorderSides::horizontal()) |
| Responsive gap | .gap_at(Breakpoint::Md, 2) |
ui.text.bold.italic.underline.fg.bg;
16 named colors · 256-color palette · 24-bit RGB · 6 modifiers · 6 border styles
// 7 built-in presets
run_with;
// Build custom themes — unfilled fields default to Theme::dark()
let theme = builder
.primary
.accent
.build;
7 presets (dark, light, dracula, catppuccin, nord, solarized_dark, tokyo_night). Custom themes with 15 color slots + is_dark flag. All widgets inherit automatically. Theme::light() uses high-contrast Tailwind slate-based palette.
use ;
// Define reusable styles — const for zero runtime cost
const CARD: ContainerStyle = new
.border.p.bg;
const DANGER: ContainerStyle = new
.bg;
// Apply one
ui.container.apply.col;
// Compose multiple — last write wins
ui.container.apply.apply.col;
// Mix with inline overrides
ui.container.apply.grow.gap.col;
Define once, apply anywhere. const styles have zero runtime cost. Compose by chaining .apply() calls — inline methods always override.
ui.container
.bg
.dark_bg // applied when dark mode active
.col;
ui.set_dark_mode; // toggle
Container-level style overrides that activate based on dark/light mode.
ui.container
.w.md_w.lg_w // width changes at breakpoints
.p.lg_p
.col;
35 breakpoint-conditional methods (xs_, sm_, md_, lg_, xl_ × w, h, min_w, max_w, gap, p, grow). Breakpoints: Xs (<40), Sm (40–79), Md (80–119), Lg (120–159), Xl (≥160).
ui.group
.border
.group_hover_bg
.col;
Parent container hover/focus state propagates to children. Like Tailwind's group-hover:.
let count = ui.use_state;
ui.text;
if ui.button
let doubled = *ui.use_memo;
React-style persistent state in immediate mode. State<T> handle pattern. Call in same order every frame.
- Double-buffer diff — only changed cells hit the terminal
- Synchronized output — DECSET 2026 prevents tearing on supported terminals
- u32 coordinates — no overflow on large terminals
- Clipping — content outside container bounds is hidden
- Viewport culling — off-screen widgets are skipped entirely
- FPS cap —
RunConfig { max_fps: Some(60), .. }for CPU control - Non-TTY safety — graceful exit when stdout is not a terminal
- Resize handling — automatic reflow on terminal resize
collect_all()— single DFS pass replaces 7 separate tree traversals (v0.9)- Delta flush —
apply_style_delta()emits only changed attributes per cell (v0.9) - Keyframes pre-sort — stops sorted at build time, not per-frame (v0.9)
let mut tween = new.easing;
let value = tween.value;
let mut spring = new;
spring.set_target;
let mut kf = new
.stop.stop.stop
.loop_mode;
let mut seq = new
.then
.then;
let mut stagger = new.delay;
let val = stagger.value;
Tween with 9 easing functions. Spring physics. Keyframe timelines with loop modes. Sequence chains. Stagger for list animations. All support .on_complete() callbacks (.on_settle() for Spring).
run_inline;
Render a fixed-height UI below the cursor without taking over the terminal.
let tx = run_async?;
tx.send.await?;
Optional tokio integration. Enable with cargo add superlighttui --features async.
ui.error_boundary;
ui.error_boundary_with;
Catch widget panics without crashing the app. Partial commands are rolled back and a fallback is rendered.
let mut email = with_placeholder;
ui.text_input;
email.validate;
Call .validate() after text_input() to show inline error messages. Works with form_field() for grouped form validation.
ui.modal;
ui.overlay;
modal() dims the background and renders content on top. overlay() renders floating content without dimming. Both support full layout and interaction.
ui.link;
Renders clickable OSC 8 hyperlinks. Ctrl/Cmd+click opens in browser on supporting terminals (iTerm2, WezTerm, Ghostty, Windows Terminal).
use TestBackend;
let mut backend = new;
backend.run;
assert_snapshot!;
Use with insta for snapshot-based UI regression tests.
Serialize/deserialize Style, Color, Theme, Border, Padding, Margin, Constraints, and Modifiers.
use HalfBlockImage;
let photo = open.unwrap;
let img = from_dynamic;
ui.image;
Half-block (▀▄) image rendering. Also works without the image feature via HalfBlockImage::from_rgb().
| Flag | Description |
|---|---|
async |
run_async() with tokio channel-based message passing |
serde |
Serialize/Deserialize for Style, Color, Theme, layout types |
image |
HalfBlockImage::from_dynamic() with the image crate |
full |
All of the above |
[]
= { = "0.10", = ["full"] }
use ;
let mut backend = new;
let events = new.key.key_code.build;
backend.run_with_events;
assert!;
Headless rendering with TestBackend and event simulation with EventBuilder for automated testing.
ui.container.w.h.draw;
ContainerBuilder::draw() gives you raw access to the cell buffer for pixel-level rendering. Useful for custom effects, games, and image rendering. The closure receives (&mut Buffer, Rect) and runs after layout is resolved.
ui.code_block;
Renders code with One Dark palette syntax highlighting. Supports Rust keywords, string literals, comments, and numeric literals. Falls back to plain monospace for unknown languages.
Press F12 in any SLT app to toggle the layout debugger overlay. Shows container bounds, nesting depth, and layout structure.
Examples
| Example | Command | What it shows |
|---|---|---|
| hello | cargo run --example hello |
Minimal setup |
| counter | cargo run --example counter |
State + keyboard |
| demo | cargo run --example demo |
All widgets |
| demo_dashboard | cargo run --example demo_dashboard |
Live dashboard |
| demo_cli | cargo run --example demo_cli |
CLI tool layout |
| demo_spreadsheet | cargo run --example demo_spreadsheet |
Data grid |
| demo_website | cargo run --example demo_website |
Website in terminal |
| demo_game | cargo run --example demo_game |
Tetris + Snake + Minesweeper |
| demo_fire | cargo run --release --example demo_fire |
DOOM fire effect (half-block) |
| demo_ime | cargo run --example demo_ime |
Korean/CJK IME input |
| inline | cargo run --example inline |
Inline mode |
| anim | cargo run --example anim |
Tween + Spring + Keyframes |
| demo_infoviz | cargo run --example demo_infoviz |
Data visualization |
| async_demo | cargo run --example async_demo --features async |
Background tasks |
Architecture
Closure → Context collects Commands → build_tree() → flexbox layout → diff buffer → flush
Each frame: your closure runs, SLT collects what you described, computes flexbox layout, diffs against the previous frame, and flushes only the changed cells.
Pure Rust. No macros, no code generation, no build scripts.
Contributing
See CONTRIBUTING.md for guidelines.