Examples for 'cli::ansi_substr'


Substring(s) of an ANSI colored string

Aliases: ansi_substr

Keywords:

### ** Examples

str <- paste(
  col_red("red"),
  "default",
  col_green("green")
)

cat(str, "\n")
red default green 
cat(ansi_substr(str, 1, 5), "\n")
red d 
cat(ansi_substr(str, 1, 15), "\n")
red default gre 
cat(ansi_substr(str, 3, 7), "\n")
d def 
substr(ansi_strip(str), 1, 5)
[1] "red d"
substr(ansi_strip(str), 1, 15)
[1] "red default gre"
substr(ansi_strip(str), 3, 7)
[1] "d def"
str2 <- paste(
  "another",
  col_red("multi-", style_underline("style")),
  "text"
)

cat(str2, "\n")
another multi-style text 
cat(ansi_substr(c(str, str2), c(3,5), c(7, 18)), sep = "\n")
d def
her multi-styl
substr(ansi_strip(c(str, str2)), c(3,5), c(7, 18))
[1] "d def"          "her multi-styl"

[Package cli version 3.6.3 Index]