Skip to content

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.

php
take(): void

Moves focus to this component immediately.

php
request(): void

Asks the runtime to focus this component once it has mounted.

php
held(): bool

Returns whether this component currently holds focus.

php
next(): void
previous(): void

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

php
setInterval(Closure $callback, int $intervalMs): int

Runs $callback every $intervalMs milliseconds and returns the timer id.

php
setTimeout(Closure $callback, int $delayMs): int

Runs $callback once after $delayMs milliseconds and returns the timer id.

php
clear(int $id): void

Cancels the timer with the given id.

System

final readonly class Phui\Runtime\System

Reached as $this->system.

php
screenSize(): Size

Returns the terminal's current Size.

php
clipboardWrite(string $text): void

Writes $text to the system clipboard.

php
clipboardRead(): ?string

Returns the clipboard contents, or null when unavailable.

php
printAbove(string $line): void

Prints a line into the scrollback above the rendered region.

php
complete(mixed $value = null): never

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

php
current(): Theme

Returns the active Theme.

php
palette(string $as = Palette::class): Palette

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

php
swap(Theme $theme): void

Replaces the active theme and rebuilds the tree.

Async

final readonly class Phui\Runtime\Async

Reached as $this->async.

php
track(Closure $callback): Closure

Wraps $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.

php
active(): Keymap

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

Released under the MIT License.