chr.color {misty} | R Documentation |
Colored and Styled Terminal Output Text
Description
This function adds color and style to output texts on terminals that support
'ANSI' color and highlight codes that can be printed by using the cat
function.
Usage
chr.color(x, color = c("black", "red", "green", "yellow", "blue", "violet",
"cyan", "white", "gray1", "gray2", "gray3",
"b.red", "b.green", "b.yellow", "b.blue", "b.violet",
"b.cyan", "b.white"),
bg = c("none", "black", "red", "green", "yellow", "blue", "violet",
"cyan", "white"),
style = c("regular", "bold", "italic", "underline"), check = TRUE)
Arguments
x |
a character vector. |
color |
a character string indicating the text color, e.g., |
bg |
a character string indicating the background color of the text,
e.g., |
style |
a character vector indicating the font style, i.e., |
check |
logical: if |
Value
Returns a character vector.
Note
This function is based on functions provided in the crayon package by Gábor Csárdi.
Author(s)
Takuya Yanagida
References
Csárdi G (2022). crayon: Colored Terminal Output. R package version 1.5.2, https://CRAN.R-project.org/package=crayon
See Also
chr.grep
, chr.grepl
, chr.gsub
,
chr.omit
, chr.trim
, chr.trunc
Examples
## Not run:
# Example 1:
cat(chr.color("Text in red.", color = "red"))
# Example 2:
cat(chr.color("Text in blue with green background.",
color = "blue", bg = "yellow"))
# Example 3a:
cat(chr.color("Text in boldface.", style = "bold"))
# Example 3b:
cat(chr.color("Text in boldface and italic.", style = c("bold", "italic")))
## End(Not run)