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
effect
Effect-based state management
event
Event types for the pub/sub system
features
Runtime feature flags for TUI applications
keybindings
Keybindings system with context-aware key parsing and lookup
prelude
Prelude for convenient imports
runtime
Runtime helpers for tui-dispatch apps.
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.
reducer_compose
Compose a reducer by routing actions to focused handlers.

Structs§

ComposedMiddleware
Compose multiple middleware into a single middleware
DispatchResult
Result of dispatching an action to an effect-aware store.
DispatchRuntime
Runtime helper for simple stores (no effects).
DynamicFeatures
A dynamic feature flag store for cases where compile-time flags aren’t needed
EffectContext
Context passed to effect handlers.
EffectRuntime
Runtime helper for effect-based stores.
EffectStore
A store that supports effect-emitting reducers.
EffectStoreTestHarness
Test harness for effect-based stores.
EffectStoreWithMiddleware
An effect store with middleware support.
Event
An event with its context
EventBus
Event bus that manages subscriptions and dispatches events
EventContext
Context passed with every event
EventOutcome
Result of mapping an event into actions plus an optional render hint.
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
PollerConfig
Configuration for the event poller.
Rect
A Rectangular area.
RenderContext
Context passed to render closures.
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
StoreTestHarness
Test harness combining Store + action channel + render capabilities.
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
ActionParams
Trait for getting action parameters without the variant name.
ActionSummaryDeprecated
Trait for actions that provide a summary representation for logging
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
DispatchStore
Store interface used by DispatchRuntime.
EffectAssertions
Fluent assertions for effect vectors.
EffectAssertionsEq
Equality-based assertions for effect vectors.
EffectStoreLike
Effect store interface used by EffectRuntime.
FeatureFlags
Trait for feature flag containers
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§

EffectReducer
A reducer function that can emit effects.
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
DebugState
Derive macro for the DebugState trait
FeatureFlags
Derive macro for the FeatureFlags trait