chr.color: Colored and Styled Terminal Output Text

View source: R/chr.color.R

chr.colorR 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", "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)

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.

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

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)

misty documentation built on Oct. 24, 2024, 5:10 p.m.

Related to chr.color in misty...