Skip to main content

Terminal

The Terminal interface provides low-level access to terminal operations including rendering, cursor control, and screen management.

Terminal Interface

Minimal terminal interface for TUI with input handling and screen control.

ProcessTerminal Class

Real terminal implementation using process.stdin/process.stdout.

Constructor

Creates a new ProcessTerminal instance.

Methods

start()

Starts the terminal with input and resize handlers.
(data: string) => void
required
Callback invoked when input data is received
() => void
required
Callback invoked when terminal is resized

stop()

Stops the terminal and restores previous state.

drainInput()

Drains stdin before exiting to prevent Kitty key release events from leaking to the parent shell over slow SSH connections.
number
default:"1000"
Maximum time to drain in milliseconds
number
default:"50"
Exit early if no input arrives within this time in milliseconds

write()

Writes output to the terminal.
string
required
Data to write to terminal

moveBy()

Moves cursor up or down by N lines relative to current position.
number
required
Number of lines to move. Positive moves down, negative moves up.

hideCursor() / showCursor()

Controls cursor visibility.

clearLine()

Clears the current line.

clearFromCursor()

Clears from cursor to end of screen.

clearScreen()

Clears entire screen and moves cursor to (0,0).

setTitle()

Sets terminal window title.
string
required
Window title text

Properties

columns

Current terminal width in columns.

rows

Current terminal height in rows.

kittyProtocolActive

Whether Kitty keyboard protocol is active.

Features

Kitty Keyboard Protocol

The terminal automatically queries and enables the Kitty keyboard protocol when available, providing:
  • Disambiguated escape codes
  • Key press/repeat/release events
  • Alternate keys (shifted key, base layout key)
  • Support for non-Latin keyboard layouts

Bracketed Paste Mode

Bracketed paste mode is automatically enabled, wrapping pastes in \x1b[200~\x1b[201~ sequences.

Windows VT Input Support

On Windows, automatically enables ENABLE_VIRTUAL_TERMINAL_INPUT so the terminal sends VT sequences for modified keys (e.g., \x1b[Z for Shift+Tab).

Example Usage

Environment Variables

string
Path to log all terminal writes (for debugging)