Manuscript Documentation
v2026.12.0

@std/cli/terminal.ms#

Import each required symbol with import Name from "@std/cli/terminal.ms".

EraseRegion Enum#

The part of the screen cleared by RawTerminal.erase.

Manuscript
enum EraseRegion {
    Screen
    Line
    LineEnd
    LineStart
    ScreenEnd
    ScreenStart
    Scrollback
}

EraseRegion.Line#

The whole cursor line.

Manuscript
Line

EraseRegion.LineEnd#

From the cursor to the end of the line.

Manuscript
LineEnd

EraseRegion.LineStart#

From the start of the line to the cursor.

Manuscript
LineStart

EraseRegion.Screen#

Every cell of the screen; the cursor does not move.

Manuscript
Screen

EraseRegion.ScreenEnd#

From the cursor to the end of the screen.

Manuscript
ScreenEnd

EraseRegion.ScreenStart#

From the start of the screen to the cursor.

Manuscript
ScreenStart

EraseRegion.Scrollback#

The scrollback buffer above the screen.

Manuscript
Scrollback

RawHandle Type#

What the native raw_mode returns: the runtime handle itself.

Manuscript
opaque type RawHandle {
}

RawTerminal Type#

Raw terminal input and cursor control. Closing it, or leaving the scope that acquired it by return, error, fault, or cancellation, restores the original terminal settings, shows the cursor, and leaves the alternate screen. In raw mode, Ctrl-C arrives as a c key with ctrl set instead of cancelling.

Manuscript
opaque type RawTerminal {
}

RawTerminal.clear#

Erases the screen and moves the cursor to the top left.

Manuscript
fn clear() Result[Void, Error]

RawTerminal.close#

Restores the terminal; closing again does nothing.

Manuscript
move fn close() Result[Void, Error]

RawTerminal.erase#

Erases the selected screen region without moving the cursor.

Manuscript
fn erase(region EraseRegion) Result[Void, Error]

RawTerminal.events#

Input events as a stream: keys, text and resizes, one per read. Waits honor cancellation and promise timeouts. The stream ends with an error once the terminal is closed; closing the stream leaves the terminal open.

Manuscript
fn events() ReadStream[TerminalEvent]

RawTerminal.move_by#

Moves the cursor down by rows and right by columns; negative values move up and left. The cursor stops at the screen edge.

Manuscript
fn move_by(rows Int, columns Int) Result[Void, Error]

RawTerminal.move_cursor#

Moves the cursor to a zero-based row and column; negative or very large values return EINVAL.

Manuscript
fn move_cursor(row Int, column Int) Result[Void, Error]

RawTerminal.move_to_column#

Moves the cursor to a zero-based column of its current row.

Manuscript
fn move_to_column(column Int) Result[Void, Error]

RawTerminal.restore_cursor#

Returns to the position remembered by save_cursor.

Manuscript
fn restore_cursor() Result[Void, Error]

RawTerminal.save_cursor#

Remembers the cursor position for restore_cursor.

Manuscript
fn save_cursor() Result[Void, Error]

RawTerminal.set_title#

Sets the window title. BEL, ESC, and U+009C are removed first, so the text cannot end the title early or start another escape sequence.

Manuscript
fn set_title(title String) Result[Void, Error]

RawTerminal.show_cursor#

Shows or hides the cursor until the terminal is restored on close.

Manuscript
fn show_cursor(visible Bool) Result[Void, Error]

RawTerminal.size#

Returns the current terminal size, or EBADF after close.

Manuscript
fn size() Result[TerminalSize, Error]

RawTerminal.write#

Writes text or escape sequences to the terminal, after any buffered program output. Fails with EBADF after close.

Manuscript
fn write(text String) Result[Void, Error]

TerminalCapabilities Type#

What the current process can do with its standard streams as a terminal. colors is 0 when output is not a terminal, NO_COLOR is set, or TERM is dumb; otherwise 16, 256, or 16777216 from TERM and COLORTERM.

Manuscript
type TerminalCapabilities {
    input_is_terminal Bool
    output_is_terminal Bool
    error_is_terminal Bool
    raw_mode Bool
    resize_events Bool
    colors Int
}

TerminalCapabilities.colors#

Supported color count, or 0 when color output should be avoided.

Manuscript
colors Int

TerminalCapabilities.error_is_terminal#

True when standard error is a terminal.

Manuscript
error_is_terminal Bool

TerminalCapabilities.input_is_terminal#

True when standard input is a terminal.

Manuscript
input_is_terminal Bool

TerminalCapabilities.output_is_terminal#

True when standard output is a terminal.

Manuscript
output_is_terminal Bool

TerminalCapabilities.raw_mode#

True when raw_mode can succeed on this host and the streams are terminals.

Manuscript
raw_mode Bool

TerminalCapabilities.resize_events#

True when raw terminals deliver Resize events.

Manuscript
resize_events Bool

TerminalDecoder Type#

Turns terminal input text into TerminalEvents. decode takes what a read returned and may hold back an incomplete escape sequence for the next call; flush resolves a held lone escape into the Escape key once input has gone quiet. Bracketed pastes become one Paste event however the input is split. Resize events do not come from input; the event stream adds them.

Manuscript
type TerminalDecoder {
    pending List[String]
    pasting Bool
    paste List[String]
    discarding Bool
}

TerminalDecoder.discarding#

True while the rest of an overlong CSI sequence is being dropped.

Manuscript
discarding Bool

TerminalDecoder.paste#

Characters of the paste so far.

Manuscript
paste List[String]

TerminalDecoder.pasting#

True between the paste start and end markers.

Manuscript
pasting Bool

TerminalDecoder.pending#

Characters of an escape sequence that is not complete yet.

Manuscript
pending List[String]

TerminalDecoder.decode#

Decodes input text into events.

Manuscript
var fn decode(text String) List[TerminalEvent]

TerminalDecoder.flush#

Resolves a held lone escape into the Escape key and drops any other unfinished sequence.

Manuscript
var fn flush() List[TerminalEvent]

TerminalDecoder.partial#

True when an escape sequence is waiting for more input.

Manuscript
fn partial() Bool

TerminalDecoder.take_paste#

Takes pasted characters from buf at at; returns where ordinary input resumes.

Manuscript
var fn take_paste(buf List[String], at Int, var out List[TerminalEvent]) Int

TerminalEvent Enum#

One decoded terminal input event. Text carries printable characters typed together. Key names a non-printing or modified key: enter, tab, backspace, escape, space, up, down, left, right, home, end, insert, delete, page_up, page_down, f1 to f12, or a letter with ctrl or alt set. Paste carries text pasted as one unit, line breaks as \n. Resize carries the new size.

Manuscript
enum TerminalEvent {
    Text(text String)
    Key(name String, ctrl Bool, alt Bool, shift Bool)
    Resize(columns Int, rows Int)
    Paste(text String)
}

TerminalEvent.Key#

A named or modified key press.

Manuscript
Key(name String, ctrl Bool, alt Bool, shift Bool)

TerminalEvent.Paste#

Text pasted through bracketed paste, delivered whole.

Manuscript
Paste(text String)

TerminalEvent.Resize#

The terminal window changed size.

Manuscript
Resize(columns Int, rows Int)

TerminalEvent.Text#

Printable characters typed together.

Manuscript
Text(text String)

TerminalEvent.Key.alt#

True when Alt was held.

Manuscript
alt Bool

TerminalEvent.Key.ctrl#

True when Control was held.

Manuscript
ctrl Bool

TerminalEvent.Key.name#

The key name, such as enter, up, or a lowercase letter.

Manuscript
name String

TerminalEvent.Key.shift#

True when Shift was held for a named key.

Manuscript
shift Bool

TerminalEvent.Paste.text#

The pasted text with line breaks as \n.

Manuscript
text String

TerminalEvent.Resize.columns#

The new width in columns.

Manuscript
columns Int

TerminalEvent.Resize.rows#

The new height in rows.

Manuscript
rows Int

TerminalEvent.Text.text#

The typed characters in order, as valid UTF-8 text.

Manuscript
text String

TerminalSize Type#

Character columns and rows of a terminal window.

Manuscript
type TerminalSize {
    columns Int
    rows Int
}

TerminalSize.columns#

Width in character columns.

Manuscript
columns Int

TerminalSize.rows#

Height in character rows.

Manuscript
rows Int

raw_mode Function#

Acquires raw input and, when alternate_screen is true, switches to the alternate screen. Returns EBUSY while another raw terminal is open and ENOTTY when the streams are redirected.

Manuscript
fn raw_mode(alternate_screen Bool = false) Result[RawTerminal, Error] { ... }

terminal_capabilities Function#

Reports terminal availability and color support without changing terminal state.

Manuscript
fn terminal_capabilities() TerminalCapabilities { ... }

terminal_decoder Function#

A decoder with nothing pending.

Manuscript
fn terminal_decoder() TerminalDecoder { ... }

terminal_size Function#

Returns the terminal size, or ENOTTY when output is redirected.

Manuscript
fn terminal_size() Result[TerminalSize, Error] { ... }