mirror of
https://codeberg.org/JasterV/teatui.git
synced 2026-04-26 18:10:03 +00:00
2.7 KiB
2.7 KiB
TeaTui: Agent Context & Project Overview
Project Summary
TeaTui (Tea = The Elm Architecture) is an experimental Rust framework for building Terminal User Interfaces (TUIs) on top of Ratatui. It reproduces the Elm Architecture (Model-Update-View) to provide a pure functional development experience in Rust.
Tech Stack & Environment
- Language: Rust (Edition 2024).
- Workspace Structure: The project is organized as a workspace containing the core
teatuilibrary and anexamplesdirectory. - Core Dependencies:
ratatui: Used for terminal rendering.crossterm: Handles terminal backend and event polling.thiserror: Utilized for structured, descriptive error handling across the runtime.
Design Philosophy
- Functional Purity: The goal is to build TUI applications in a pure-functional style, completely removing the usage of
&mutand procedural state management. - Minimal Mutability: Mutability is discouraged in user-provided code; state transitions occur by returning new instances of the Model.
- Message Passing as Side Effects: Communication between internal processes is strictly handled via
std::sync::mpscchannels. Message passing is considered the "highest form of side effect" in the design.
Core Architecture
The framework operates through four concurrent actors (threads) that manage the application lifecycle:
- Model: A single type representing the entire application state.
- View Actor: Renders the Model into the terminal. It takes a pure function
&Model -> Widgetand redraws only when the Model changes. - Update Actor: Manages state transitions. It takes the current Model and an incoming Message, returning an
Updateenum (eitherUpdate::ExitorUpdate::Next(NewModel, Option<Effect>)). - Effects Actor: Processes side effects (e.g., IO) returned by the Update actor. It can optionally return a Message to trigger further state updates.
- Event Actor: Translates raw terminal events (via
crossterm) into application-specific Messages.
Key Types & Signatures
Update<M, E>: Enum signaling whether to exit or continue with a new state and optional effect.update(model: M, msg: Msg) -> Update<M, E>: The core logic for state changes.view(model: &M) -> Widget: The rendering logic.effects(model: &M, effect: E) -> Option<Msg>: The side-effect handler.
Development Guide
When extending the framework or building apps with it, ensure that update and view functions remain pure. Any operation involving the "outside world" (files, network, etc.) must be modeled as an Effect and handled within the effects actor.