Skip to contents

Align an ANSI colored string

Usage

col_align(
  text,
  width = getOption("width"),
  align = c("left", "center", "right"),
  type = "width"
)

Arguments

text

The character vector to align.

width

Width of the field to align in.

align

Whether to align "left", "center" or "right".

type

Passed on to col_nchar() and there to nchar()

Value

The aligned character vector.

See also

Other ANSI string operations: col_nchar(), col_strsplit(), col_substr(), col_substring()

Examples

col_align(red("foobar"), 20, "left")
#> [1] "\033[31mfoobar\033[39m              "
col_align(red("foobar"), 20, "center")
#> [1] "       \033[31mfoobar\033[39m       "
col_align(red("foobar"), 20, "right")
#> [1] "              \033[31mfoobar\033[39m"