Skip to content

terminal ​

Terminal input, output, cursor control and ANSI styling.

Import

ts
import { Terminal } from "terminal";

TerminalSize class ​

ts
class TerminalSize

Type only: the runtime hands you instances; you never construct it yourself.

Dimensions returned by Terminal.size().

TerminalSize.rows ​

ts
readonly rows: int

Terminal height in rows.

TerminalSize.cols ​

ts
readonly cols: int

Terminal width in columns.

TerminalKeyEvent class ​

ts
class TerminalKeyEvent

Type only: the runtime hands you instances; you never construct it yourself.

A keypress returned by Terminal.readKey().

TerminalKeyEvent.key ​

ts
readonly key: string

The key name, e.g. "a", "Enter", "Escape", "ArrowUp".

TerminalKeyEvent.ctrl ​

ts
readonly ctrl: boolean

Whether Ctrl is held.

TerminalKeyEvent.alt ​

ts
readonly alt: boolean

Whether Alt is held.

TerminalKeyEvent.shift ​

ts
readonly shift: boolean

Whether Shift is held.

Terminal static class ​

ts
static class Terminal

Terminal I/O, cursor control, clearing, styling, and raw mode.

Terminal.readLine ​

ts
static readLine(prompt: string, defaultValue?: string): Promise<string>

Read a line from stdin with the given prompt, optionally initialised to defaultValue. Returns a promise that resolves to the entered text.

Terminal.readPassword ​

ts
static readPassword(prompt: string): Promise<string>

Read a password from stdin with the given prompt, echoing asterisks instead of characters. Returns a promise that resolves to the entered password.

Terminal.readKey ​

ts
static readKey(): Promise<TerminalKeyEvent>

Read a single keypress including modifier state (Ctrl, Alt, Shift). Returns a promise that resolves to a TerminalKeyEvent.

Terminal.write ​

ts
static write(text: string): void

Write text to stdout without moving the cursor or writing a newline.

Example

ts
import { Terminal } from "terminal";
Terminal.write("loading...");

Terminal.rewriteLine ​

ts
static rewriteLine(text: string): void

Overwrite the current line with text, moving the cursor to the start.

Terminal.size ​

ts
static size(): TerminalSize

Query the terminal dimensions. Returns {rows, cols}.

Terminal.moveTo ​

ts
static moveTo(row: int, col: int): void

Move the cursor to (row, col) (1-indexed).

Terminal.moveUp ​

ts
static moveUp(n?: int): void

Move the cursor up by n rows (default 1).

Terminal.moveDown ​

ts
static moveDown(n?: int): void

Move the cursor down by n rows (default 1).

Terminal.moveLeft ​

ts
static moveLeft(n?: int): void

Move the cursor left by n columns (default 1).

Terminal.moveRight ​

ts
static moveRight(n?: int): void

Move the cursor right by n columns (default 1).

Terminal.moveToColumn ​

ts
static moveToColumn(col: int): void

Move the cursor to column col on the current row (1-indexed).

Terminal.clearLine ​

ts
static clearLine(): void

Clear from the cursor to the end of the current line.

Terminal.clearDown ​

ts
static clearDown(): void

Clear from the cursor to the end of the screen.

Terminal.clearScreen ​

ts
static clearScreen(): void

Clear the entire screen and move cursor to top-left.

Terminal.bold ​

ts
static bold(text: string): string

Wrap text with ANSI bold formatting.

Terminal.dim ​

ts
static dim(text: string): string

Wrap text with ANSI dim formatting.

Terminal.italic ​

ts
static italic(text: string): string

Wrap text with ANSI italic formatting.

Terminal.underline ​

ts
static underline(text: string): string

Wrap text with ANSI underline formatting.

Terminal.strikethrough ​

ts
static strikethrough(text: string): string

Wrap text with ANSI strikethrough formatting.

Terminal.red ​

ts
static red(text: string): string

Wrap text with red foreground color.

Terminal.green ​

ts
static green(text: string): string

Wrap text with green foreground color.

Terminal.yellow ​

ts
static yellow(text: string): string

Wrap text with yellow foreground color.

Terminal.blue ​

ts
static blue(text: string): string

Wrap text with blue foreground color.

Terminal.magenta ​

ts
static magenta(text: string): string

Wrap text with magenta foreground color.

Terminal.cyan ​

ts
static cyan(text: string): string

Wrap text with cyan foreground color.

Terminal.white ​

ts
static white(text: string): string

Wrap text with white foreground color.

Terminal.gray ​

ts
static gray(text: string): string

Wrap text with gray (light black) foreground color.

Terminal.rgb ​

ts
static rgb(r: int, g: int, b: int, text: string): string

Wrap text with an RGB foreground color. @param r Red channel (0-255). @param g Green channel (0-255). @param b Blue channel (0-255). @param text The text to color. @returns The text wrapped with ANSI RGB color codes.

Terminal.bgRed ​

ts
static bgRed(text: string): string

Wrap text with red background color.

Terminal.bgGreen ​

ts
static bgGreen(text: string): string

Wrap text with green background color.

Terminal.bgYellow ​

ts
static bgYellow(text: string): string

Wrap text with yellow background color.

Terminal.bgBlue ​

ts
static bgBlue(text: string): string

Wrap text with blue background color.

Terminal.bgMagenta ​

ts
static bgMagenta(text: string): string

Wrap text with magenta background color.

Terminal.bgCyan ​

ts
static bgCyan(text: string): string

Wrap text with cyan background color.

Terminal.bgWhite ​

ts
static bgWhite(text: string): string

Wrap text with white background color.

Terminal.bgGray ​

ts
static bgGray(text: string): string

Wrap text with gray (light black) background color.

Terminal.reset ​

ts
static reset(): void

Reset all ANSI formatting (bold, dim, color, etc.) on stdout.

Terminal.setRawMode ​

ts
static setRawMode(enable: boolean): void

Enable or disable raw mode on stdin, allowing direct control of keyboard input including modifier keys.

Terminal.isTTY ​

ts
static readonly isTTY: boolean

True if stdin is a TTY (interactive terminal); false if redirected.

Terminal.stdoutIsTTY ​

ts
static readonly stdoutIsTTY: boolean

True if stdout is a TTY (interactive terminal); false if redirected.

Terminal.colorDepth ​

ts
static readonly colorDepth: int

The terminal's color depth: 1 (monochrome), 4 (16 colors), 8 (256 colors), or 24 (true color).


Generated from lang/types/terminal.d.tks in the ThicketScript repository.