fansi (version 0.3.0)

strtrim_ctl: ANSI Control Sequence Aware Version of strtrim

Description

One difference with base::strtrim is that all C0 control characters such as newlines, carriage returns, etc., are treated as zero width.

Usage

strtrim_ctl(x, width, warn = getOption("fansi.warn"))

strtrim2_ctl(x, width, warn = getOption("fansi.warn"), tabs.as.spaces = getOption("fansi.tabs.as.spaces"), tab.stops = getOption("fansi.tab.stops"))

Arguments

x

a character vector, or an object which can be coerced to a character vector by as.character.

width

Positive integer values: recycled to the length of x.

warn

TRUE (default) or FALSE, whether to warn when potentially problematic Control Sequences are encountered. These could cause the assumptions fansi makes about how strings are rendered on your display to be incorrect, for example by moving the cursor (see fansi).

tabs.as.spaces

FALSE (default) or TRUE, whether to convert tabs to spaces. This can only be set to TRUE if strip.spaces is FALSE.

tab.stops

integer(1:n) indicating position of tab stops to use when converting tabs to spaces. If there are more tabs in a line than defined tab stops the last tab stop is re-used. For the purposes of applying tab stops, each input line is considered a line and the character count begins from the beginning of the input line.

Details

strtrim2_ctl adds the option of converting tabs to spaces before trimming. This is the only difference between strtrim_ctl and strtrim2_ctl.

See Also

fansi for details on how Control Sequences are interpreted, particularly if you are getting unexpected results. strwrap_ctl is used internally by this function.

Examples

Run this code
# NOT RUN {
strtrim_ctl("\033[42mHello world\033[m", 6)
# }

Run the code above in your browser using DataLab