A3S TUI
TEA (The Elm Architecture) framework for terminal user interfaces
A3S TUI is a Rust library for building terminal applications using The Elm Architecture pattern. It combines declarative UI with Flexbox layout, incremental rendering, and a rich component library.
Why
Most terminal UI libraries force you to manage state, layout, and rendering manually. A3S TUI brings modern UI patterns to the terminal:
- TEA Architecture — predictable state management with Model-Update-View
- Declarative UI — describe what you want, not how to draw it
- Flexbox Layout — CSS-like layout powered by Taffy
- Incremental Rendering — only redraw what changed
- Rich Components — 16 ready-to-use components (tables, modals, text editors, etc.)
Quick Start
Add to Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
Create a counter app:
use ;
use ;
use Color;
async
Run with cargo run --example counter_element.
Features
Architecture
- TEA Pattern — Model-Update-View cycle with immutable state
- Element Tree — Virtual DOM-like tree structure for declarative UI
- Taffy Flexbox — CSS Flexbox layout engine (flex-direction, gap, padding, align-items, justify-content)
- Incremental Rendering — Line-diff algorithm minimizes terminal redraws
- Async Runtime — Non-blocking event loop powered by Tokio
Components
| Component | Description |
|---|---|
Alert |
Colored alerts (Success/Info/Warning/Error) |
Badge |
Inline status badges |
Divider |
Horizontal/vertical separators |
List |
Scrollable list with selection |
MultiSelect |
Multi-selection list with checkboxes |
Select |
Single-selection dropdown |
Table |
Data table with headers |
Tabs |
Tab navigation |
TextInput |
Single-line text input |
Textarea |
Multi-line text editor with scrolling |
Viewport |
Scrollable content container |
Modal |
Overlay dialog |
StatusBar |
Bottom status bar |
Progress |
Progress bar |
Spinner |
Loading animation |
Layout & Styling
- Flexbox Layout —
FlexDirection,AlignItems,JustifyContent - Dimensions —
Auto,Points(f32),Percent(f32) - Spacing —
padding,margin,gap - Borders —
Single,Double,Rounded,Thick - Colors — 16 ANSI colors + RGB support
- Text Styles — bold, italic, underline, dim, strikethrough
Advanced Features
- Markdown Rendering — Full CommonMark support with syntax highlighting (via
syntect) - Streaming Content — Real-time text streaming (perfect for LLM outputs)
- Keymap System — Vim-like key bindings
- Focus Management — Tab navigation between components
- Mouse Support — Click and scroll events (coming soon)
Examples
Component Demo
use ;
use ;
Run cargo run --example demo to see all components in action.
Chat Application
See examples/chat.rs for a complete chat UI with:
- Markdown rendering with syntax highlighting
- Streaming text output
- Modal dialogs
- Scrollable viewport
- Custom keybindings
Architecture
TEA Flow
┌─────────────────────────────────────────┐
│ User Input (keyboard, resize, etc.) │
└──────────────────┬──────────────────────┘
│
▼
┌─────────────────┐
│ Event → Msg │
└────────┬────────┘
│
▼
┌─────────────────┐
│ update(msg) │ ← Modify state
└────────┬────────┘
│
▼
┌─────────────────┐
│ view() │ ← Build Element tree
└────────┬────────┘
│
▼
┌─────────────────┐
│ Layout Engine │ ← Taffy Flexbox
└────────┬────────┘
│
▼
┌─────────────────┐
│ Renderer │ ← Paint to grid
└────────┬────────┘
│
▼
┌─────────────────┐
│ Terminal │ ← Crossterm output
└─────────────────┘
Element Tree
Elements are the building blocks of your UI:
Use macros for concise syntax:
col!
API Reference
Core Traits
ElementModel
Builders
ElementProgramBuilder
new
.with_alt_screen // Use alternate screen buffer
.with_fps // Target frame rate
.with_mouse // Enable mouse events
.run
.await
Macros
col![...]— Vertical column (FlexDirection::Column)row![...]— Horizontal row (FlexDirection::Row)text!("...")— Text element shorthandspacer!()— Flexible spacer
Comparison
| Feature | a3s-tui | ratatui | cursive |
|---|---|---|---|
| Architecture | TEA | Immediate mode | Object-oriented |
| Layout | Flexbox (Taffy) | Constraints | Linear |
| Rendering | Incremental | Full redraw | Incremental |
| Async | Native (Tokio) | Manual | Callbacks |
| Markdown | Built-in | External | External |
| Components | 16 built-in | DIY | 10+ built-in |
Roadmap
- TEA architecture
- Element tree + Flexbox layout
- 16 core components
- Markdown rendering
- Streaming content
- Keymap system
- Mouse event support
- Grid layout
- Animation system
- Theme system
- Performance benchmarks
- Comprehensive test suite
Contributing
Contributions are welcome! Please:
- Follow Microsoft Rust Guidelines
- Run
cargo fmtandcargo clippybefore committing - Add tests for new features
- Update documentation
License
MIT License - see LICENSE for details.