make_ansi_style {cli}R Documentation

Create a new ANSI style

Description

Create a function that can be used to add ANSI styles to text.

Usage

make_ansi_style(..., bg = FALSE, grey = FALSE, colors = num_ansi_colors())

Arguments

...

The style to create. See details and examples below.

bg

Whether the color applies to the background.

grey

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 hexadecimal string), and it is ignored on eight color ANSI terminals.

colors

Number of colors, detected automatically by default.

Details

The ... style argument can be any of the following:

make_ansi_style() 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.

Value

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

See Also

Other ANSI styling: ansi-styles, combine_ansi_styles(), num_ansi_colors()

Examples

make_ansi_style("orange")
make_ansi_style("#123456")
make_ansi_style("orange", bg = TRUE)

orange <- make_ansi_style("orange")
orange("foobar")
cat(orange("foobar"))

[Package cli version 3.6.2 Index]