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
| Parameter | Type |
|---|---|
opts | TerminalOptions |
Returns
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
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
| Parameter | Type |
|---|---|
v | number |
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
| Parameter | Type | Default value |
|---|---|---|
n | number | 1 |
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
| Parameter | Type | Default value |
|---|---|---|
n | number | 1 |
Returns
void
write()
write(data): void
Write ANSI text to the terminal. Resets scrollback to the latest output.
Parameters
| Parameter | Type |
|---|---|
data | string |
Returns
void