Skip to content

Termcodes

The termcodes module provides low-level escape sequence builders. Each function returns a Uint8Array you can write directly to stdout.

Encode a plain escape sequence. Prepends ESC (\x1b) to the given string.

import {
function ESC(str: string): Uint8Array

Encode a plain escape sequence.

Prepends ESC (\x1b) to the given string and returns the result as bytes.

ESC
} from "@bomb.sh/tty";
var process: NodeJS.Process
process
.
NodeJS.Process.stdout: NodeJS.WriteStream & {
fd: 1;
}

The process.stdout property returns a stream connected tostdout (fd 1). It is a net.Socket (which is a Duplex stream) unless fd 1 refers to a file, in which case it is a Writable stream.

For example, to copy process.stdin to process.stdout:

import { stdin, stdout } from 'node:process';
stdin.pipe(stdout);

process.stdout differs from other Node.js streams in important ways. See note on process I/O for more information.

stdout
.
Socket.write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean (+1 overload)

Sends data on the socket. The second parameter specifies the encoding in the case of a string. It defaults to UTF8 encoding.

Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory.'drain' will be emitted when the buffer is again free.

The optional callback parameter will be executed when the data is finally written out, which may not be immediately.

See Writable stream write() method for more information.

@sincev0.1.90

@paramencoding Only used when data is string.

write
(
function ESC(str: string): Uint8Array

Encode a plain escape sequence.

Prepends ESC (\x1b) to the given string and returns the result as bytes.

ESC
("7")); // save cursor (DECSC)

Encode a Control Sequence Introducer command. Prepends ESC[ to the given string.

import {
function CSI(str: string): Uint8Array

Encode a Control Sequence Introducer (CSI) command.

Prepends ESC[ to the given string and returns the result as bytes.

CSI
} from "@bomb.sh/tty";
var process: NodeJS.Process
process
.
NodeJS.Process.stdout: NodeJS.WriteStream & {
fd: 1;
}

The process.stdout property returns a stream connected tostdout (fd 1). It is a net.Socket (which is a Duplex stream) unless fd 1 refers to a file, in which case it is a Writable stream.

For example, to copy process.stdin to process.stdout:

import { stdin, stdout } from 'node:process';
stdin.pipe(stdout);

process.stdout differs from other Node.js streams in important ways. See note on process I/O for more information.

stdout
.
Socket.write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean (+1 overload)

Sends data on the socket. The second parameter specifies the encoding in the case of a string. It defaults to UTF8 encoding.

Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory.'drain' will be emitted when the buffer is again free.

The optional callback parameter will be executed when the data is finally written out, which may not be immediately.

See Writable stream write() method for more information.

@sincev0.1.90

@paramencoding Only used when data is string.

write
(
function CSI(str: string): Uint8Array

Encode a Control Sequence Introducer (CSI) command.

Prepends ESC[ to the given string and returns the result as bytes.

CSI
("2J")); // clear screen

Request cursor position via Device Status Report. Sends CSI 6n. The terminal responds with a Cursor Position Report (CSI row ; column R) where row and column are 1-based.

import {
function DSR(): Uint8Array

Request the cursor position via Device Status Report (DSR).

Sends CSI 6n. The terminal responds with a Cursor Position Report (CSI row ; column R) where row and column are 1-based.

DSR
} from "@bomb.sh/tty";
var process: NodeJS.Process
process
.
NodeJS.Process.stdout: NodeJS.WriteStream & {
fd: 1;
}

The process.stdout property returns a stream connected tostdout (fd 1). It is a net.Socket (which is a Duplex stream) unless fd 1 refers to a file, in which case it is a Writable stream.

For example, to copy process.stdin to process.stdout:

import { stdin, stdout } from 'node:process';
stdin.pipe(stdout);

process.stdout differs from other Node.js streams in important ways. See note on process I/O for more information.

stdout
.
Socket.write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean (+1 overload)

Sends data on the socket. The second parameter specifies the encoding in the case of a string. It defaults to UTF8 encoding.

Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory.'drain' will be emitted when the buffer is again free.

The optional callback parameter will be executed when the data is finally written out, which may not be immediately.

See Writable stream write() method for more information.

@sincev0.1.90

@paramencoding Only used when data is string.

write
(
function DSR(): Uint8Array

Request the cursor position via Device Status Report (DSR).

Sends CSI 6n. The terminal responds with a Cursor Position Report (CSI row ; column R) where row and column are 1-based.

DSR
());

The response is parsed as a cursor event by the input parser. Used by the inline regions example to place animated output in scrollback.

Show or hide the cursor (DEC private mode 25, DECTCEM).

import {
function HIDECURSOR(): Uint8Array

Hide the cursor (DECTCEM reset).

DEC private mode 25. Not part of ECMA-48; originates from the VT220.

HIDECURSOR
,
function SHOWCURSOR(): Uint8Array

Show the cursor (DECTCEM set).

DEC private mode 25. Not part of ECMA-48; originates from the VT220.

SHOWCURSOR
} from "@bomb.sh/tty";
var process: NodeJS.Process
process
.
NodeJS.Process.stdout: NodeJS.WriteStream & {
fd: 1;
}

The process.stdout property returns a stream connected tostdout (fd 1). It is a net.Socket (which is a Duplex stream) unless fd 1 refers to a file, in which case it is a Writable stream.

For example, to copy process.stdin to process.stdout:

import { stdin, stdout } from 'node:process';
stdin.pipe(stdout);

process.stdout differs from other Node.js streams in important ways. See note on process I/O for more information.

stdout
.
Socket.write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean (+1 overload)

Sends data on the socket. The second parameter specifies the encoding in the case of a string. It defaults to UTF8 encoding.

Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory.'drain' will be emitted when the buffer is again free.

The optional callback parameter will be executed when the data is finally written out, which may not be immediately.

See Writable stream write() method for more information.

@sincev0.1.90

@paramencoding Only used when data is string.

write
(
function HIDECURSOR(): Uint8Array

Hide the cursor (DECTCEM reset).

DEC private mode 25. Not part of ECMA-48; originates from the VT220.

HIDECURSOR
());
var process: NodeJS.Process
process
.
NodeJS.Process.stdout: NodeJS.WriteStream & {
fd: 1;
}

The process.stdout property returns a stream connected tostdout (fd 1). It is a net.Socket (which is a Duplex stream) unless fd 1 refers to a file, in which case it is a Writable stream.

For example, to copy process.stdin to process.stdout:

import { stdin, stdout } from 'node:process';
stdin.pipe(stdout);

process.stdout differs from other Node.js streams in important ways. See note on process I/O for more information.

stdout
.
Socket.write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean (+1 overload)

Sends data on the socket. The second parameter specifies the encoding in the case of a string. It defaults to UTF8 encoding.

Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory.'drain' will be emitted when the buffer is again free.

The optional callback parameter will be executed when the data is finally written out, which may not be immediately.

See Writable stream write() method for more information.

@sincev0.1.90

@paramencoding Only used when data is string.

write
(
function SHOWCURSOR(): Uint8Array

Show the cursor (DECTCEM set).

DEC private mode 25. Not part of ECMA-48; originates from the VT220.

SHOWCURSOR
());

Equivalent to cursor(false) / cursor(true).

Switch between main and alternate screen buffers.

import {
function ALTSCREEN(options?: {
clear?: boolean;
}): Uint8Array

Switch to the alternate screen buffer.

Saves the cursor and switches to the alternate screen. When clear is true (the default), the alternate buffer is cleared on entry. When false, the existing contents are preserved.

Use

MAINSCREEN

to switch back.

ALTSCREEN
,
function MAINSCREEN(): Uint8Array

Switch back to the main screen buffer.

Restores the cursor and returns to the main screen with scrollback intact.

MAINSCREEN
} from "@bomb.sh/tty";
var process: NodeJS.Process
process
.
NodeJS.Process.stdout: NodeJS.WriteStream & {
fd: 1;
}

The process.stdout property returns a stream connected tostdout (fd 1). It is a net.Socket (which is a Duplex stream) unless fd 1 refers to a file, in which case it is a Writable stream.

For example, to copy process.stdin to process.stdout:

import { stdin, stdout } from 'node:process';
stdin.pipe(stdout);

process.stdout differs from other Node.js streams in important ways. See note on process I/O for more information.

stdout
.
Socket.write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean (+1 overload)

Sends data on the socket. The second parameter specifies the encoding in the case of a string. It defaults to UTF8 encoding.

Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory.'drain' will be emitted when the buffer is again free.

The optional callback parameter will be executed when the data is finally written out, which may not be immediately.

See Writable stream write() method for more information.

@sincev0.1.90

@paramencoding Only used when data is string.

write
(
function ALTSCREEN(options?: {
clear?: boolean;
}): Uint8Array

Switch to the alternate screen buffer.

Saves the cursor and switches to the alternate screen. When clear is true (the default), the alternate buffer is cleared on entry. When false, the existing contents are preserved.

Use

MAINSCREEN

to switch back.

ALTSCREEN
()); // enter, clear
var process: NodeJS.Process
process
.
NodeJS.Process.stdout: NodeJS.WriteStream & {
fd: 1;
}

The process.stdout property returns a stream connected tostdout (fd 1). It is a net.Socket (which is a Duplex stream) unless fd 1 refers to a file, in which case it is a Writable stream.

For example, to copy process.stdin to process.stdout:

import { stdin, stdout } from 'node:process';
stdin.pipe(stdout);

process.stdout differs from other Node.js streams in important ways. See note on process I/O for more information.

stdout
.
Socket.write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean (+1 overload)

Sends data on the socket. The second parameter specifies the encoding in the case of a string. It defaults to UTF8 encoding.

Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory.'drain' will be emitted when the buffer is again free.

The optional callback parameter will be executed when the data is finally written out, which may not be immediately.

See Writable stream write() method for more information.

@sincev0.1.90

@paramencoding Only used when data is string.

write
(
function ALTSCREEN(options?: {
clear?: boolean;
}): Uint8Array

Switch to the alternate screen buffer.

Saves the cursor and switches to the alternate screen. When clear is true (the default), the alternate buffer is cleared on entry. When false, the existing contents are preserved.

Use

MAINSCREEN

to switch back.

ALTSCREEN
({
clear?: boolean
clear
: false })); // enter, preserve
var process: NodeJS.Process
process
.
NodeJS.Process.stdout: NodeJS.WriteStream & {
fd: 1;
}

The process.stdout property returns a stream connected tostdout (fd 1). It is a net.Socket (which is a Duplex stream) unless fd 1 refers to a file, in which case it is a Writable stream.

For example, to copy process.stdin to process.stdout:

import { stdin, stdout } from 'node:process';
stdin.pipe(stdout);

process.stdout differs from other Node.js streams in important ways. See note on process I/O for more information.

stdout
.
Socket.write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean (+1 overload)

Sends data on the socket. The second parameter specifies the encoding in the case of a string. It defaults to UTF8 encoding.

Returns true if the entire data was flushed successfully to the kernel buffer. Returns false if all or part of the data was queued in user memory.'drain' will be emitted when the buffer is again free.

The optional callback parameter will be executed when the data is finally written out, which may not be immediately.

See Writable stream write() method for more information.

@sincev0.1.90

@paramencoding Only used when data is string.

write
(
function MAINSCREEN(): Uint8Array

Switch back to the main screen buffer.

Restores the cursor and returns to the main screen with scrollback intact.

MAINSCREEN
()); // return to main screen

Equivalent to alternateBuffer() / its revert sequence.