colorize {Rdistance} | R Documentation |
colorize - Add color to result if terminal accepts it
Description
Add ANSI color to a string using the
crayon
package, if the R environment accepts color.
This function is needed because of the need to determine whether
output can be colorized. This determination is left up to
crayon::has_color()
.
In addition, for Rdistance results, we want to only colorize
numbers, not the reporting units. Everything between the last set
of square brackets ([...]
) is NOT colorized.
Usage
colorize(STR, col = NULL, bg = NULL)
Arguments
STR |
The string to colorize. |
col |
A string specifying the desired foreground color.
This is passed straight to |
bg |
A string specifying the desired background color. Must be one of "bgBlack", "bgRed", "bgGreen", "bgYellow", "bgBlue" "bgMagenta", "bgCyan", or "bgWhite". By default, no background is applied. |
Value
If color is not allowed in the terminal, the input string is returned unperturbed. If color is allowed, the input string is returned with color and background ANSI code surrounding the initial part of the string from character 1 to the character before the [ in the last pair of [].
See Also
crayon::style