Skip to contents

Function factories used to generate new formatting functions for use in highlight(), highlighter(), and friends.

Usage

background(x)

bg(x)

color(x)

colour(x)

style(x)

wrap(left = "[", right = "]")

label(string, left = "[", right = "]")

Arguments

x

[character(1)]

For background() and color(), the color that the output function applies to the text background or text of a character vector, specified by a:

  • recognized R color name (see grDevices::colors())

  • cli package color (e.g. "yellow", "br_blue")

  • 6- or 8-digit hexadecimal color string (e.g. "#ff0000")

For style, the text effect that the output function adds to the text of a character vector, specified by a cli package style (e.g. "bold", "italic", "underline").

See cli::style_bold() and friends for recognized cli styles and colors.

left, right

[character(1)]

For wrap(), label() a prefix (left) or suffix right that the output function pastes onto a character vector. By default, left is "[" and right is "]".

string

[character(1)]

For label, the label (as a word) that the output function pastes onto a character vector.

Value

A function which returns a styled character or ANSI string vector.

Examples

color_red <- color("red")
color_red(1:3)
#> <cli_ansi_string>
#> [1] 1
#> [2] 2
#> [3] 3

background_yellow <- background("yellow")
background_yellow(LETTERS[1:3])
#> <cli_ansi_string>
#> [1] A
#> [2] B
#> [3] C

style_bold <- style("bold")
style_bold(c(TRUE, FALSE, NA))
#> <cli_ansi_string>
#> [1] TRUE 
#> [2] FALSE
#> [3] NA   

embrace <- wrap("(", ")")
embrace(c(2.2, 3.3, 4.4))
#> [1] "(2.2)" "(3.3)" "(4.4)"

yes <- label("Yes")
yes(1)
#> [1] "1 [Yes]"