Crate tui_dispatch

Crate tui_dispatch 

Source
Expand description

tui-dispatch: Centralized state management for Rust TUI apps

Like Redux/Elm, but for terminals. Components are pure functions of state, and all state mutations happen through dispatched actions.

§Example

use tui_dispatch::prelude::*;

#[derive(Action, Clone, Debug)]
enum MyAction {
    NextItem,
    PrevItem,
}

#[derive(ComponentId, Clone, Copy, PartialEq, Eq, Hash, Debug)]
enum MyComponentId {
    List,
    Detail,
}

Modules§

action
Action trait for type-safe state mutations
bus
Event bus for dispatching events to subscribed components
component
Component trait for pure UI elements
debug
Debug and inspection utilities for TUI applications
event
Event types for the pub/sub system
keybindings
Keybindings system with context-aware key parsing and lookup
prelude
Prelude for convenient imports
store
Centralized state store with reducer pattern
testing
Test utilities for tui-dispatch applications

Macros§

assert_category_emitted
Assert that an action of a specific category was emitted.
assert_category_not_emitted
Assert that NO action of a specific category was emitted.
assert_emitted
Assert that a specific action was emitted.
assert_not_emitted
Assert that a specific action was NOT emitted.
assert_state
Assert that a field of the harness state has an expected value.
assert_state_matches
Assert that a field of the harness state matches a pattern.
count_category
Count how many actions belong to a specific category.
count_emitted
Count how many actions match a pattern.
find_emitted
Find and return the first action matching a pattern.

Structs§

ComposedMiddleware
Compose multiple middleware into a single middleware
Event
An event with its context
EventBus
Event bus that manages subscriptions and dispatches events
EventContext
Context passed with every event
Frame
A consistent view into the terminal state for rendering a single frame.
Keybindings
Keybindings configuration with context support
Line
A line of text, consisting of one or more Spans.
LoggingMiddleware
Middleware that logs actions (for debugging)
Modifier
Modifier changes the way a piece of text is displayed.
NoopMiddleware
A no-op middleware that does nothing
NumericComponentId
A simple numeric component ID for basic use cases
Rect
A Rectangular area.
RenderHarness
Test harness for capturing rendered output.
Span
Represents a part of a line that is contiguous and where all characters share the same style.
Store
Centralized state store with Redux-like reducer pattern
StoreWithMiddleware
Store with middleware support
Style
Style lets you control the main characteristics of the displayed elements.
TestHarness
Generic test harness for tui-dispatch applications.
Text
A string split over one or more lines.

Enums§

Color
ANSI Color
EventKind
The actual event payload
EventType
Event types that components can subscribe to
RawEvent
Raw event from crossterm before processing

Traits§

Action
Marker trait for actions that can be dispatched to the store
ActionAssertions
Fluent assertion trait for action vectors.
ActionAssertionsEq
Equality-based assertions for action vectors.
ActionCategory
Extension trait for actions with category support
BindingContext
Trait for user-defined keybinding contexts
Component
A pure UI component that renders based on props and emits actions
ComponentId
Trait for user-defined component identifiers
Middleware
Middleware trait for intercepting actions

Functions§

alt_key
Create a KeyEvent for a character with Alt modifier.
buffer_rect_to_string_plain
Convert a specific rect of a buffer to a plain string.
buffer_to_string
Convert a ratatui Buffer to a string with ANSI escape codes.
buffer_to_string_plain
Convert a ratatui Buffer to a plain string (no ANSI codes).
char_key
Create a KeyEvent for a character with no modifiers.
ctrl_key
Create a KeyEvent for a character with Ctrl modifier.
format_key_for_display
Format a key string for display (e.g., “ctrl+p” -> “^P”, “q” -> “q”, “tab” -> “Tab”)
into_event
Create an Event<C> from a KeyEvent.
key
Create a KeyEvent from a key string.
key_event
Create an Event<C> containing a key event from a key string.
key_events
Create multiple Event<C> from a space-separated key string.
keys
Parse multiple key strings into KeyEvents.
parse_key_string
Parse a key string like “q”, “esc”, “ctrl+p”, “shift+tab” into a KeyEvent
process_raw_event
Process a raw event into an EventKind
spawn_event_poller
Spawn the event polling task with cancellation support

Type Aliases§

Reducer
A reducer function that handles actions and mutates state

Derive Macros§

Action
Derive macro for the Action trait
BindingContext
Derive macro for the BindingContext trait
ComponentId
Derive macro for the ComponentId trait