This is a color-aware counterpart of base::substr()
.
It works exactly like the original, but keeps the colors
in the substrings. The ANSI escape sequences are ignored when
calculating the positions within the string.
ansi_substr(x, start, stop)
x | Character vector, potentially ANSI styled, or a vector to coarced to character. |
---|---|
start | Starting index or indices, recycled to match the length
of |
stop | Ending index or indices, recycled to match the length
of |
Character vector of the same length as x
, containing
the requested substrings. ANSI styles are retained.
Other ANSI string operations:
ansi_align()
,
ansi_nchar()
,
ansi_strsplit()
,
ansi_substring()
#> red default green#> red d#> red default gre#> d def#> [1] "red d"#> [1] "red default gre"#> [1] "d def"#> another multi-style text#> d def #> her multi-styl#> [1] "d def" "her multi-styl"