tty-supports-ansicolor? ( -- ? )
Formatted TTY Output

Prev:with-256color ( -- * )
Next:tty-supports-256color? ( -- ? )


Vocabulary
terminfo

Inputs
None

Outputs
?a boolean


Word description
Outputs t if the current terminal (based on $TERM) supports ANSI 8-color output. This uses a predefined palette, containing black, red, green, yellow/brown, blue, magenta, cyan, and white, typically at about 70% of full brightness, which can be used for both foreground and background.

If $NO_COLOR is set, unconditionally returns f regardless of the terminal's underlying capabilities.

While this is nominally an 8-colour mode, support for ANSI colour often comes with support for an additional 8-16 colors:
The "AIXterm colours" are an additional eight-colour palette, traditionally containing lighter versions of the ANSI colours. These can be used for both foreground and background.
Using dim text in conjunction with ANSI colours (see tty-supports-dim?) will produce darker colours. This can only be used to affect the foreground colour.

It is almost universally the case in modern terminals that ANSI colours are selected with SGR values 30-37 (foreground) and 40-47 (background), and AIXterm colours, if available, with 90-97 and 100-107. The corresponding terminfo capabilities are "set_a_foreground" and "set_a_background".

Caveats
The palette contents are not standardized across terminal emulators; furthermore, most terminal emulators allow these colours to be configured by the user and/or remapped at runtime by software. Thus, while you can be mostly confident that (e.g.) colour 2 is green, figuring out which green is difficult.

Dim text is sometimes created on the fly by reducing the foreground lightness, and is sometimes a separate palette. In the latter case, combining dim text with AIXterm colours or other colour modes may not work at all, or may not do what you expect.

Some terminals render bold text with increased lightness in addition to, or instead of, increased font weight. In some cases (e.g. Konsole) this is user-configurable.

See also
tty-supports-attributes?, tty-supports-256color?, tty-supports-rgbcolor?, Terminfo Databases

Definition