Create a function that can be used to add ANSI styles to text. All arguments are passed to crayon::make_style(), but see the Details below.

make_ansi_style(..., bg = FALSE, grey = FALSE, colors = crayon::num_colors())

Arguments

... The style to create. See details and examples below. Whether the color applies to the background. Whether to specifically create a grey color. This flag is included, because ANSI 256 has a finer color scale for greys, then the usual 0:5 scale for red, green and blue components. It is only used for RGB color specifications (either numerically or via a hexa string), and it is ignored on eigth color ANSI terminals. Number of colors, detected automatically by default.

Value

A function that can be used to color (style) strings.

Details

The styles (elements of ...) can be any of the following:

• An R color name, see grDevices::colors().

• A 6- or 8-digit hexa color string, e.g. #ff0000 means red. Transparency (alpha channel) values are ignored.

• A one-column matrix with three rows for the red, green and blue channels, as returned by grDevices::col2rgb().

make_ansistyle() detects the number of colors to use automatically (this can be overridden using the colors argument). If the number of colors is less than 256 (detected or given), then it falls back to the color in the ANSI eight color mode that is closest to the specified (RGB or R) color.

Other ANSI styling: ansi-styles, combine_ansi_styles()
make_ansi_style("orange")#> <ansi_style>
#> [1] foobarcat(orange("foobar"))#> foobar