nx.js
Classes

Terminal

A canvas-backed terminal. Wraps a headless xterm.js instance for terminal state/scrollback/ANSI parsing, and renders the cell grid into an OffscreenCanvas using the Canvas 2D API with the bundled Geist Mono font. Feed it ANSI text with write(); the rendered canvas is available as canvas.

Constructors

new Terminal()

new Terminal(opts): Terminal

Parameters

ParameterType
optsTerminalOptions

Returns

Terminal

Accessors

canvas

get canvas(): OffscreenCanvas

The OffscreenCanvas the terminal renders into.

Accessing this renders any pending output first (render() is a no-op when nothing changed), so the returned canvas always reflects the latest writes. This matters when an app composites console.canvas itself (e.g. drawImage) — especially after it has taken over the screen with screen.getContext('2d'), which stops the runtime's per-frame console present; without rendering here the canvas would freeze at the last auto-presented frame.

Returns

OffscreenCanvas


dirty

get dirty(): boolean

Whether the canvas needs to be re-rendered + re-presented.

Returns

boolean


scrollOffset

get scrollOffset(): number

Number of rows scrolled back from the bottom (0 = latest).

set scrollOffset(v): void

Parameters

ParameterType
vnumber

Returns

number


terminal

get terminal(): unknown

The underlying headless xterm.js Terminal instance, typed as unknown to avoid leaking the @xterm/headless dependency into the public type surface. Cast to import('@xterm/headless').Terminal if you need the full API.

Returns

unknown

Methods

render()

render(): boolean

Re-render the terminal buffer into the backing canvas. No-op when not dirty (cheap to call every frame). Returns whether a render happened.

Returns

boolean


scrollDown()

scrollDown(n): void

Scroll the viewport down n rows toward the latest output.

Parameters

ParameterTypeDefault value
nnumber1

Returns

void


scrollToBottom()

scrollToBottom(): void

Scroll back down to the latest output.

Returns

void


scrollToTop()

scrollToTop(): void

Scroll all the way up to the start of the scrollback history.

Returns

void


scrollUp()

scrollUp(n): void

Scroll the viewport up n rows into the scrollback history.

Parameters

ParameterTypeDefault value
nnumber1

Returns

void


write()

write(data): void

Write ANSI text to the terminal. Resets scrollback to the latest output.

Parameters

ParameterType
datastring

Returns

void

On this page