PUBLIC MODULE · lib/app/gtui/gtui.js
App.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/app/tui/. 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.
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.
Defined in lib/app/gtui/gtui.js
constructor({ host, theme = {…} } = {…}) constructor
Create a runtime for a host.
Returns GTUI — configured runtime
Throws — {TypeError} if host is missing
dispatch(message) method
Deliver one message immediately to the running application.
messageobject- application message
Returns void
run(app) method
Start an application and return its eventual completion result.
Returns Promise<{reason: string, code: number}> — completion promise; rejects on runtime failure
Throws — {Error} if already running; TypeError if required callbacks are absent
stop(reason = "stop", code = 0) method
Stop the application, canceling tasks and timers and restoring the host.
[reason="stop"]string- completion reason
[code=0]number- completion code
Returns void
effect = freeze({…}) constant
Immutable constructors for host, task, timer, theme, and lifecycle effects.
Defined in lib/app/gtui/gtui.js
after(ms, message) method
Describe delayed message delivery.
msnumber- delay in milliseconds
messageobject- message to dispatch
Returns object — frozen timer effect
cancel(key) method
Describe cancellation of a keyed task.
key*- task identity
Returns object — frozen cancellation effect
copy(text, id) method
Request host-mediated text copying.
textstring- text to copy
[id]*- optional correlation identifier
Returns object — frozen copy effect
notify(text) method
Request a host notification.
textstring- notification text
Returns object — frozen notification effect
open(url) method
Request host-mediated URL opening.
urlstring- URL to open
Returns object — frozen open effect
quit(code = 0) method
Request application shutdown.
[code=0]number- completion status code
Returns object — frozen quit effect
refresh() method
Request a render without changing the model.
Returns object — frozen refresh effect
task(key, run) method
Describe an abortable asynchronous task.
key*- task identity
runFunction- async task receiving signal and send
Returns object — frozen task effect
theme(tokens) method
Replace theme tokens at runtime.
tokensobject- theme token mapping
Returns object — frozen theme effect
event = freeze({…}) constant
Immutable constructors for messages delivered to an application update function.
Defined in lib/app/gtui/gtui.js
copyDone(payload) method
Create a completed-copy event.
payloadobject- event fields
Returns object — frozen copy-done event
focus(payload) method
Create a focus event.
payloadobject- event fields
Returns object — frozen focus event
inputChange(payload) method
Create an input-change event.
payloadobject- event fields
Returns object — frozen input-change event
inputSubmit(payload) method
Create an input-submit event.
payloadobject- event fields
Returns object — frozen input-submit event
key(payload) method
Create a key event.
payloadobject- event fields
Returns object — frozen key event
linkOpen(payload) method
Create a link-open event.
payloadobject- event fields
Returns object — frozen link-open event
paste(payload) method
Create a paste event.
payloadobject- event fields
Returns object — frozen paste event
pointer(payload) method
Create a pointer event.
payloadobject- event fields
Returns object — frozen pointer event
resize(payload) method
Create a resize event.
payloadobject- event fields
Returns object — frozen resize event
selectionCopy(payload) method
Create a selection-copy event.
payloadobject- event fields
Returns object — frozen selection-copy event
taskDone(payload) method
Create a completed-task event.
payloadobject- event fields
Returns object — frozen task-done event
taskFailed(payload) method
Create a failed-task event.
payloadobject- event fields
Returns object — frozen task-failed event
host = freeze({…}) constant
Host constructors for tests and terminal execution.
Defined in lib/app/gtui/gtui.js
memory(...) method
Create a memory host for deterministic application tests.
terminal(...) method
Create a terminal host for interactive execution.
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 — in-memory host implementing the GTUI host protocol
Defined in lib/app/gtui/gtui.js
effects property
Read: get effects()
Recorded effects, copied so callers cannot mutate host state.
Returns object[] — shallow copy of recorded effects
flush() method
Finish pending host output; memory hosts have nothing to flush.
Returns void
restoreCount property
Read: get restoreCount()
Number of completed host restoration cycles.
Returns number — restoration count
send(message) method
Send a host input message to the mounted application.
messageobject- input message
Returns void
snapshot() method
Return the current rendered scene in semantic, testable form.
Returns object — scene snapshot with current dimensions
scrollGlyph(value, fallback) function
Validate a one-cell grapheme for use as a scroll indicator.
value*- candidate glyph
fallback*- result when candidate is invalid
Returns * — candidate when it is a one-cell grapheme, otherwise fallback
Defined in lib/app/gtui/gtui.js
terminal(options = {…}) function
Construct a terminal host that owns input decoding and terminal rendering, or return options.host unchanged.
[options={}]object- terminal streams, mode, dimensions, and policies
Returns object — supplied or newly-created GTUI host
Defined in lib/app/gtui/gtui.js
view = freeze({…}) constant
Immutable constructors for renderable view nodes.
Defined in lib/app/gtui/gtui.js
button(props = {…}, label = "") method
Create a button node; activation emits action.select {id, action}. pressed styles an on toggle and tone adds a role.
[props={}]object- button properties
[label=""]*- label converted to a string
Returns object — frozen button node
column(...) method
Create an immutable vertical container.
[props={}]object- node properties
[children=[]Array|*- ] child nodes
Returns object — frozen column node
feed(props = {…}) method
Create an immutable feed control.
[props={}]object- feed properties
Returns object — frozen feed node
grid(...) method
Create an immutable grid container.
[props={}]object- node properties
[children=[]Array|*- ] child nodes
Returns object — frozen grid node
input(props = {…}) method
Create an immutable controlled text input. The value remains application-owned. mask: true displays one bullet per codepoint; a non-empty string requests a one-cell mask glyph (invalid glyphs use a bullet). Masking preserves the actual value and UTF-16 caret/selection offsets, hides completions, disables Copy, and omits the actual value from JSON and ordinary debug inspection. Masking is presentation, not encryption: direct node.value access still returns the actual value; input.change/input.submit carry it to the owner.
[props={}]object- Input properties including optional value, mask, caret, selection, focus, and placeholder. Properties are shallow-copied; referenced objects are retained, not mutated.
Returns object — Frozen input node; construction has no side effects and is retry-safe.
Throws — {Error} Propagates property-access or mask string processing errors.
overlay(...) method
Create an immutable overlay container. passive: true draws its last child above anchorAction in the first child's canvas without reserving layout rows or capturing input; position: "above-right" aligns its right edge.
[props={}]object- node properties
[children=[]Array|*- ] child nodes
Returns object — frozen overlay node
panel(...) method
Create an immutable bordered panel.
[props={}]object- node properties
[children=[]Array|*- ] child nodes
Returns object — frozen panel node
row(...) method
Create an immutable horizontal container.
[props={}]object- node properties
[children=[]Array|*- ] child nodes
Returns object — frozen row node
scroll(...) method
Create an immutable scroll container. Keyboard scroll.change events carry source:"keyboard" and repaint immediately; wheel paints remain coalesced.
[props={}]object- node properties
[children=[]Array|*- ] child nodes
Returns object — frozen scroll node
table(props = {…}, rows = []) method
Create an immutable table with frozen rows and cells.
[props={}]object- table properties
[rows=[]object[]- ] rows; each row's cells are copied and frozen
Returns object — frozen table node
text(props = {…}, content = "") method
Create immutable text content.
[props={}]object- text-node properties
[content=""]*- text content
Returns object — frozen text node
toolbar(...) method
Create a horizontal toolbar container with host-owned roving focus. Children use {id, focus, gap?, align?: "end"}; while focused, navigation keys move focus and Enter/Space activate; other keys bubble.
[props={}]object- toolbar properties
[children=[]Array|*- ] button children
Returns object — frozen toolbar node