ansi_trimws {cli}R Documentation

Remove leading and/or trailing whitespace from an ANSI string

Description

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"))

Arguments

x

ANSI string vector.

which

Whether to remove leading or trailing whitespace or both.

Value

ANSI string, with the whitespace removed.

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"), "   "))
ansi_trimws(paste0("   ", col_red("I am red"), "   "))
trimws(col_red("   I am red   "))
ansi_trimws(col_red("   I am red   "))

[Package cli version 3.0.1 Index]