$ show gyscos/cursive
Cursive is a mature, backend-agnostic TUI (Text User Interface) framework for Rust. It provides a rich set of composable widgets (dialogs, text views, edit views, select lists, progress bars, etc.), a flexible event system, full styling and theming support, and multiple backend implementations (crossterm, termion, ncurses, pancurses, BearLibTerminal). The architecture is split into `cursive-core` (backend-independent core) and `cursive` (user-facing crate with backends), plus `cursive-macros` for procedural macro support and `cursive-syntect` for syntax highlighting. The framework is designed for both simple scripts and complex real-time applications, with a focus on ease of use and composability. The core `View` trait defines layout, drawing, and event handling, while wrappers like `ViewWrapper`, `OnEventView`, `NamedView`, and `ResizedView` allow behavior composition without inheritance. The event system uses `EventTrigger` for declarative key binding and `Callback` for delayed actions. The style model supports gradients, palettes, effects, and TOML-based themes. The `Printer` abstraction handles coordinate transformations and styled drawing, and the `PrintBuffer` implements efficient double-buffering with diff-based output to minimize terminal writes. The builder module (experimental) enables declarative UI construction from YAML/JSON config files via a `Resolvable` trait and blueprint macros. The codebase is well-structured, extensively documented, and includes numerous examples and integration tests. It demonstrates strong software engineering practices: clean trait-based abstractions, thread-safe state via channels and `Arc`, efficient rendering, and modularity. While there is some code duplication across backends and a few deprecated items (e.g., `ScrollBase`), the overall quality is high and the library is actively maintained with a large user community.
The LLM identified 5 files worth highlighting for reuse:
Provides a `Printer` struct that abstracts terminal output with offset, cropping, style stacking, effects, and box-drawing. It is self-contained (depends only on core geometry and style types) and can be extracted as a reusable rendering layer for any terminal application. Demonstrates non-obvious skill in layering styles and efficiently managing coordinate spaces.
Implements `PrintBuffer` and `Cell` for efficient double-buffered terminal output. The `flush` method computes a diff between current and previous frames, sending only changed cells to the backend. This pattern is highly reusable for any TUI or terminal-based application seeking to minimize write operations. The code handles wide graphemes and color pairs with care.
Defines the core event types (`Event`, `EventResult`, `Callback`, `EventTrigger`). `EventTrigger` provides a composable, declarative API for matching key combinations and mouse events, with methods like `or()` for combining triggers. `Callback` supports `from_fn`, `from_fn_mut`, and `from_fn_once` for flexible deferred execution. This module is self-contained and could be reused in any event-driven system.
Provides `SpannedString` and `StyledString` for representing text with multiple style spans. It offers an efficient, immutable representation with a builder pattern and methods for splitting, merging, and applying styles. This is a reusable pattern for any application needing rich text rendering, and it is isolated from the rest of the TUI framework.
Implements `Core` for scrollable views, handling scroll position, thumb dragging, and multiple scroll strategies (scroll-to-top, keep-bottom). It is generic over the content size and viewport, and can be extracted as a standalone scroll controller for any scrollable widget. The code demonstrates careful management of scroll boundaries and smooth thumb movement.