@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.
enum EraseRegion {
Screen
Line
LineEnd
LineStart
ScreenEnd
ScreenStart
Scrollback
}EraseRegion.Line#
The whole cursor line.
LineEraseRegion.LineEnd#
From the cursor to the end of the line.
LineEndEraseRegion.LineStart#
From the start of the line to the cursor.
LineStartEraseRegion.Screen#
Every cell of the screen; the cursor does not move.
ScreenEraseRegion.ScreenEnd#
From the cursor to the end of the screen.
ScreenEndEraseRegion.ScreenStart#
From the start of the screen to the cursor.
ScreenStartEraseRegion.Scrollback#
The scrollback buffer above the screen.
ScrollbackRawHandle Type#
What the native raw_mode returns: the runtime handle itself.
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.
opaque type RawTerminal {
}RawTerminal.clear#
Erases the screen and moves the cursor to the top left.
fn clear() Result[Void, Error]RawTerminal.close#
Restores the terminal; closing again does nothing.
move fn close() Result[Void, Error]RawTerminal.erase#
Erases the selected screen region without moving the cursor.
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.
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.
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.
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.
fn move_to_column(column Int) Result[Void, Error]RawTerminal.restore_cursor#
Returns to the position remembered by save_cursor.
fn restore_cursor() Result[Void, Error]RawTerminal.save_cursor#
Remembers the cursor position for restore_cursor.
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.
fn set_title(title String) Result[Void, Error]RawTerminal.show_cursor#
Shows or hides the cursor until the terminal is restored on close.
fn show_cursor(visible Bool) Result[Void, Error]RawTerminal.size#
Returns the current terminal size, or EBADF after close.
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.
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.
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.
colors IntTerminalCapabilities.error_is_terminal#
True when standard error is a terminal.
error_is_terminal BoolTerminalCapabilities.input_is_terminal#
True when standard input is a terminal.
input_is_terminal BoolTerminalCapabilities.output_is_terminal#
True when standard output is a terminal.
output_is_terminal BoolTerminalCapabilities.raw_mode#
True when raw_mode can succeed on this host and the streams are terminals.
raw_mode BoolTerminalCapabilities.resize_events#
True when raw terminals deliver Resize events.
resize_events BoolTerminalDecoder 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.
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.
discarding BoolTerminalDecoder.paste#
Characters of the paste so far.
paste List[String]TerminalDecoder.pasting#
True between the paste start and end markers.
pasting BoolTerminalDecoder.pending#
Characters of an escape sequence that is not complete yet.
pending List[String]TerminalDecoder.decode#
Decodes input text into events.
var fn decode(text String) List[TerminalEvent]TerminalDecoder.flush#
Resolves a held lone escape into the Escape key and drops any other unfinished sequence.
var fn flush() List[TerminalEvent]TerminalDecoder.partial#
True when an escape sequence is waiting for more input.
fn partial() BoolTerminalDecoder.take_paste#
Takes pasted characters from buf at at; returns where ordinary input resumes.
var fn take_paste(buf List[String], at Int, var out List[TerminalEvent]) IntTerminalEvent 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.
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.
Key(name String, ctrl Bool, alt Bool, shift Bool)TerminalEvent.Paste#
Text pasted through bracketed paste, delivered whole.
Paste(text String)TerminalEvent.Resize#
The terminal window changed size.
Resize(columns Int, rows Int)TerminalEvent.Text#
Printable characters typed together.
Text(text String)TerminalEvent.Key.alt#
True when Alt was held.
alt BoolTerminalEvent.Key.ctrl#
True when Control was held.
ctrl BoolTerminalEvent.Key.name#
The key name, such as enter, up, or a lowercase letter.
name StringTerminalEvent.Key.shift#
True when Shift was held for a named key.
shift BoolTerminalEvent.Paste.text#
The pasted text with line breaks as \n.
text StringTerminalEvent.Resize.columns#
The new width in columns.
columns IntTerminalEvent.Resize.rows#
The new height in rows.
rows IntTerminalEvent.Text.text#
The typed characters in order, as valid UTF-8 text.
text StringTerminalSize Type#
Character columns and rows of a terminal window.
type TerminalSize {
columns Int
rows Int
}TerminalSize.columns#
Width in character columns.
columns IntTerminalSize.rows#
Height in character rows.
rows Intraw_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.
fn raw_mode(alternate_screen Bool = false) Result[RawTerminal, Error] { ... }terminal_capabilities Function#
Reports terminal availability and color support without changing terminal state.
fn terminal_capabilities() TerminalCapabilities { ... }terminal_decoder Function#
A decoder with nothing pending.
fn terminal_decoder() TerminalDecoder { ... }terminal_size Function#
Returns the terminal size, or ENOTTY when output is redirected.
fn terminal_size() Result[TerminalSize, Error] { ... }