Reratui
A Modern, Reactive TUI Framework for Rust
Build beautiful, interactive terminal applications with React-inspired components and hooks
Getting Started β’ Documentation β’ Examples β’ Contributing
Overview
Reratui brings modern web development patterns to terminal user interfaces. Inspired by React, it provides a component-based architecture with hooks, enabling you to build complex, stateful TUI applications with clean, maintainable code.
Why Reratui?
- π¨ Declarative UI - Build interfaces with JSX-like syntax using the
rsx!macro - πͺ React-Style Hooks - Manage state and side effects with familiar patterns
- β‘ High Performance - Zero-cost abstractions with compile-time optimizations
- π Type-Safe - Leverage Rust's type system for compile-time correctness
- π Async-First - Built on Tokio with first-class async/await support
- π§© Modular - Compose complex UIs from simple, reusable components
β¨ Features
ποΈ Component System
- Component-based architecture with lifecycle hooks
- Reusable, composable components
- Type-safe props with
#[derive(Props)] - Automatic prop validation
πͺ Comprehensive Hooks
- State management (
use_state,use_reducer) - Side effects (
use_effect,use_async_effect) - Performance (
use_memo,use_callback) - Events (keyboard, mouse, resize)
π― Developer Experience
- JSX-like
rsx!macro syntax - Compile-time hook rules validation
- Comprehensive error messages
- Hot-reload support (coming soon)
β‘ Performance
- Zero-cost abstractions
- Compile-time macro expansion
- Efficient event handling
- Minimal runtime overhead
| Category | Hook | Description |
|---|---|---|
| State | use_state |
Local component state management |
use_reducer |
Complex state logic with actions (Redux-style) | |
use_ref |
Mutable references that persist across renders | |
| Effects | use_effect |
Side effects with dependency tracking |
use_effect_once |
Run effect only on mount | |
use_async_effect |
Async side effects with cleanup | |
| Performance | use_callback |
Memoized callbacks to prevent re-renders |
use_memo |
Memoized computed values | |
use_effect_event |
Stable event handlers with latest values | |
| Context | use_context |
Access shared data without prop drilling |
use_context_provider |
Provide context values to children | |
| Events | use_event |
Generic terminal event handling |
use_keyboard |
Keyboard events with stable callbacks | |
use_keyboard_press |
Handle key press events only | |
use_keyboard_shortcut |
Specific key combinations | |
use_mouse |
Mouse events with stable callbacks | |
use_mouse_click |
Handle mouse click events | |
use_mouse_drag |
Track drag operations | |
use_double_click |
Detect double-click gestures | |
on_global_event |
Global keyboard event handlers | |
| Layout | use_frame |
Frame timing and render context |
use_area |
Component's rendering area | |
use_on_resize |
Handle terminal resize events | |
use_terminal_dimensions |
Current terminal size |
π Installation
Add Reratui to your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["full"] }
Note: The main
reratuicrate re-exports all necessary functionality. You typically don't need to add individual sub-crates.
π Quick Start
Your First Component
use *;
async
Component with Props
use *;
π Advanced Usage
Complex State with Reducers
use *;
Context for Global State
Share state across components without prop drilling:
ποΈ Architecture
Reratui follows a modular, layered architecture with clear separation of concerns:
βββββββββββββββββββββββββββββββββββββββββββββββ
β reratui (Main Crate) β β Public API
βββββββββββββββββββββββββββββββββββββββββββββββ€
β reratui-macro β reratui-hooks β β Developer Tools
βββββββββββββββββββββββββββββββββββββββββββββββ€
β reratui-core β reratui-runtime β β Core Engine
βββββββββββββββββββββββββββββββββββββββββββββββ€
β reratui-ratatui (Backend) β β Rendering
βββββββββββββββββββββββββββββββββββββββββββββββ
Crate Structure
| Crate | Purpose |
|---|---|
reratui |
Main crate - re-exports all functionality |
reratui-core |
Core types (Element, Component, VNode) |
reratui-macro |
Procedural macros (#[component], rsx!, Props) |
reratui-hooks |
Hook implementations and state management |
reratui-runtime |
Event loop, lifecycle, and rendering runtime |
reratui-ratatui |
Ratatui backend integration |
Design Principles
| Principle | Implementation |
|---|---|
| SOLID | Single responsibility, interface segregation, dependency inversion |
| DDD | Clear domain boundaries with well-defined interfaces |
| Composition | Build complex UIs by composing simple components |
| Type Safety | Leverage Rust's type system for compile-time correctness |
| Zero-Cost | No runtime overhead for abstractions |
π‘ Examples
Explore complete, runnable examples in the examples/ directory:
| Example | Description | Command |
|---|---|---|
| counter | Basic state management and keyboard events | cargo run --example counter |
| rsx_demo | Comprehensive RSX macro features | cargo run --example rsx_demo |
| events_showcase | Complete event handling (keyboard, mouse, resize) | cargo run --example events_showcase |
| router | Navigation and routing | Coming soon |
π Documentation
| Resource | Description |
|---|---|
| API Docs | Complete API reference with examples |
| Examples | Working code examples and demos |
| Hooks Guide | Detailed hook usage patterns |
| Component Patterns | Best practices and design patterns |
π§ Requirements
Minimum Supported Rust Version (MSRV): 1.75.0
Required for:
let-elsestatementsletchains inifexpressions- Edition 2024 features
π€ Contributing
We welcome contributions! See our Contributing Guide for:
- π Code of conduct
- π οΈ Development setup
- β Testing requirements
- π Pull request process
πΊοΈ Roadmap
β Completed
- Core component system with lifecycle hooks (
on_mount,on_unmount) - Comprehensive hooks system (state, effect, reducer, context)
- RSX macro with conditional rendering
- Hook rules validation at compile-time
- Event handling (keyboard, mouse, resize)
- Global event system for application-wide shortcuts
π§ In Progress
- Router with nested routes
- Form validation helpers
- Animation system
π Planned
- Dev tools and debugging utilities
- Performance profiling tools
- Hot-reload support
- Component testing utilities
π License
Dual-licensed under your choice of:
- Apache License 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion shall be dual licensed as above, without additional terms or conditions.
π Acknowledgments
Reratui stands on the shoulders of giants:
- Ratatui - The powerful TUI library that powers our rendering
- React - Inspiration for component architecture and hooks patterns
- Yew - Rust web framework with similar design patterns
Built with β€οΈ by the Rust community
β Star us on GitHub β’ π Read the Docs β’ π¬ Join Discussions