Skip to content

This function is similar to base::strtrim(), but works correctly with ANSI styled strings. It also adds ... (or the corresponding Unicode character if Unicode characters are allowed) to the end of truncated strings.

Usage

ansi_strtrim(x, width = console_width(), ellipsis = symbol$ellipsis)

Arguments

x

Character vector of ANSI strings.

width

The width to truncate to.

ellipsis

The string to append to truncated strings. Supply an empty string if you don't want a marker.

Details

Note: ansi_strtrim() does not support NA values currently.

See also

Examples

text <- cli::col_red(cli:::lorem_ipsum())
ansi_strtrim(c(text, "foobar"), 40)
#> <cli_ansi_string>
#> [1] Culpa laboris laborum occaecat occaecat
#> [2] foobar