installTTYBridge
installTTYBridge(
module,options):void
Defined in: packages/runtime/src/wasm/tty-bridge.ts:623
Install custom TTY ops on an Emscripten module so that stdin reads suspend via Asyncify and resume when input arrives.
Replaces the default get_char, put_char, fsync, and ioctl_* handlers
on both the console (major=5) and stderr (major=6) TTY devices, wires
a 1-byte-per-call TTY.stream_ops.read (see caveat), and installs an
Asyncify-aware poll on stdin so select() works with async input.
Call this AFTER module init but BEFORE calling _main().
Parameters
Section titled “Parameters”module
Section titled “module”An initialized Emscripten module compiled with Asyncify + TTY.
options
Section titled “options”Input source, output sink, and optional terminal size. See TTYBridgeOptions.
Returns
Section titled “Returns”void
Throws
Section titled “Throws”Error if module.Asyncify is undefined — the module was not compiled with -sASYNCIFY.
Throws
Section titled “Throws”Error if module.TTY is undefined — TTY is not in EXPORTED_RUNTIME_METHODS.
Caveat
Section titled “Caveat”The default TTY read loop calls get_char until the buffer fills,
which triggers a double-Asyncify-unwind and crashes. The 1-byte
read override forces fd_read to return to WASM after each byte.
Example
Section titled “Example”const queue = createInputQueue()const output = createBufferedOutput(chunk => proc.stdout.write(chunk))installTTYBridge(module, { input: queue, output })await runWithAsyncify(module, args)