Expand description
Debug and inspection utilities for TUI applications
This module provides tools for debugging TUI applications:
- DebugLayer: High-level wrapper with automatic rendering (recommended)
- Action Logging: Pattern-based filtering for action logs
- Frame Freeze: Capture and inspect UI state
- Cell Inspection: Examine individual buffer cells
- Debug Widgets: Render debug overlays and tables
§Quick Start (Recommended)
ⓘ
use tui_dispatch_debug::debug::DebugLayer;
// Minimal setup with sensible defaults (F12 toggle key)
let debug = DebugLayer::<MyAction>::simple().active(args.debug);
// In render loop:
debug.render_state(frame, &state, |f, area| {
render_main_ui(f, area, &state);
});
// Built-in keybindings (when debug mode is active):
// - Toggle key (e.g., F12): Toggle debug mode
// - S: Show/hide state overlay
// - B: Toggle debug banner position
// - J/K, arrows, PgUp/PgDn, g/G: Scroll overlays
// - Y: Copy frozen frame to clipboard
// - W: Save state snapshot as JSON
// - I: Toggle mouse capture for cell inspection§Customization
ⓘ
use crossterm::event::KeyCode;
use tui_dispatch_debug::debug::{BannerPosition, DebugLayer, DebugStyle};
let debug = DebugLayer::<MyAction>::new(KeyCode::F(11))
.with_banner_position(BannerPosition::Top)
.with_action_log_capacity(500)
.with_style(DebugStyle::default())
.active(args.debug);§Manual Control (Escape Hatch)
ⓘ
// Split area manually
let (app_area, banner_area) = debug.split_area(frame.area());
// Custom layout
render_my_ui(frame, app_area);
// Let debug layer render its parts
debug.render_overlay(frame, app_area);
debug.render_banner(frame, banner_area);§State Inspection
Implement DebugState for your state types:
ⓘ
use tui_dispatch::debug::{DebugState, DebugSection};
impl DebugState for AppState {
fn debug_sections(&self) -> Vec<DebugSection> {
vec![
DebugSection::new("Connection")
.entry("host", &self.host)
.entry("status", format!("{:?}", self.status)),
]
}
}
// Then show it:
debug.show_state_overlay(&app_state);§Action Logging
Use ActionLoggerMiddleware for pattern-based action filtering:
use tui_dispatch_debug::debug::ActionLoggerConfig;
// Log only Search* and Connect* actions
let config = ActionLoggerConfig::new(Some("Search*,Connect*"), None);
// Log everything except Tick and Render (default excludes)
let config = ActionLoggerConfig::default();§Low-Level API
For full control, use DebugFreeze directly:
ⓘ
use tui_dispatch::debug::{DebugFreeze, paint_snapshot, dim_buffer};
let debug: DebugFreeze<MyAction> = DebugFreeze::default();
// In render loop:
if debug.enabled {
if debug.pending_capture || debug.snapshot.is_none() {
render_app(f, state);
debug.capture(f.buffer());
} else {
paint_snapshot(f, debug.snapshot.as_ref().unwrap());
}
dim_buffer(f.buffer_mut(), 0.7);
render_debug_overlay(f, &debug);
}Modules§
- action_
logger - Action logging with pattern-based filtering and in-memory storage
- actions
- Debug actions and side effects
- cell
- Cell inspection utilities
- config
- Debug layer configuration
- format
- layer
- High-level debug layer for TUI applications
- state
- Debug state introspection trait
- table
- Debug table types and builder
- widgets
- Debug rendering utilities and widgets
Structs§
- Action
Log - In-memory ring buffer for storing recent actions
- Action
LogConfig - Configuration for the action log ring buffer
- Action
LogDisplay Entry - A display-ready action log entry
- Action
LogEntry - An entry in the action log
- Action
LogOverlay - Overlay for displaying the action log
- Action
LogStyle - Style configuration for action log rendering
- Action
LogWidget - A widget for rendering an action log overlay
- Action
Logger Config - Configuration for action logging with glob pattern filtering.
- Action
Logger Middleware - Middleware that logs actions with configurable pattern filtering.
- Banner
Item - An item in a debug banner (status bar)
- Cell
Preview - Visual representation of a buffer cell for debug preview
- Cell
Preview Widget - A widget that renders a cell preview
- Debug
Banner - A debug banner widget (status bar at bottom)
- Debug
Config - Configuration for the debug layer
- Debug
Entry - A debug entry (key-value pair)
- Debug
Freeze - Debug freeze state for capturing and inspecting UI frames
- Debug
Layer - High-level debug layer with minimal configuration.
- Debug
Outcome - Result of handling a debug event.
- Debug
Section - A debug section with a title and entries
- Debug
Style - Style configuration for debug UI
- Debug
Table Builder - Builder for constructing debug tables
- Debug
Table Overlay - A debug table overlay with title, rows, and optional cell preview
- Debug
Table Style - Style configuration for debug table rendering
- Debug
Table Widget - A debug table widget that renders a DebugTableOverlay
- Debug
Wrapper - Wrapper to use Debug impl as DebugState
- KeyStyles
- Styles for different debug key hints
- Scrollbar
Style - Style and symbol overrides for debug scrollbars
- Status
Item - Status item for the debug banner
Enums§
- Banner
Position - Location of the debug banner relative to the app area.
- Debug
Action - Debug actions provided by tui-dispatch
- Debug
Overlay - Type of debug overlay
- Debug
Side Effect - Side effects that the app needs to handle after debug actions
- Debug
Table Row - A row in a debug table - either a section header or a key-value entry
- Simple
Debug Context - Built-in context for default debug keybindings.
Traits§
- Debug
State - Trait for types that can provide debug state information
Functions§
- buffer_
to_ text - Convert a buffer to plain text (for clipboard export)
- debug_
string - debug_
string_ compact - debug_
string_ pretty - default_
debug_ keybindings - Create default debug keybindings with
F12/Escto toggle. - default_
debug_ keybindings_ with_ toggle - Create debug keybindings with custom toggle key(s).
- dim_
buffer - Dim a buffer by scaling colors towards black
- format_
color_ compact - Format a color as a compact string for display
- format_
modifier_ compact - Format modifiers as a compact string
- glob_
match - Simple glob pattern matching supporting
*and?. - inspect_
cell - Inspect a cell at the given position in a buffer
- paint_
snapshot - Paint a snapshot buffer onto the current frame
- point_
in_ rect - Check if a point is within a rectangle