fansi provides counterparts to the base string manipulation functions substr, 
strwrap, strtrim, strsplit, and n(z)char that account for ANSI CSI SGR control 
sequences.  ANSI CSI SGR control sequences [1] can be used to format text in 
terminals that support them.

For example the control sequence "\033[31m" causes text that follows to render 
in red, and the control sequence "\033[0m" turns off formatting.  So with:

> substr_ctl("\033[31mABC\033[0m", 2, 2)
[1] "\033[31mB\033[0m"

we extract the second letter of the red formatted ABC while retaining the 
formatting.

fansi is written mostly in C, so its performance is comparable to the 
corresponding base functions.  There are versions of some of the functions with 
additional functionality.  For example, `substr2_ctl` supports character-width 
(as opposed to character-count) based substrings.

fansi is dependency-less.

Feedback is welcome either by e-mail or via github 
(<https://github.com/brodieG/fansi>).


Brodie.

[1] 
<https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters>.

_______________________________________________
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to