gespenst API - v0.1.0
    Preparing search index...

    Getting Started

    Create a responsive browser terminal with the default worker and renderer selection.

    pnpm add @gespenst/core
    

    The terminal needs its package stylesheet and a host element with a nonzero width and height.

    <div id="terminal"></div>

    <style>
    #terminal {
    width: 100%;
    height: 32rem;
    }
    </style>

    This example is compiled by the workspace typecheck and included here from its canonical source.

    const host = requiredElement<HTMLElement>('#terminal');

    const terminal = await createTerminal({
    container: host,
    worker: 'dedicated',
    renderer: 'auto',
    accessibility: 'basic',
    });

    terminal.write('\x1b[1;32mgespenst is ready\x1b[0m\r\n');
    terminal.focus();

    window.addEventListener('beforeunload', () => terminal.dispose(), { once: true });

    createTerminal() waits until Ghostty WASM, the selected execution context, and the renderer are ready. The returned terminal owns its DOM nodes, worker, renderer, listeners, addons, and active connections.

    The default worker policy uses a dedicated worker when the browser supports workers and OffscreenCanvas. Otherwise, the same API runs on the main thread. The default renderer: 'auto' tries WebGPU, then WebGL2, then Canvas 2D for cell backgrounds. Text shaping always uses the browser Canvas 2D implementation.

    The package CSS makes the terminal fill its host. It cannot invent a height for the host. A missing height usually produces a zero-row or unexpectedly small terminal.

    The terminal watches its own root with ResizeObserver. When its host changes size, the grid is remeasured and a resize event is emitted after the backend receives the new geometry. If the host is initially hidden, call terminal.fit() after it becomes visible.

    Use write() for fire-and-forget output. Use writeAsync() when a producer needs to wait until that chunk has crossed the parse and render boundary. Keep PTY output as Uint8Array data whenever possible.

    Call dispose() when the view is removed. Disposal closes connections, disposes addons in reverse activation order, releases loaded font faces, terminates owned workers, and removes terminal DOM.

    Attach a shell in Connecting a PTY, or review worker and renderer choices in Configuration.