pub struct DebugLayer<A, C: BindingContext> { /* private fields */ }Expand description
High-level debug layer with sensible defaults
Wraps DebugFreeze and provides automatic rendering with:
- 1-line status bar at bottom when debug mode is active
- Frame capture/restore with dimming
- Modal overlays for state inspection
§Type Parameters
A: The application’s action type (for queuing actions while frozen)C: The keybinding context type
§Example
use tui_dispatch::debug::{DebugLayer, DebugConfig};
// In your app:
struct App {
debug: DebugLayer<MyAction, MyContext>,
// ...
}
// In render loop:
app.debug.render(frame, |f, area| {
// Render your normal UI here
app.render_main(f, area);
});Implementations§
Source§impl<A, C: BindingContext> DebugLayer<A, C>
impl<A, C: BindingContext> DebugLayer<A, C>
Sourcepub fn new(config: DebugConfig<C>) -> Self
pub fn new(config: DebugConfig<C>) -> Self
Create a new debug layer with the given configuration
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if debug mode is enabled
Sourcepub fn freeze(&self) -> &DebugFreeze<A>
pub fn freeze(&self) -> &DebugFreeze<A>
Get a reference to the underlying freeze state
Sourcepub fn freeze_mut(&mut self) -> &mut DebugFreeze<A>
pub fn freeze_mut(&mut self) -> &mut DebugFreeze<A>
Get a mutable reference to the underlying freeze state
Sourcepub fn config(&self) -> &DebugConfig<C>
pub fn config(&self) -> &DebugConfig<C>
Get the configuration
Sourcepub fn config_mut(&mut self) -> &mut DebugConfig<C>
pub fn config_mut(&mut self) -> &mut DebugConfig<C>
Get mutable configuration
Sourcepub fn render<F>(&mut self, frame: &mut Frame<'_>, render_fn: F)
pub fn render<F>(&mut self, frame: &mut Frame<'_>, render_fn: F)
Render with automatic debug handling (primary API)
When debug mode is disabled, simply calls render_fn with the full frame area.
When debug mode is enabled:
- Reserves 1 line at bottom for the debug banner
- Captures the frame on first render or when requested
- Paints the frozen snapshot with dimming
- Renders debug overlay (banner + modal if open)
§Example
terminal.draw(|frame| {
app.debug.render(frame, |f, area| {
render_main_ui(f, area, &app.state);
});
})?;Sourcepub fn split_area(&self, area: Rect) -> (Rect, Rect)
pub fn split_area(&self, area: Rect) -> (Rect, Rect)
Split area for manual layout control (escape hatch)
Returns (app_area, debug_banner_area). When debug mode is disabled, returns the full area and an empty rect.
§Example
let (app_area, banner_area) = debug.split_area(frame.area());
// Custom layout
let chunks = Layout::vertical([...]).split(app_area);
app.render_main(frame, chunks[0]);
app.render_status(frame, chunks[1]);
// Let debug layer render its UI
if debug.is_enabled() {
debug.render_overlay(frame, app_area);
debug.render_banner(frame, banner_area);
}Sourcepub fn render_overlay(&self, frame: &mut Frame<'_>, app_area: Rect)
pub fn render_overlay(&self, frame: &mut Frame<'_>, app_area: Rect)
Render just the debug overlay (modal + dimming)
Use this with split_area for manual layout control.
Render just the debug banner
Use this with split_area for manual layout control.
Render the debug banner with custom status items
Use this if you need to add dynamic status items to the banner. The status_items slice must outlive this call.
Sourcepub fn handle_action(
&mut self,
action: DebugAction,
) -> Option<DebugSideEffect<A>>
pub fn handle_action( &mut self, action: DebugAction, ) -> Option<DebugSideEffect<A>>
Handle a debug action
Returns a side effect if the app needs to take action (clipboard, mouse capture, etc).
Sourcepub fn handle_mouse(&mut self, mouse: MouseEvent) -> Option<DebugSideEffect<A>>
pub fn handle_mouse(&mut self, mouse: MouseEvent) -> Option<DebugSideEffect<A>>
Handle a mouse event in debug mode
Returns true if the event was consumed by debug handling.
Sourcepub fn show_state_overlay<S: DebugState>(&mut self, state: &S)
pub fn show_state_overlay<S: DebugState>(&mut self, state: &S)
Show state overlay using a DebugState implementor
Sourcepub fn show_state_overlay_with_title<S: DebugState>(
&mut self,
state: &S,
title: &str,
)
pub fn show_state_overlay_with_title<S: DebugState>( &mut self, state: &S, title: &str, )
Show state overlay with custom title
Sourcepub fn queue_action(&mut self, action: A)
pub fn queue_action(&mut self, action: A)
Queue an action to be processed when debug mode is disabled
Trait Implementations§
Auto Trait Implementations§
impl<A, C> Freeze for DebugLayer<A, C>where
C: Freeze,
impl<A, C> !RefUnwindSafe for DebugLayer<A, C>
impl<A, C> Send for DebugLayer<A, C>
impl<A, C> Sync for DebugLayer<A, C>
impl<A, C> Unpin for DebugLayer<A, C>
impl<A, C> !UnwindSafe for DebugLayer<A, C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more