Runtime
Classes in the Phui\Runtime namespace. Each is supplied to a component as a protected property and acts on that component.
Focus
final readonly class Phui\Runtime\Focus
Reached as $this->focus.
take(): voidMoves focus to this component immediately.
request(): voidAsks the runtime to focus this component once it has mounted.
held(): boolReturns whether this component currently holds focus.
next(): void
previous(): voidMove focus to the next or previous focusable component.
Timers
final readonly class Phui\Runtime\Timers
Reached as $this->timers. Timers are cancelled automatically when the component unmounts.
setInterval(Closure $callback, int $intervalMs): intRuns $callback every $intervalMs milliseconds and returns the timer id.
setTimeout(Closure $callback, int $delayMs): intRuns $callback once after $delayMs milliseconds and returns the timer id.
clear(int $id): voidCancels the timer with the given id.
System
final readonly class Phui\Runtime\System
Reached as $this->system.
screenSize(): SizeReturns the terminal's current Size.
clipboardWrite(string $text): voidWrites $text to the system clipboard.
clipboardRead(): ?stringReturns the clipboard contents, or null when unavailable.
printAbove(string $line): voidPrints a line into the scrollback above the rendered region.
complete(mixed $value = null): neverEnds the run and makes $value the return value of run(). Throws CompleteException, which the runtime catches.
Themes
final readonly class Phui\Runtime\Themes
Reached as $this->themes.
current(): ThemeReturns the active Theme.
palette(string $as = Palette::class): PaletteReturns the active theme's Palette. Pass a Palette subclass as $as to receive it typed as that class — the return type narrows to $as — for reading roles added by an extended palette. Throws UnexpectedPaletteException if the active palette is not an instance of $as.
swap(Theme $theme): voidReplaces the active theme and rebuilds the tree.
Async
final readonly class Phui\Runtime\Async
Reached as $this->async.
track(Closure $callback): ClosureWraps $callback so that work resuming inside it is attributed to this component, and is discarded if the component has unmounted by then.
Keymaps
final readonly class Phui\Runtime\Keymaps
Reached as $this->keymaps.
active(): KeymapReturns the Keymap a keypress would currently resolve against: the active layer's focused component, its ancestors, then that layer's globals, with shadowed chords removed. Reading it during build() subscribes the component, so it rebuilds whenever the active keymap changes.