Expand description
How wide the terminal is, asked of the terminal itself.
A help page that wraps at 80 columns on a 200-column terminal is the most visible thing a
CLI can get wrong about its own output, and COLUMNS does not answer the question: no
POSIX shell exports it, so it is unset in almost every process that is not an interactive
shell’s own. The only answer is to ask the kernel — TIOCGWINSZ on unix, the console
screen buffer on Windows — which is two dozen lines of FFI vendored here rather than a
dependency, because this crate runs on every invocation of every CLI built on it and has
none.
This is the one place in the runtime that is allowed unsafe, which is why it is a module
of its own: the crate is deny(unsafe_code) and only this file opts out. Nothing here
dereferences a pointer the caller supplied or hands one out; each call fills a struct
this module owns and reads two integers back out of it.
A page is rendered by whichever implementation the CLI was built with, and all of them have
to reach the same width on the same terminal. usage-lib calls this module rather than
carrying a second copy of the FFI; Go’s argv.terminalColumns is the one twin, because it
cannot call this one.
Functions§
- columns
- The terminal’s width in columns, or
Nonewhen output is not a terminal.