Description Usage Arguments Examples
This is the ANSI-aware version of the base::nchar()
function.
It simply drops all ANSI styles and calls base::nchar()
.
1 | ansi_nchar(x, ...)
|
x |
character vector, or a vector to be coerced to a character vector. Giving a factor is an error. |
... |
Extra arguments are passed to |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | str <- crayon::red("I am red")
# Has ANSI markup if your terminal supports it
str
# It prints in red if your terminal supports it
cat(str)
# But base::nchar() also counts the ANSI control characters,
# which is not what we want
nchar(str)
# ansi_nchar is better:
ansi_nchar(str)
# This is the same
nchar(crayon::strip_style(str))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.