Package cli version 3.6.0
Description
这是base::strsplit()的彩色版本。它的工作方式与原版几乎一样,只不过保留了子字符串的色彩。
Usage
R
ansi_strsplit(x, split, ...)
Argument
参数【x】:字符向量,可能是ANSI样式的,或者是强制转换为字符的向量。
参数【split】:长度为1的字符向量(或可以强制为1的对象)包含用于分割的正则表达式(除非fixed = TRUE)。如果出现空匹配,特别是如果split包含零个字符,则将x拆分为单个字符。
参数【...】:额外的参数传递给base::strsplit()。
Value
与参数【x】长度相同的列表,其中第i个元素包含参数【x】的分割向量[i]。ANSI样式被保留。
Examples
R
str <- paste0(
col_red("I am red---"),
col_green("and I am green-"),
style_underline("I underlined")
)
I am red---and I am green-I underlined
R
cat(ansi_strsplit(str, "[-]+")[[1]], sep = "\n")
I am red
and I am green
I underlined
R
strsplit(ansi_strip(str), "[-]+")
[[1]]
[1] "I am red" "and I am green" "I underlined"
R
cat(ansi_strsplit(str, "")[[1]], "\n", sep = " ")
I a m r e d - - - a n d I a m g r e e n - I u n d e r l i n e d
R
strsplit(ansi_strip(str), "")
[[1]]
[1] "I" " " "a" "m" " " "r" "e" "d" "-" "-" "-" "a" "n" "d" " " "I" " " "a" "m" " " "g" "r" "e" "e" "n" "-" "I" " " "u" "n"
[31] "d" "e" "r" "l" "i" "n" "e" "d"