DebugLayer

Struct DebugLayer 

Source
pub struct DebugLayer<A> { /* private fields */ }
Expand description

High-level debug layer with minimal configuration.

Provides automatic freeze/unfreeze with pause/resume of tasks and subscriptions.

§Example

use tui_dispatch::debug::DebugLayer;

// Minimal setup with sensible defaults (F12 toggle key)
let mut debug = DebugLayer::simple()
    .with_task_manager(&tasks)
    .with_subscriptions(&subs)
    .active(args.debug);

// In event loop
if debug.intercepts(&event) {
    continue;
}

// In render
debug.render(frame, |f, area| {
    app.render(f, area);
});

// Log actions for the action log feature
debug.log_action(&action);

Implementations§

Source§

impl<A: Action> DebugLayer<A>

Source

pub fn new(toggle_key: KeyCode) -> Self

Create a new debug layer with the given toggle key.

§Example
use crossterm::event::KeyCode;

let debug = DebugLayer::new(KeyCode::F(12));
Source

pub fn simple() -> Self

Create a debug layer with sensible defaults (F12 toggle key).

Source

pub fn simple_with_toggle_key(toggle_key: KeyCode) -> Self

Create a debug layer with a custom toggle key.

Source

pub fn active(self, active: bool) -> Self

Set whether the debug layer is active.

When inactive (false), all methods become no-ops with zero overhead.

Source

pub fn with_banner_position(self, position: BannerPosition) -> Self

Set the initial banner position.

Source

pub fn with_action_log_capacity(self, capacity: usize) -> Self

Set the action log capacity.

Source

pub fn with_style(self, style: DebugStyle) -> Self

Set custom style.

Source

pub fn is_active(&self) -> bool

Check if the debug layer is active.

Source

pub fn is_enabled(&self) -> bool

Check if debug mode is enabled (and layer is active).

Source

pub fn toggle_enabled(&mut self) -> Option<DebugSideEffect<A>>

Toggle debug mode on/off and return any side effects.

Returns None when the layer is inactive or no side effects are needed.

Source

pub fn set_enabled(&mut self, enabled: bool) -> Option<DebugSideEffect<A>>

Set debug mode on/off and return any side effects.

Returns None when the layer is inactive or already in the requested state.

Source

pub fn set_banner_position(&mut self, position: BannerPosition)

Update the banner position (top/bottom) and request a new capture.

Source

pub fn is_state_overlay_visible(&self) -> bool

Check if the state overlay is currently visible.

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 log_action<T: ActionParams>(&mut self, action: &T)

Log an action to the action log.

Call this when dispatching actions to record them for the debug overlay.

Source

pub fn action_log(&self) -> &ActionLog

Get the action log.

Source

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

Render with automatic debug handling.

When debug mode is disabled, simply calls render_fn with the full frame area. When enabled, captures/paints the frozen snapshot and renders debug overlay.

Source

pub fn render_with_state<F>(&mut self, frame: &mut Frame<'_>, render_fn: F)
where F: FnOnce(&mut Frame<'_>, Rect, bool) -> Option<DebugTableOverlay>,

Render with optional state capture for the state overlay.

render_fn receives the frame, app area, and a wants_state hint that is true when debug mode is active and state data may be requested. Return Some(DebugTableOverlay) to update the cached state overlay.

Source

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

Render with a DebugState reference and automatic state table generation.

This is a convenience wrapper around render_with_state.

Source

pub fn split_area(&self, area: Rect) -> (Rect, Rect)

Split area for manual layout control.

Source

pub fn intercepts(&mut self, event: &EventKind) -> bool

Check if debug layer intercepts an event.

Call this before your normal event handling. If it returns true, the event was consumed by the debug layer.

§Example
if debug.intercepts(&event) {
    continue;
}
// Normal event handling
Source

pub fn handle_event(&mut self, event: &EventKind) -> DebugOutcome<A>

Handle a debug event with a single call and return a summary outcome.

Source

pub fn handle_event_with_state<S: DebugState>( &mut self, event: &EventKind, state: &S, ) -> DebugOutcome<A>

Handle a debug event with access to state (for the state overlay).

Source

pub fn intercepts_with_effects( &mut self, event: &EventKind, ) -> Option<Vec<DebugSideEffect<A>>>

Check if debug layer intercepts an event, returning any side effects.

Returns None if the event was not consumed, Some(effects) if it was.

Source

pub fn intercepts_with_effects_and_state<S: DebugState>( &mut self, event: &EventKind, state: &S, ) -> Option<Vec<DebugSideEffect<A>>>

Check if debug layer intercepts an event with access to app state.

Use this to populate the state overlay when S is pressed.

Source

pub fn intercepts_with_state<S: DebugState>( &mut self, event: &EventKind, state: &S, ) -> bool

Check if debug layer intercepts an event with access to app state.

Source

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

Show state overlay using a DebugState implementor.

Source

pub fn show_action_log(&mut self)

Show action log overlay.

Source

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

Queue an action to be processed when debug mode is disabled.

Source

pub fn take_queued_actions(&mut self) -> Vec<A>

Take any queued actions (from task manager resume).

Call this after intercepts() returns effects to get queued actions that should be dispatched.

Trait Implementations§

Source§

impl<A> Debug for DebugLayer<A>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A> Freeze for DebugLayer<A>

§

impl<A> RefUnwindSafe for DebugLayer<A>
where A: RefUnwindSafe,

§

impl<A> Send for DebugLayer<A>
where A: Send,

§

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

§

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

§

impl<A> UnwindSafe for DebugLayer<A>
where A: UnwindSafe,

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