VocabularyterminfoInputsNone
OutputsWord descriptionOutputs
t if the current terminal (based on
$TERM and
$COLORTERM) supports RGB color output, aka "direct colour". On modern terminals this is typically an 8-bit-per-channel RGB mode which either displays the colour as given, or automatically maps it to the perceptually closest colour available in an internal palette.
If
$NO_COLOR is set, unconditionally returns
f regardless of the terminal's underlying capabilities.
In principle, foreground colour is selected using the sequence
SGR 38:2:0:r:g:b, and background colour with
SGR 48:2:0:r:g:b, where
r:g:b are the channel values in the range 0-255. In practice, there is some disagreement about this; see below.
CaveatsAutodetection of RGB support is a hot mess and false negatives are common. In particular,
$COLORTERM is not usually propagated across ssh connections unless the user takes extra steps to do so, and while
$TERM is, many terminfo files do not properly report RGB support.
Like 256 colour mode (see
tty-supports-256color?), there is disagreement across terminals on whether to use
: or
; as the argument separator. Additionally, the always-zero second argument is mandatory in some terminals, optional in others, and some may reject it entirely. The standard uses
: and requires the zero (which is nominally a colourspace ID, and in practice, ignored), and following that format will give you the best out-of-the-box compatibility. For maximum portability, however, you must consult the
"set_a_foreground" and
"set_a_background" terminfo capabilities.
See alsotty-supports-attributes?,
tty-supports-ansicolor?,
tty-supports-256color?,
Terminfo DatabasesDefinition