This is the color-aware counterpart of
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_substring(text, first, last = 1000000L)
Character vector, potentially ANSI styled, or a vector to
coarced to character. It is recycled to the longest of
Starting index or indices, recycled to match the length
Ending index or indices, recycled to match the length
Character vector of the same length as
the requested substrings. ANSI styles are retained.
#> red default greencat(ansi_substring(str, 1, 5), "\n")#> red dcat(ansi_substring(str, 1, 15), "\n")#> red default grecat(ansi_substring(str, 3, 7), "\n")#> d def#>  "red d"#>  "red default gre"#>  "d def"#> another multi-style text#> other #> her multi-styl#>  "other" "her multi-styl"