Learn R Programming

misty (version 0.6.7)

chr.color: 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", "gray", "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)

Value

Returns a character vector.

Arguments

x

a character vector.

color

a character string indicating the text color, e.g., red for red and b.red for bright red text.

bg

a character string indicating the background color of the text, e.g., red for red background.

style

a character vector indicating the font style, i.e., regular, (default) for regular text, bold for bold text, italic, for italic text, and underline for underline text. Note that font styles can be combined, e.g., style = c("bold", "italic") provides a bold and italic text.

check

logical: if TRUE (default), argument specification is checked.

Author

Takuya Yanagida

References

Csárdi G (2022). crayon: Colored Terminal Output. R package version 1.5.2, https://CRAN.R-project.org/package=crayon

Examples

Run this code
if (FALSE) {

# 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")))

}

Run the code above in your browser using DataLab