num_colors: Number of colors the terminal supports

Description Usage Arguments Details Value Examples

Description

Number of colors the terminal supports

Usage

1
num_colors(forget = FALSE)

Arguments

forget

Whether to forget the cached result of the color check.

Details

If the crayon.colors option is set, then we just use that. It should be an integer number. You can use this option as a workaround if crayon does not detect the number of colors accurately.

In Emacs, we report eight colors.

Otherwise, we use the tput shell command to detect the number of colors. If tput is not available, but we think that the terminal supports colors, then eigth colors are assumed.

If tput returns 8, but TERM is xterm, we return 256, as most xterm compatible terminals in fact do support 256 colors. There is some discussion about this here: https://github.com/r-lib/crayon/issues/17

For efficiency, num_colors() caches its result. To re-check the number of colors, set the forget argument to TRUE. The cached value is only used if no sinks are active, see also has_color() for more information about sinks.

Value

Numeric scalar, the number of colors the terminal supports.

Examples

1

Example output

[1] 1

crayon documentation built on May 2, 2019, 8:16 a.m.