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.1"
= "0.29"
= "0.28"
= { = "1", = ["full"] }
Getting Started
Minimal Example
Every tears application implements the Application trait with four required methods:
use *;
use Frame;
;
To run your application, create a 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
Tears provides several built-in subscription sources:
- Terminal Events (
subscription::terminal::TerminalEvents): Keyboard, mouse, and window resize events - Timer (
subscription::time::Timer): Periodic tick events at configurable intervals - Signal (Unix:
subscription::signal::Signal, Windows:subscription::signal::CtrlC,subscription::signal::CtrlBreak): OS signal handling for graceful shutdown and interrupt handling
You can also 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.)
Run an example:
Design Philosophy
Tears is designed with these principles in mind:
- Simplicity First: Keep the API minimal and easy to understand
- Thin Framework: Minimal abstraction over ratatui - you have full control
- Proven Patterns: Based on battle-tested architectures (Elm, iced)
- Type Safety: Leverage Rust's type system for correctness
Inspiration
This framework is heavily inspired by:
- Elm: The original Elm Architecture
- iced: Rust GUI framework (v0.12 design)
- Bubble Tea: Go TUI framework with TEA
Minimum Supported Rust Version (MSRV)
Tears requires Rust 1.85.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