std/term
Terminal raw mode, terminal size, and single-key input. Each OS has its own implementation behind the one import path. Restore the saved state before exiting; std/keys decodes the escape sequences that raw mode lets through.
from "std/term" import { enableRawMode, restoreTerminal, terminalSize }API reference
std/term has one implementation per target (darwin, linux, windows); the resolver picks the one for the target you build for.
TermSize
pub struct TermSizeSize of the controlling terminal, in character cells.
Queried on stdout rather than stdin so it still works when input is piped. The ioctl request number is platform-specific and is inlined rather than exposed as a helper, because std/pty already defines a tiocgwinsz in the same flat namespace and importing both would clash.
Falls back to 80x24 when the fd is not a terminal (piped, redirected, or run under a harness) so callers always get a usable frame size.
Fields: rows: i64, cols: i64.
TermState
pub struct TermStatemacOS arm64: termios is 72 bytes, padded to 80
Fields: saved: [u8; 80].
Functions
enableRawMode
pub fn enableRawMode(): TermStateenableRawModeBlocking
pub fn enableRawModeBlocking(): TermStateLike enableRawMode but VMIN=1: read(0,…) blocks until one byte arrives instead of returning immediately. For an input-driven loop (a line editor) this waits on the keyboard without busy-spinning, which VMIN=0 would force.
getConsoleModeOf
pub fn getConsoleModeOf(handle: i64): u32Only on windows.
rawModeFrom
pub fn rawModeFrom(saved: u32): u32Only on windows.
ENABLE_PROCESSED_INPUT 0x1 | ENABLE_LINE_INPUT 0x2 | ENABLE_ECHO_INPUT 0x4 cleared, ENABLE_VIRTUAL_TERMINAL_INPUT 0x200 set.
readKey
pub fn readKey(): i32read a keypress without blocking; returns KEY_* constant
restoreTerminal
pub fn restoreTerminal(state: &TermState): voidstdinHandle
pub fn stdinHandle(): i64Only on windows.
terminalSize
pub fn terminalSize(): TermSizeQueried on stdout, matching the POSIX arms, so it still works with piped input. Falls back to 80x24 when stdout is not a console (redirected, or under a harness).