R语言【cli】——ansi_strwrap():将ANSI样式的字符串包装为一定的宽度

Package cli version 3.6.0


Description

这个函数类似于base::strwrap(),但它适用于ANSI样式的字符串,并且保持样式不变。


Usage

R 复制代码
ansi_strwrap(
  x,
  width = console_width(),
  indent = 0,
  exdent = 0,
  simplify = TRUE
)

Arguments

参数【x】:ANSI字符串。

参数【width】:换行到的宽度。

参数【indent】:每段第一行的缩进。

参数【exdent】:缩进每段后面的行。

参数【simplify】:是否在单个字符向量中返回所有包装的字符串,还是单独包装x的每个元素并返回一个列表。


Value

如果simplify为FALSE,则一个字符向量列表,每个字符向量都是ANSI字符串。否则为单个ANSI字符串向量。


Example

R 复制代码
text <- cli:::lorem_ipsum()
# Highlight some words, that start with 's'
rexp <- gregexpr("\\b([sS][a-zA-Z]+)\\b", text)
regmatches(text, rexp) <- lapply(regmatches(text, rexp), col_red)
cat(text)
复制代码
Est dolor voluptate culpa qui consequat irure Lorem proident ut elit occaecat et id. Eiusmod velit officia nostrud est minim ullamco incididunt elit nulla. Aliquip ex cillum et minim minim. Nulla irure aute ut magna nisi enim anim sunt elit. Sunt proident sit et aliquip anim tempor ex excepteur quis reprehenderit nulla ut.
R 复制代码
wrp <- ansi_strwrap(text, width = 40)
cat(wrp, sep = "\n")
复制代码
Est dolor voluptate culpa qui consequat
irure Lorem proident ut elit occaecat
et id. Eiusmod velit officia nostrud
est minim ullamco incididunt elit
nulla. Aliquip ex cillum et minim
minim. Nulla irure aute ut magna nisi
enim anim sunt elit. Sunt proident sit
et aliquip anim tempor ex excepteur
quis reprehenderit nulla ut.
相关推荐
墨客希4 分钟前
安装 awscli
开发语言
天天进步201529 分钟前
Python全栈项目:结合Puppeteer和AI模型操作浏览器
开发语言·人工智能·python
唐僧洗头爱飘柔952731 分钟前
【GORM(3)】Go的跨时代ORM框架!—— 数据库连接、配置参数;本文从0开始教会如何配置GORM的数据库
开发语言·数据库·后端·golang·gorm·orm框架·dsn
Jonathan Star41 分钟前
在 Go 语言中,模板字符串
开发语言·后端·golang
闲人编程1 小时前
用Python识别图片中的文字(Tesseract OCR)
开发语言·python·ocr·识图·codecapsule
程序员卷卷狗1 小时前
JVM 内存结构与 GC 调优全景图
java·开发语言·jvm
froginwe111 小时前
HTML 段落
开发语言
z20348315201 小时前
我与C++的故事
开发语言·c++·c++40周年
wuwu_q2 小时前
用通俗易懂 + Android 开发实战的方式讲解 Kotlin Flow 中的 filter 操作符
android·开发语言·kotlin
想唱rap2 小时前
Linux开发工具(4)
linux·运维·服务器·开发语言·算法