The crayon package comes with predefined styles (see
styles()
for a list) and functions for the basic eight-color
ANSI standard (red
, blue
, etc., see crayon).
There are no predefined styles or style functions for the 256 color
ANSI mode, however, because we simply did not want to create that
many styles and functions. Instead, make_style()
can be
used to create a style (or a style function, or both).
There are two ways to use this function:
If its first argument is not named, then it returns a function
that can be used to color strings.
If its first argument is named, then it also creates a
style with the given name. This style can be used in
style()
. One can still use the return value
of the function, to create a style function.
The style (the ...
argument) can be anything of the
following:
An R color name, see 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 col2rgb
(in the base
grDevices package).
make_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 the examples below.