This function is similar to base::trimws()
but works on ANSI strings,
and keeps color and other styling.
Usage
ansi_trimws(x, which = c("both", "left", "right"))
See also
Other ANSI string operations:
ansi_align()
,
ansi_columns()
,
ansi_nchar()
,
ansi_strsplit()
,
ansi_strtrim()
,
ansi_strwrap()
,
ansi_substring()
,
ansi_substr()
,
ansi_toupper()
Examples
trimws(paste0(" ", col_red("I am red"), " "))
#> [1] "\033[31mI am red\033[39m"
ansi_trimws(paste0(" ", col_red("I am red"), " "))
#> <cli_ansi_string>
#> [1] I am red
trimws(col_red(" I am red "))
#> <cli_ansi_string>
#> [1] I am red
ansi_trimws(col_red(" I am red "))
#> <cli_ansi_string>
#> [1] I am red