$ show veeso/tui-realm
tui-realm is a Rust library/framework for building terminal user interfaces (TUIs) using a component-based, event-driven architecture. It is not a standalone application but a reusable framework that wraps ratatui (formerly tui-rs) and provides an Application loop, Component/AppComponent traits, a Model/Update/View pattern, and a subscription system for routing events between components. The monorepo is organized as a Cargo workspace containing the core `tuirealm` crate, a `tuirealm_derive` procedural macro crate, a standard library of reusable components (`tui-realm-stdlib`: Input, Label, List, Table, etc.), and optional integration crates `tui-realm-textarea` and `tui-realm-treeview`. The framework is designed to reduce boilerplate by centralizing focus management, event routing, and state handling in the Application/View layer, while allowing developers to define custom components and event sources via Ports and Subscriptions.
The LLM identified 4 files worth highlighting for reuse:
The View module implements a focus stack with blur/active transitions, managing which component receives events at any time. It supports subscriptions that route events to non-focused components based on event clauses and state/attribute conditions. This is an isolated, self-contained pattern for focus management in event-driven UIs that could be extracted into any TUI or GUI framework.
The Application core loop with `tick(PollStrategy)` polls events from multiple backends (crossterm, termion, termwiz), forwards them to active/subscribed components, collects returned messages, and drives the Model::update -> Model::view cycle. The PollStrategy abstraction (Blocking, NonBlocking, Once, WaitFor) and the event listener worker with test barrier demonstrate a non-trivial, reusable event-loop design.
A collection of production-ready TUI components (Input, Label, List, Table, Paragraph, etc.) built on the Component trait. Each component encapsulates its own state, event handling, and rendering logic, making them directly reusable in any tui-realm application. The Table component with column width negotiation and the Input component with validation state demonstrate non-trivial widget engineering.
An adapter crate that bridges the `tui-textarea` crate into the tui-realm component model. It demonstrates a clean adapter pattern for wrapping an external widget library into a framework's component lifecycle, handling focus, key events, and rendering delegation. This is a good reference for integrating third-party TUI widgets into a component-based architecture.