ansi_align: Align an ANSI colored string

View source: R/ansiex.R

ansi_alignR Documentation

Align an ANSI colored string

Description

Align an ANSI colored string

Usage

ansi_align(
  text,
  width = console_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 ansi_nchar() and there to nchar()

Details

str <- c(
  col_red("This is red"),
  style_bold("This is bold")
)
astr <- ansi_align(str, width = 30)
boxx(astr)
#> ┌────────────────────────────────────┐                                          
#> │                                    │                                          
#> │   This is red                      │                                          
#> │   This is bold                     │                                          
#> │                                    │                                          
#> └────────────────────────────────────┘                                          
str <- c(
  col_red("This is red"),
  style_bold("This is bold")
)
astr <- ansi_align(str, align = "center", width = 30)
boxx(astr)
#> ┌────────────────────────────────────┐                                          
#> │                                    │                                          
#> │             This is red            │                                          
#> │            This is bold            │                                          
#> │                                    │                                          
#> └────────────────────────────────────┘                                          
str <- c(
  col_red("This is red"),
  style_bold("This is bold")
)
astr <- ansi_align(str, align = "right", width = 30)
boxx(astr)
#> ┌────────────────────────────────────┐                                          
#> │                                    │                                          
#> │                      This is red   │                                          
#> │                     This is bold   │                                          
#> │                                    │                                          
#> └────────────────────────────────────┘                                          

Value

The aligned character vector.

See Also

Other ANSI string operations: ansi_columns(), ansi_nchar(), ansi_strsplit(), ansi_strtrim(), ansi_strwrap(), ansi_substring(), ansi_substr(), ansi_toupper(), ansi_trimws()


cli documentation built on June 22, 2024, 10:57 a.m.