tears
A simple and elegant framework for building TUI applications using The Elm Architecture (TEA).
Built on top of ratatui, Tears provides a clean, type-safe, and functional approach to terminal user interface development.
Features
- π― Simple & Predictable: Based on The Elm Architecture - easy to reason about and test
- π Async-First: Built-in support for async operations via Commands
- π‘ Subscriptions: Handle terminal events, timers, and custom event sources
- π§ͺ Testable: Pure functions for update logic make testing straightforward
- π Powered by Ratatui: Leverage the full power of the ratatui ecosystem
- π¦ Type-Safe: Leverages Rust's type system for safer TUI applications
Installation
Add this to your Cargo.toml:
[]
= "0.8"
= "0.30"
= "0.29"
= { = "1", = ["full"] }
See the Optional Features section for information about enabling ws (WebSocket) and http (HTTP Query/Mutation) features.
Getting Started
Minimal Example
Every tears application implements the Application trait with four required methods:
use *;
use Frame;
;
To run your application, create an Runtime and call run():
async
Complete Example
Here's a simple counter application that increments every second:
use Result;
use ;
use ;
use *;
use ;
async
Architecture
Tears follows The Elm Architecture (TEA) pattern:
ββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β βββββββββββ ββββββββββ ββββββββ β
β β Model βββββββΆβ View βββββββΆβ UI β β
β βββββββββββ ββββββββββ ββββββββ β
β β² β
β β β
β ββββββ΄ββββββ ββββββββββββββββ β
β β Update βββββββ Messages β β
β ββββββββββββ ββββββββββββββββ β
β β² β² β
β β β β
β ββββββ΄ββββββ ββββββββ΄βββββββ β
β β Commands β βSubscriptionsβ β
β ββββββββββββ βββββββββββββββ β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββ
Core Concepts
- Model: Your application state
- Message: Events that trigger state changes
- Update: Pure function that processes messages and returns new state + commands
- View: Pure function that renders UI based on current state
- Subscriptions: External event sources (keyboard, timers, network, etc.)
- Commands: Asynchronous side effects that produce messages
Built-in Subscriptions
- Terminal Events (
terminal::TerminalEvents): Keyboard, mouse, and resize events - Timer (
time::Timer): Periodic tick events - Signal (
signal::Signal): OS signal handling (Unix/Windows) - WebSocket (
websocket::WebSocket, requiresws): Real-time bidirectional communication - Query (
http::Query, requireshttp): HTTP data fetching with caching - Mutation (
http::Mutation, requireshttp): HTTP data modifications - MockSource (
mock::MockSource): Controllable mock for testing
Create custom subscriptions by implementing the SubscriptionSource trait.
Examples
Check out the examples/ directory for more examples:
counter.rs- A simple counter with timer and keyboard inputviews.rs- Multiple view states with navigation and conditional subscriptionssignals.rs- OS signal handling with graceful shutdown (SIGINT, SIGTERM, etc.)websocket.rs- WebSocket echo chat demonstrating real-time communication (requireswsfeature)http_todo.rs- HTTP Todo list with Query subscription, Mutation, and cache management (requireshttpfeature)
Run an example:
Optional Features
Tears supports optional features that can be enabled in your Cargo.toml:
WebSocket Support
[]
= { = "0.8", = ["ws", "rustls"] }
ws: Enables WebSocket subscription support- TLS backends (choose one for
wss://support):native-tls- Platform's native TLSrustls- Pure Rust TLS with native certificatesrustls-tls-webpki-roots- Pure Rust TLS with webpki certificates
HTTP Support
[]
= { = "0.8", = ["http"] }
http: Enables HTTP Query and Mutation supportQuerysubscription for automatic data fetching with cachingMutationfor data modifications (POST, PUT, PATCH, DELETE)QueryClientfor cache management and invalidation
Inspiration & Design Philosophy
Tears is inspired by battle-tested architectures:
- Elm: The original Elm Architecture
- iced: Rust GUI framework (v0.12 design)
- Bubble Tea: Go TUI framework with TEA
The framework is designed with these principles:
- Simplicity First: Minimal and easy-to-understand API
- Thin Framework: Minimal abstraction over ratatui - you have full control
- Type Safety: Leverage Rust's type system for correctness
Minimum Supported Rust Version (MSRV)
Tears requires Rust 1.86.0 or later (uses edition 2024).
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
Built with β€οΈ using ratatui