API Reference

Complete reference for all wterm options, methods, types, and transport APIs.

Terminal Options

Both the React <Terminal> component and the vanilla WTerm constructor accept these options:

OptionTypeDefaultDescription
colsnumber80Initial column count
rowsnumber24Initial row count
wasmUrlstringURL to serve the WASM binary separately. When omitted, the ~12 KB binary is decoded from an inlined base64 string.
autoResizebooleantrue (vanilla) / false (React)Automatically resize the terminal to fit its container using a ResizeObserver
cursorBlinkbooleanfalseEnable cursor blinking animation
onData(data: string) => voidCalled when the terminal produces data (user input or host response). When omitted, input is echoed back automatically.
onTitle(title: string) => voidCalled when the terminal title changes via an escape sequence
onResize(cols: number, rows: number) => voidCalled after the terminal is resized

React-Only Props

The React <Terminal> component adds these props on top of the shared options above. It also spreads standard HTML attributes (className, style, id, etc.) onto the root div.

PropTypeDescription
themestringName of a built-in or custom theme (see Themes)
onReady(wt: WTerm) => voidCalled with the underlying WTerm instance after WASM loads and initialization completes
onError(error: unknown) => voidCalled if WASM loading or initialization fails. When omitted, errors are logged to the console.

WTerm Methods

Instance methods on the vanilla WTerm class:

MethodDescription
init(): Promise<WTerm>Load WASM and start rendering
write(data: string | Uint8Array)Write data to the terminal
resize(cols, rows)Resize the terminal grid
focus()Focus the terminal input
destroy()Clean up event listeners, observers, and DOM

Imperative Handle (React)

The useTerminal hook returns a ref and convenience methods that delegate to the underlying WTerm instance:

const { ref, write, resize, focus } = useTerminal();
ReturnTypeDescription
refRefObject<TerminalHandle>Pass to <Terminal ref={ref}>
write(data: string | Uint8Array) => voidWrite data to the terminal
resize(cols: number, rows: number) => voidResize the terminal grid
focus() => voidFocus the terminal input

The TerminalHandle interface exposed via ref:

interface TerminalHandle {
  write(data: string | Uint8Array): void;
  resize(cols: number, rows: number): void;
  focus(): void;
  readonly instance: WTerm | null;
}

WebSocketTransport

Connect to a PTY backend over WebSocket with automatic reconnection and send buffering.

Options

OptionTypeDefaultDescription
urlstringWebSocket server URL
reconnectbooleantrueAutomatically reconnect on disconnect with exponential backoff
maxReconnectDelaynumber30000Maximum delay between reconnection attempts (ms)
onData(data: Uint8Array | string) => voidCalled when data is received from the server
onOpen() => voidCalled when the connection opens
onClose() => voidCalled when the connection closes
onError(event: Event) => voidCalled when a WebSocket error occurs

Methods

MethodDescription
connect(url?)Open the WebSocket connection. Optionally override the URL.
send(data: string | Uint8Array)Send data to the server. If the socket is not yet open, data is buffered and flushed on connect.
close()Close the connection and stop reconnection attempts.

Properties

PropertyTypeDescription
connectedbooleanWhether the WebSocket is currently open

WasmBridge

Low-level interface to the Zig/WASM terminal state machine. The bridge manages a virtual terminal grid in WASM memory — you write data in and read cells, cursor state, and scrollback out.

Loading

import { WasmBridge } from "@wterm/core";

const bridge = await WasmBridge.load();
const bridge = await WasmBridge.load("/wterm.wasm");

When no URL is provided, the ~12 KB WASM binary is decoded from a base64 string inlined in the package. Pass a URL when you want to serve the binary separately for caching or CDN use.

Methods

MethodDescription
WasmBridge.load(url?): Promise<WasmBridge>Load the WASM binary and return a new bridge instance
init(cols, rows)Initialize the terminal grid
writeString(str)Write a UTF-8 string (including escape sequences) to the terminal
writeRaw(data: Uint8Array)Write raw bytes to the terminal (chunked to 8192 bytes internally)
resize(cols, rows)Resize the terminal grid
getCell(row, col): CellDataGet cell data at a grid position
getCursor(): CursorStateGet current cursor position and visibility
getCols() / getRows()Get current grid dimensions
isDirtyRow(row): booleanCheck if a row has changed since last clearDirty()
clearDirty()Reset all dirty-row flags
getTitle(): string | nullGet pending title change (via OSC escape), or null if unchanged
getResponse(): string | nullGet pending host response (e.g. DSR), or null. Reading clears the buffer.
getScrollbackCount(): numberNumber of lines in the scrollback buffer
getScrollbackCell(offset, col): CellDataGet cell data from a scrollback line
getScrollbackLineLen(offset): numberGet the length of a scrollback line
cursorKeysApp(): booleanWhether cursor keys are in application mode
bracketedPaste(): booleanWhether bracketed paste mode is active
usingAltScreen(): booleanWhether the alternate screen buffer is active

Types

interface CellData {
  char: number;   // Unicode code point
  fg: number;     // Foreground color index (256 = default)
  bg: number;     // Background color index (256 = default)
  flags: number;  // Style flags (bold, italic, underline, etc.)
}

interface CursorState {
  row: number;
  col: number;
  visible: boolean;
}