Configuration

Options

Both the React Terminal component and the vanilla WTerm constructor accept the same core options:

OptionTypeDefaultDescription
colsnumber80Number of columns
rowsnumber24Number of rows
wasmUrlstring"wterm.wasm"URL to the WASM binary
autoResizebooleantrue (vanilla) / false (React)Automatically resize to fit the container using a ResizeObserver
cursorBlinkbooleanfalseEnable cursor blinking animation

Event Callbacks

CallbackTypeDescription
onData(data: string) => voidCalled when the terminal produces output (user input or emulator response)
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

The React Terminal component adds two extra props:

PropTypeDescription
onReady(wt: WTerm) => voidFires with the underlying WTerm instance once initialization completes
themestringName of a built-in or custom theme (see Themes)

The component also spreads standard HTML attributes onto the root div, so you can pass className, style, ARIA attributes, and other DOM props directly.

Imperative Handle (React)

When using useTerminal, the returned ref exposes an imperative handle:

import { Terminal, useTerminal } from "@wterm/react";

function App() {
  const { ref, write } = useTerminal();

  return (
    <Terminal
      ref={ref}
      wasmUrl="/wterm.wasm"
      onReady={(wt) => {
        wt.resize(120, 40);
      }}
      onData={(data) => write(data)}
    />
  );
}
MethodTypeDescription
write(data: string | Uint8Array) => voidWrite data to the terminal
resize(cols: number, rows: number) => voidResize the terminal grid
focus() => voidFocus the terminal element
instanceWTerm | nullDirect access to the underlying WTerm instance

WebSocket Transport

For connecting to a remote shell over WebSocket, use the built-in WebSocketTransport:

import { WTerm, WebSocketTransport } from "@wterm/dom";

const ws = new WebSocketTransport({
  url: "wss://your-server.example/shell",
  reconnect: true,
  maxReconnectDelay: 5000,
  onData(data) {
    term.write(data);
  },
  onOpen() {
    console.log("connected");
  },
  onClose() {
    console.log("disconnected");
  },
});

const term = new WTerm(document.getElementById("terminal"), {
  wasmUrl: "/wterm.wasm",
  onData(data) {
    ws.send(data);
  },
});

await term.init();
ws.connect();
OptionTypeDefaultDescription
urlstringWebSocket server URL
reconnectbooleantrueAutomatically reconnect on disconnect
maxReconnectDelaynumber30000Maximum delay between reconnection attempts (ms), with exponential backoff
onData(data: Uint8Array | string) => voidCalled when data is received from the server
onOpen() => voidCalled when the connection opens
onClose() => voidCalled when the connection closes

The transport buffers any send() calls made before the connection is open and flushes them automatically on connect.