class TUI::Runtime

Overview

Owns the generic TUI application lifecycle: terminal setup/teardown, the render/read-key/dispatch loop, SIGWINCH-driven resize, and the push/pop/render mechanics of a stack of full-screen Widgets. Consumers build their own widgets, wrap them in a NavStack(Widget), and hand it here along with a callback for everything that isn't Ctrl-C/Ctrl-D — this class owns no opinion about what any printable key (including 'q') should do.

Once a Runtime owns a NavStack, push/pop through Runtime#push/#pop (not NavStack#push/#pop or #handle_esc directly) so revealed/pushed widgets get resized to the current screen before their next render.

Defined in:

tui/runtime.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(screen : Screen, nav : NavStack(Widget), on_key : KeyEvent -> Nil, io : IO = STDIN) #

[View source]

Instance Method Detail

def handle_esc(consumed : Bool, &on_pop : -> ) : Nil #

The "delegate to child, pop only if unconsumed" idiom for Esc, routed through Runtime#pop (not NavStack#pop directly) so the revealed widget gets resized in case it went stale while backgrounded — mirrors NavStack#handle_esc's contract exactly, but callers that own a Runtime should use this one instead.


[View source]
def pop : Nil #

Pop back to the previous widget, resyncing its size in case it went stale while backgrounded.


[View source]
def push(widget : Widget) : Nil #

Push a widget, resizing it to the current screen first.


[View source]
def read_dispatch_loop : Nil #

The render/read-key/dispatch loop itself, without the surrounding terminal setup/teardown/signal trap — split out so it's exercisable against an injected IO (see @io) without touching real terminal state, e.g. in specs.


[View source]
def render_now : Nil #

Forces a synchronous full render+flush outside the normal read/dispatch loop. Intended for a long blocking operation (e.g. a pkg apply) that emits progress via callbacks and needs the screen repainted between the loop's normal render points.


[View source]
def replace_base(widget : Widget) : Nil #

Swaps the widget at the bottom of the stack, resizing it to the current screen first — for a root screen whose structure changes based on runtime state.


[View source]
def run : Nil #

[View source]