term
term provides the small terminal-focused building blocks shared by zigcli packages and
programs.
Use it when you want reusable ANSI styling, a shared color type, or lightweight terminal capability checks without pulling table rendering into your own code.
Features
Style.Colordefines the standard ANSI foreground/background colors, including bright variantsStylecombines bold, italic, foreground color, and background color into one reusable valueisTty(file)reports whether a file is attached to an interactive terminalterminalWidth(file)returns the terminal width when it can be detected, otherwisenullstdoutWidth()is a convenience wrapper for the common stdout case
Usage
| |
Style.Color
Style.Color is the shared ANSI color enum used by pretty-table cell styling and by any program
that wants plain colored output.
Available colors:
black,red,green,yellowblue,magenta,cyan,white- bright variants such as
bright_redandbright_cyan
Useful helpers:
toEscapeCode(): foreground color escape sequencetoBgEscapeCode(): background color escape sequencewriteString(writer, text): write colored text and reset afterwardreset: the ANSI reset sequence
| |
Style
Style groups multiple text attributes into one value:
bolditalicfg: ?Style.Colorbg: ?Style.Color
Useful helpers:
isPlain(): whether the style would emit any ANSI escape sequenceswritePrefix(writer): emit only the leading ANSI sequence(s)writeSuffix(writer): emit the trailing reset when neededwriteString(writer, text): wrap the text with the full style
| |
Terminal capability helpers
isTty(file)
Use isTty() when color or formatting should only be enabled for interactive terminals.
| |
terminalWidth(file)
terminalWidth() returns ?u16. It yields null when width detection is unavailable, including
non-terminal files and platforms where the current implementation does not probe terminal size.
| |
This makes it easy to keep behavior-safe fallbacks in callers such as table renderers.
stdoutWidth()
Use stdoutWidth() when stdout is the intended output stream and you do not need to choose a
different file handle explicitly.
| |