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
- 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§
- Composed
Middleware - Compose multiple middleware into a single middleware
- Dispatch
Result - Result of dispatching an action to an effect-aware store.
- Dynamic
Features - A dynamic feature flag store for cases where compile-time flags aren’t needed
- Effect
Store - A store that supports effect-emitting reducers.
- Effect
Store With Middleware - An effect store with middleware support.
- Event
- An event with its context
- Event
Bus - Event bus that manages subscriptions and dispatches events
- Event
Context - 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. - Logging
Middleware - Middleware that logs actions (for debugging)
- Modifier
- Modifier changes the way a piece of text is displayed.
- Noop
Middleware - A no-op middleware that does nothing
- Numeric
Component Id - A simple numeric component ID for basic use cases
- Rect
- A Rectangular area.
- Render
Harness - 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
- Store
With Middleware - Store with middleware support
- Style
- Style lets you control the main characteristics of the displayed elements.
- Test
Harness - Generic test harness for tui-dispatch applications.
- Text
- A string split over one or more lines.
Enums§
- Color
- ANSI Color
- Event
Kind - The actual event payload
- Event
Type - 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
- Action
Assertions - Fluent assertion trait for action vectors.
- Action
Assertions Eq - Equality-based assertions for action vectors.
- Action
Category - Extension trait for actions with category support
- Action
Params - Trait for getting action parameters without the variant name.
- Action
Summary Deprecated - Trait for actions that provide a summary representation for logging
- Binding
Context - Trait for user-defined keybinding contexts
- Component
- A pure UI component that renders based on props and emits actions
- Component
Id - Trait for user-defined component identifiers
- Feature
Flags - Trait for feature flag containers
- Middleware
- Middleware trait for intercepting actions
Functions§
- alt_key
- Create a
KeyEventfor 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
KeyEventfor a character with no modifiers. - ctrl_
key - Create a
KeyEventfor 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 aKeyEvent. - key
- Create a
KeyEventfrom 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§
- Effect
Reducer - 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
- Binding
Context - Derive macro for the BindingContext trait
- Component
Id - Derive macro for the ComponentId trait
- Debug
State - Derive macro for the DebugState trait
- Feature
Flags - Derive macro for the FeatureFlags trait