GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cli
  • FAQ
  • Reference
  • Building a Semantic CLI
  • From usethis::ui functions to cli
  • cli pluralization
  • Introduction to progress bars in cli
  • Advanced cli progress bars
  • cli color palettes
  • More articles...
  • Changelog

This view

  • Original page
  • New address

GeezerVison is showing cli.r-lib.org — Create a new ANSI style — make_ansi_style

Create a new ANSI style

Source: R/ansi.R
make_ansi_style.Rd

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.

Value

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

Details

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

  • A cli ANSI style function of class cli_ansi_style. This is returned as is, without looking at the other arguments.

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

  • A 6- or 8-digit hexadecimal 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_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.

See also

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

Examples

make_ansi_style("orange")
#> <cli_ansi_style>
#> Example output
make_ansi_style("#123456")
#> <cli_ansi_style>
#> Example output
make_ansi_style("orange", bg = TRUE)
#> <cli_ansi_style>
#> Example output

orange <- make_ansi_style("orange")
orange("foobar")
#> <cli_ansi_string>
#> [1] foobar
cat(orange("foobar"))
#> foobar
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.