has_ctl
checks for any Control Sequence. You can check for different
types of sequences with the ctl
parameter. Warnings are only emitted for
malformed CSI or OSC sequences.
has_ctl(x, ctl = "all", warn = getOption("fansi.warn", TRUE), which)
logical of same length as x
; NA values in x
result in NA values
in return
a character vector or object that can be coerced to such.
character, which Control Sequences should be treated
specially. Special treatment is context dependent, and may include
detecting them and/or computing their display/character width as zero. For
the SGR subset of the ANSI CSI sequences, and OSC hyperlinks, fansi
will also parse, interpret, and reapply the sequences as needed. You can
modify whether a Control Sequence is treated specially with the ctl
parameter.
"nl": newlines.
"c0": all other "C0" control characters (i.e. 0x01-0x1f, 0x7F), except for newlines and the actual ESC (0x1B) character.
"sgr": ANSI CSI SGR sequences.
"csi": all non-SGR ANSI CSI sequences.
"url": OSC hyperlinks
"osc": all non-OSC-hyperlink OSC sequences.
"esc": all other escape sequences.
"all": all of the above, except when used in combination with any of the above, in which case it means "all but".
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
).
At most one warning will be issued per element in each input vector. Will
also warn about some badly encoded UTF-8 strings, but a lack of UTF-8
warnings is not a guarantee of correct encoding (use validUTF8
for
that).
character, deprecated in favor of ctl
.
?fansi
for details on how Control Sequences are
interpreted, particularly if you are getting unexpected results,
unhandled_ctl
for detecting bad control sequences.
has_ctl("hello world")
has_ctl("hello\nworld")
has_ctl("hello\nworld", "sgr")
has_ctl("hello\033[31mworld\033[m", "sgr")
Run the code above in your browser using DataLab