Module term
Terminal facade: TTY detection, terminal size, color-support detection and
raw mode for the standard streams — the typed, non-sys face of
std/sys/tty (which stays fd- and errno-oriented). std/cli and
interactive tools consume this module.
Stability
unstable — a small facade (is_terminal, size, supports_color,
enter_raw_mode, restore_mode) whose names are settled, over a
std/sys/tty that is not. Two things are open. enter_raw_mode /
restore_mode are a PAIR the caller must balance by hand, and a process
that dies between them leaves the terminal in raw mode — the shape that
fixes it is a guard value with a Dispose, the way Semaphore.with_permit
and Mutex.with_lock already work in std/sync. And supports_color
answers a bool from TERM/NO_COLOR heuristics, where callers
increasingly want a LEVEL (none / 16 / 256 / truecolor).
Both are additive to add and breaking to change afterwards, so they belong before the freeze rather than after.
Types
One of the process's three standard streams.
Variants
| Variant | Fields | Description |
|---|---|---|
Stdin | ||
Stdout | ||
Stderr |
Terminal dimensions in character cells.
Fields
| Name | Type | Description |
|---|---|---|
columns | usize | Width in columns. |
rows | usize | Height in rows. |
Functions
True when s is connected to a terminal (false for pipes, files and
redirections — including every yo test child, whose streams are pipes).
Parameters
| Name | Type | Notes |
|---|---|---|
s | Stream |
Returns: bool
True when it is reasonable to emit ANSI colors on s: the stream is a
terminal, NO_COLOR is unset (https://no-color.org — any value disables),
and TERM is not dumb.
Parameters
| Name | Type | Notes |
|---|---|---|
s | Stream |
Returns: bool
Put the terminal for s into RAW mode (no echo, byte-at-a-time input).
Throws IoError when s is not a terminal or the mode change fails.
ALWAYS pair with restore_mode() — a process exiting in raw mode leaves
the user's shell unreadable.
Parameters
| Name | Type | Notes |
|---|---|---|
s | Stream | |
exn | Exception |
Returns: unit
Restore the terminal mode saved by the first enter_raw_mode call.
Safe to call when raw mode was never entered.
Returns: unit