EVOLUTION-MANAGER
Edit File: strip_ctl.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Strip ANSI Control Sequences</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for strip_ctl {fansi}"><tr><td>strip_ctl {fansi}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Strip ANSI Control Sequences</h2> <h3>Description</h3> <p>Removes <em>Control Sequences</em> from strings. By default it will strip all known <em>Control Sequences</em>, including ANSI CSI sequences, two character sequences starting with ESC, and all C0 control characters, including newlines. You can fine tune this behavior with the <code>ctl</code> parameter. <code>strip_sgr</code> only strips ANSI CSI SGR sequences. </p> <h3>Usage</h3> <pre> strip_ctl(x, ctl = "all", warn = getOption("fansi.warn"), strip) strip_sgr(x, warn = getOption("fansi.warn")) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>a character vector or object that can be coerced to character.</p> </td></tr> <tr valign="top"><td><code>ctl</code></td> <td> <p>character, any combination of the following values (see details): </p> <ul> <li><p> "nl": strip newlines. </p> </li> <li><p> "c0": strip all other "C0" control characters (i.e. x01-x1f, x7F), except for newlines and the actual ESC character. </p> </li> <li><p> "sgr": strip ANSI CSI SGR sequences. </p> </li> <li><p> "csi": strip all non-SGR csi sequences. </p> </li> <li><p> "esc": strip all other escape sequences. </p> </li> <li><p> "all": all of the above, except when used in combination with any of the above, in which case it means "all but" (see details). </p> </li></ul> </td></tr> <tr valign="top"><td><code>warn</code></td> <td> <p>TRUE (default) or FALSE, whether to warn when potentially problematic <em>Control Sequences</em> are encountered. These could cause the assumptions <code>fansi</code> makes about how strings are rendered on your display to be incorrect, for example by moving the cursor (see <a href="fansi.html">fansi</a>).</p> </td></tr> <tr valign="top"><td><code>strip</code></td> <td> <p>character, deprecated in favor of <code>ctl</code>.</p> </td></tr> </table> <h3>Details</h3> <p>The <code>ctl</code> value contains the names of <strong>non-overlapping</strong> subsets of the known <em>Control Sequences</em> (e.g. "csi" does not contain "sgr", and "c0" does not contain newlines). The one exception is "all" which means strip every known sequence. If you combine "all" with any other option then everything <strong>but</strong> that option will be stripped. </p> <h3>Value</h3> <p>character vector of same length as x with ANSI escape sequences stripped </p> <h3>_ctl vs. _sgr</h3> <p>The <code>*_ctl</code> versions of the functions treat all <em>Control Sequences</em> specially by default. 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, <code>fansi</code> will also parse, interpret, and reapply the text styles they encode if needed. You can modify whether a <em>Control Sequence</em> is treated specially with the <code>ctl</code> parameter. You can exclude a type of <em>Control Sequence</em> from special treatment by combining "all" with that type of sequence (e.g. <code>ctl=c("all", "nl")</code> for special treatment of all <em>Control Sequences</em> <strong>but</strong> newlines). The <code>*_sgr</code> versions only treat ANSI CSI SGR sequences specially, and are equivalent to the <code>*_ctl</code> versions with the <code>ctl</code> parameter set to "sgr". </p> <h3>Note</h3> <p>Non-ASCII strings are converted to and returned in UTF-8 encoding. </p> <h3>See Also</h3> <p><a href="fansi.html">fansi</a> for details on how <em>Control Sequences</em> are interpreted, particularly if you are getting unexpected results. </p> <h3>Examples</h3> <pre> string <- "hello\033k\033[45p world\n\033[31mgoodbye\a moon" strip_ctl(string) strip_ctl(string, c("nl", "c0", "sgr", "csi", "esc")) # equivalently strip_ctl(string, "sgr") strip_ctl(string, c("c0", "esc")) ## everything but C0 controls, we need to specify "nl" ## in addition to "c0" since "nl" is not part of "c0" ## as far as the `strip` argument is concerned strip_ctl(string, c("all", "nl", "c0")) ## convenience function, same as `strip_ctl(ctl='sgr')` strip_sgr(string) </pre> <hr /><div style="text-align: center;">[Package <em>fansi</em> version 0.4.1 <a href="00Index.html">Index</a>]</div> </body></html>