即时模版Rust TUI框架有弹性盒布局和Tailwind式链式API.
SuperLightTUI is an immediate-mode TUI library for Rust with a deliberately small public grammar. You write one closure, SLT calls it every frame, and the library handles layout, focus, diffing, and rendering.
It is designed for fast product iteration, approachable Rust syntax, and serious backend discipline. That makes it work equally well for humans prototyping a tool and for coding agents generating UI from docs.
Widget Demo cargo run --example demo
Dashboard cargo run --example showcase_tour
Website Layout cargo run --example showcase_tour
Spreadsheet cargo run --example showcase_tour
Games cargo run --example showcase_tour
DOOM Fire Effect cargo run --example text_tour
Pretext Reflow — text reflows around the mouse cursor in real time cargo run --example text_tour
cargo add superlighttuifn main() -> std::io::Result {
slt::run(|ui: &mut slt::Context| {
ui.text("hello, world");
})
}5 lines. No App trait. No Model/Update/View. No manual event loop. Ctrl+C just works.
MSRV: Rust 1.88. Default features enable the crossterm backend.
There are four ideas most apps start with:
row(), col(), and container().Response.ui.bordered(Border::Rounded).title("Status").p(1).gap(1).col(|ui| {
ui.text("SLT").bold().fg(Color::Cyan);
ui.row(|ui| {
ui.text("mode:");
ui.text("ready").fg(Color::Green);
ui.spacer();
if ui.button("Quit").clicked {
ui.quit();
}
});
});That is the core mental model. Everything else is depth, not a second framework.
…The same closure runs across several entry points. Pick one based on UI shape, not size.
| Mode | API | When to use |
|---|---|---|
| Full-screen | slt::run / slt::run_with |
Standard TUI app — alternate screen, mouse, theme. |
| Inline | slt::run_inline / slt::run_inline_with |
Fixed-height widget below the prompt — no alternate screen. |
| Static + inline | slt::run_static |
Log lines stream into scrollback while an inline UI stays live below. |
| Async messages | slt::run_async (feature: async) |
Background tasks use the wake-aware AsyncSender; retain the returned AsyncRunHandle to join or cancel the loop. |
| Custom backend | slt::frame + Backend + AppState |
Drive rendering yourself — tests, GUI embeds, WASM, snapshot harnesses. |
RunConfig tunes mouse, kitty keyboard, color depth, max FPS, scroll speed, theme, and title across every mode.
Scrollable containers reveal the focused widget when focus, caret, or layout
changes, including nested horizontal/vertical views and modal forms. Manual
scrolling is preserved between those changes; set scroll.follow_focus = false
for application-controlled positioning. Keep one ScrollState per container.
Use ui.form_field_response(...) for field/input interaction feedback without
changing existing ui.form_field(...) callers. ui.focused_layout_rect() and
ui.measured_layout_rect(name) expose previous-frame geometry before scrolling
and clipping; Response.rect remains the visible mouse-hit rectangle.
See the migration guide for the coordinate and timing rules.
[dependencies]
superlighttui = { version = "0.25.0", features = ["async", "image"] }| Feature | What it adds |
|---|---|
async |
tokio + run_async for background message loops |
bidi |
UAX #9 bidirectional text reordering; enabled by default |
serde |
Serialize/Deserialize on selected state types |
theme-watch |
TOML theme hot reload (serde + filesystem watcher) |
image |
PNG/JPEG decoding for ui.image |
qrcode |
QR code rendering |
kitty-compress |
zlib compression for the Kitty image protocol |
syntax |
Tree-sitter highlighting for all bundled languages |
syntax- |
Highlighting for a single language (rust, python, typescript, ...) |
full |
crossterm + async + serde + theme-watch + image + qrcode + kitty-compress + bidi — does not include syntax (grammars are heavy; opt in explicitly) |
row() / col() / container(), method chaining, and Response.Backend, AppState, and frame().unsafe, feature-gated runtime paths, and validation across all-features, no-default-features, WASM, clippy, examples, cargo-hack, semver, and deny checks.For Rust users, that usually means less setup than retained-mode TUI frameworks. For AI-assisted workflows, it means the public grammar is easy to infer from docs and examples.
SLT fits best when you want to build terminal apps quickly without giving up Rust type safety or backend escape hatches. If you want a retained component tree or a GUI-first toolkit, another library may be a better fit.
SLT's rendering pipeline is why the grammar stays small. Your code only touches the first stage — the engine handles the rest.
graph LR
subgraph your_code ["Your Code"]
A["Closure"]
end
subgraph engine ["SLT Engine"]
B[Commands] --> C[Build Tree] --> D[Flexbox] --> E[Collect] --> F[Render] --> G["Diff + Flush"]
end
A -->|"records intent"| B
G -.->|"prev-frame feedback"| AEvery ui.*() call records a command to a flat list — no tree construction, no layout math.
The engine replays those commands through a four-stage DFS pipeline — each stage specializes: build the layout tree, compute flexbox, collect interaction and feedback data, render cells to a back buffer — then diffs against the previous frame and flushes only what changed.
This architecture is what makes the simple grammar possible:
App trait, no Model/Message/Update/View. Your closure is the entire UI. State is normal Rust variables. Control flow is if/for.ui.col(|ui| { ... }) records an "open column" command. The engine builds the tree and runs flexbox — you never see LayoutNode.ui.button("Save") gives you hover, click, and focus for free. The collect stage fused seven independent sub-walks (hit areas, focus rects, scroll regions, group rects, content rects, focus groups, raw-draw rects) into one DFS — so the top-level pipeline is four passes, not ten.For the full eight-stage lifecycle, see [Architecture Guide].
Stateless calls take values; stateful widgets take an explicit state struct so your data keeps living in normal Rust variables across frames.
…State structs (ListState, TableState, TextInputState, TabsState, CommandPaletteState,
ToastState, FilePickerState, RichLogState, ...) are public — keep them in your app
struct or local variables and pass them in each frame.
For the categorized widget list, see [Widget Guide]. For composition advice, see [Patterns Guide].
| Document | What it covers |
|---|---|
| [Quick Start] | Install, first app, closure mental model, layout, widget state |
| [Widget Guide] | Complete API catalog of widgets, runtime methods, and state types |
| [State API Guide] | Public fields, accessors, and mutation methods for widget state |
| [Migration Guide] | Version-by-version breaking changes and upgrade paths |
| [Patterns Guide] | State placement, screen composition, helper extraction, large-app structure |
| [Examples Guide] | Runnable examples grouped by product shape and feature area |
| [Backends Guide] | Backend, AppState, frame(), inline mode, static output |
| [Testing Guide] | TestBackend, EventBuilder, multi-frame tests, backend contract tests |
| [Debugging Guide] | F12 overlay, clipping, focus surprises, previous-frame behavior |
| [AI Guide] | Fastest path for AI-assisted builders and coding agents |
| [Architecture Guide] | Module map, frame lifecycle, layout/render pipeline |
| [Features Guide] | Feature flags, optional dependencies, recommended combos |
| [Animation Guide] | Tween, spring, keyframes, sequence, stagger |
| [Theming Guide] | Theme struct, presets, ThemeBuilder, custom themes |
| [Design Principles] | API constraints and design philosophy |
| [API Design] | Five consistency rules for new widgets and PR review checklist |
| Example | Command | Focus |
|---|---|---|
hello |
cargo run --example hello |
Smallest possible app |
counter |
cargo run --example counter |
State + keyboard input |
demo |
cargo run --example demo |
Broad widget tour |
showcase_tour |
cargo run --example showcase_tour |
Dashboard, CLI, website, game, and showcase layouts |
cookbook_tour |
cargo run --example cookbook_tour |
Form, table, modal, file picker, dashboard recipes |
text_tour |
cargo run --example text_tour |
CJK, pretext, image, and rich text demos |
canvas_tour |
cargo run --example canvas_tour |
Canvas and raw drawing |
system_tour |
cargo run --example system_tour --features async |
Inline, static output, async messages, and system demos |
v020_tour |
cargo run --example v020_tour |
v0.20 API feature tour |
v0211_tour |
cargo run --example v0211_tour |
v0.21.1 API additions |
The full categorized index — including per-release feature tours and showcase demos — lives in [Examples Guide].
scripts/ghostty_demos.sh opens demos in fresh Ghostty windows, which is
useful for skimming the full set side by side. See [Examples Guide] for the
list of demos at each release.
./scripts/ghostty_demos.sh # interactive picker
./scripts/ghostty_demos.sh --features # full feature-tour spread
./scripts/ghostty_demos.sh --showcase # integration showcases onlyWidget when you want reusable high-level building blocks.Backend and drive frame() when you want a non-terminal target, external event loop, or embedded runtime.TestBackend for headless rendering checks and stable interaction tests.The public grammar stays small even when you need the escape hatches.
Read [Contributing], then [Design Principles] and [Architecture Guide]. The release process expects format, check, clippy, tests, examples, and backend gates to stay green.
暂无开放 Issues,或尚未同步最近议题。