terminal
Terminal input, output, cursor control and ANSI styling.
Import
ts
import { Terminal } from "terminal";TerminalSize class
ts
class TerminalSizeType only: the runtime hands you instances; you never construct it yourself.
Dimensions returned by Terminal.size().
TerminalSize.rows
ts
readonly rows: intTerminal height in rows.
TerminalSize.cols
ts
readonly cols: intTerminal width in columns.
TerminalKeyEvent class
ts
class TerminalKeyEventType only: the runtime hands you instances; you never construct it yourself.
A keypress returned by Terminal.readKey().
TerminalKeyEvent.key
ts
readonly key: stringThe key name, e.g. "a", "Enter", "Escape", "ArrowUp".
TerminalKeyEvent.ctrl
ts
readonly ctrl: booleanWhether Ctrl is held.
TerminalKeyEvent.alt
ts
readonly alt: booleanWhether Alt is held.
TerminalKeyEvent.shift
ts
readonly shift: booleanWhether Shift is held.
Terminal static class
ts
static class TerminalTerminal 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): voidWrite 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): voidOverwrite the current line with text, moving the cursor to the start.
Terminal.size
ts
static size(): TerminalSizeQuery the terminal dimensions. Returns {rows, cols}.
Terminal.moveTo
ts
static moveTo(row: int, col: int): voidMove the cursor to (row, col) (1-indexed).
Terminal.moveUp
ts
static moveUp(n?: int): voidMove the cursor up by n rows (default 1).
Terminal.moveDown
ts
static moveDown(n?: int): voidMove the cursor down by n rows (default 1).
Terminal.moveLeft
ts
static moveLeft(n?: int): voidMove the cursor left by n columns (default 1).
Terminal.moveRight
ts
static moveRight(n?: int): voidMove the cursor right by n columns (default 1).
Terminal.moveToColumn
ts
static moveToColumn(col: int): voidMove the cursor to column col on the current row (1-indexed).
Terminal.clearLine
ts
static clearLine(): voidClear from the cursor to the end of the current line.
Terminal.clearDown
ts
static clearDown(): voidClear from the cursor to the end of the screen.
Terminal.clearScreen
ts
static clearScreen(): voidClear the entire screen and move cursor to top-left.
Terminal.bold
ts
static bold(text: string): stringWrap text with ANSI bold formatting.
Terminal.dim
ts
static dim(text: string): stringWrap text with ANSI dim formatting.
Terminal.italic
ts
static italic(text: string): stringWrap text with ANSI italic formatting.
Terminal.underline
ts
static underline(text: string): stringWrap text with ANSI underline formatting.
Terminal.strikethrough
ts
static strikethrough(text: string): stringWrap text with ANSI strikethrough formatting.
Terminal.red
ts
static red(text: string): stringWrap text with red foreground color.
Terminal.green
ts
static green(text: string): stringWrap text with green foreground color.
Terminal.yellow
ts
static yellow(text: string): stringWrap text with yellow foreground color.
Terminal.blue
ts
static blue(text: string): stringWrap text with blue foreground color.
Terminal.magenta
ts
static magenta(text: string): stringWrap text with magenta foreground color.
Terminal.cyan
ts
static cyan(text: string): stringWrap text with cyan foreground color.
Terminal.white
ts
static white(text: string): stringWrap text with white foreground color.
Terminal.gray
ts
static gray(text: string): stringWrap text with gray (light black) foreground color.
Terminal.rgb
ts
static rgb(r: int, g: int, b: int, text: string): stringWrap 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): stringWrap text with red background color.
Terminal.bgGreen
ts
static bgGreen(text: string): stringWrap text with green background color.
Terminal.bgYellow
ts
static bgYellow(text: string): stringWrap text with yellow background color.
Terminal.bgBlue
ts
static bgBlue(text: string): stringWrap text with blue background color.
Terminal.bgMagenta
ts
static bgMagenta(text: string): stringWrap text with magenta background color.
Terminal.bgCyan
ts
static bgCyan(text: string): stringWrap text with cyan background color.
Terminal.bgWhite
ts
static bgWhite(text: string): stringWrap text with white background color.
Terminal.bgGray
ts
static bgGray(text: string): stringWrap text with gray (light black) background color.
Terminal.reset
ts
static reset(): voidReset all ANSI formatting (bold, dim, color, etc.) on stdout.
Terminal.setRawMode
ts
static setRawMode(enable: boolean): voidEnable or disable raw mode on stdin, allowing direct control of keyboard input including modifier keys.
Terminal.isTTY
ts
static readonly isTTY: booleanTrue if stdin is a TTY (interactive terminal); false if redirected.
Terminal.stdoutIsTTY
ts
static readonly stdoutIsTTY: booleanTrue if stdout is a TTY (interactive terminal); false if redirected.
Terminal.colorDepth
ts
static readonly colorDepth: intThe 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.