DebugLayer

Struct DebugLayer 

Source
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>

Source

pub fn new(config: DebugConfig<C>) -> Self

Create a new debug layer with the given configuration

Source

pub fn is_enabled(&self) -> bool

Check if debug mode is enabled

Source

pub fn freeze(&self) -> &DebugFreeze<A>

Get a reference to the underlying freeze state

Source

pub fn freeze_mut(&mut self) -> &mut DebugFreeze<A>

Get a mutable reference to the underlying freeze state

Source

pub fn config(&self) -> &DebugConfig<C>

Get the configuration

Source

pub fn config_mut(&mut self) -> &mut DebugConfig<C>

Get mutable configuration

Source

pub fn render<F>(&mut self, frame: &mut Frame<'_>, render_fn: F)
where F: FnOnce(&mut Frame<'_>, Rect),

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);
    });
})?;
Source

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);
}
Source

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.

Source

pub fn render_banner(&self, frame: &mut Frame<'_>, banner_area: Rect)

Render just the debug banner

Use this with split_area for manual layout control.

Source

pub fn render_banner_with_status( &self, frame: &mut Frame<'_>, banner_area: Rect, status_items: &[(&str, &str)], )

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.

Source

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).

Source

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.

Source

pub fn show_state_overlay<S: DebugState>(&mut self, state: &S)

Show state overlay using a DebugState implementor

Source

pub fn show_state_overlay_with_title<S: DebugState>( &mut self, state: &S, title: &str, )

Show state overlay with custom title

Source

pub fn queue_action(&mut self, action: A)

Queue an action to be processed when debug mode is disabled

Trait Implementations§

Source§

impl<A, C: BindingContext> Debug for DebugLayer<A, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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>
where C: Send, A: Send,

§

impl<A, C> Sync for DebugLayer<A, C>
where C: Sync, A: Sync,

§

impl<A, C> Unpin for DebugLayer<A, C>
where C: Unpin, A: Unpin,

§

impl<A, C> !UnwindSafe for DebugLayer<A, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more