PUBLIC MODULE · lib/gtui/gtui.js

GTUI

GTUI public façade for synchronous terminal applications.

GTUI owns view geometry, rendering, terminal controls, selection, editing, and key decoding. Applications own semantic policy and conversation state; TUI turn lifecycle remains in lib/tui-app/. Hosts provide terminal I/O and receive rendered scenes and effects. Interactive input, including key events, is applied immediately; background frames are not used to delay input. GTUI is not a web-app abstraction.

view = freeze({…}) constant

Immutable constructors for renderable view nodes.

text(props = {…}, content = "") method

Create immutable text content.

table(props = {…}, rows = []) method

Create an immutable table with frozen rows and cells.

feed(props = {…}) method

Create an immutable feed control.

input(props = {…}) method

Create an immutable text input control.

menu(props = {…}) method

Create an immutable menu control.

row(...) method

Create an immutable horizontal container.

column(...) method

Create an immutable vertical container.

grid(...) method

Create an immutable grid container.

panel(...) method

Create an immutable bordered panel.

scroll(...) method

Create an immutable scroll container.

overlay(...) method

Create an immutable overlay container.

effect = freeze({…}) constant

Immutable constructors for host, task, timer, theme, and lifecycle effects.

task(key, run) method

Run an abortable asynchronous task.

cancel(key) method

Cancel the task for a key.

after(ms, message) method

Deliver a message after a delay.

copy(text, id) method

Copy text through the host.

open(url) method

Ask the host to open a URL.

notify(text) method

Ask the host to show a notification.

theme(tokens) method

Replace theme tokens.

refresh() method

Request a render without changing the model.

quit(code = 0) method

End the application with a status code.

event = freeze({…}) constant

Immutable constructors for messages delivered to an application update function.

key(payload) method

Create a key event.

paste(payload) method

Create a paste event.

pointer(payload) method

Create a pointer event.

resize(payload) method

Create a resize event.

focus(payload) method

Create a focus event.

inputChange(payload) method

Create an input-change event.

inputSubmit(payload) method

Create an input-submit event.

menuSelect(payload) method

Create a menu-selection event.

menuCancel(payload = {…}) method

Create a menu-cancel event.

selectionCopy(payload) method

Create a selection-copy event.

linkOpen(payload) method

Create a link-open event.

taskDone(payload) method

Create a completed-task event.

taskFailed(payload) method

Create a failed-task event.

copyDone(payload) method

Create a completed-copy event.

memory({ width = 80, height = 24, scrollBar } = {…}) function

Create an in-memory host for application tests. It records rendered semantics and effects; it never emits terminal bytes.

Returns object — host implementing the GTUI host protocol

send(message) method

Send a host input message to the mounted application.

flush() method

Finish pending host output; memory hosts have nothing to flush.

snapshot() method

Return the current rendered scene in semantic, testable form.

get effects() getter

Recorded effects, copied so callers cannot mutate host state.

get restoreCount() getter

Number of completed host restoration cycles.

_start(listener, binding) method

Start the runtime-to-host message protocol.

_render(next) method

Render a view through the in-memory layout engine.

_setTheme(theme) method

Install the resolved theme for subsequent layouts.

_effect(value, send) method

Record an effect and acknowledge copy effects asynchronously.

_restore() method

Clear runtime callbacks and record host restoration.

terminal(options = {…}) function

Construct a terminal host that owns input decoding and terminal rendering.

[options] object
terminal streams, mode, dimensions, and policies

Returns object — opaque GTUI host

class GTUI class

Run a synchronous application against a GTUI host. The application supplies init, update, view, and optional bindings/dispose; update transitions may return effects. GTUI applies messages, renders views, and manages host/task/timer cleanup.

constructor({ host, theme = {…} } = {…}) constructor

Create a runtime for a host.

dispatch(message) method

Deliver one message immediately to the running application.

stop(reason = "stop", code = 0) method

Stop the application, canceling tasks and timers and restoring the host.

run(app) method

Start an application and return its eventual completion result.

host = freeze({…}) constant

Host constructors for tests and terminal execution.

memory(...) method

Create a memory host for deterministic application tests.

terminal(...) method

Create a terminal host for interactive execution.

scrollGlyph(value, fallback) function

Return a one-cell grapheme or the supplied fallback.