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.
相关推荐
郑州光合科技余经理9 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo1239 天前
matlab画图工具
开发语言·matlab
dustcell.9 天前
haproxy七层代理
java·开发语言·前端
norlan_jame9 天前
C-PHY与D-PHY差异
c语言·开发语言
多恩Stone9 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
QQ4022054969 天前
Python+django+vue3预制菜半成品配菜平台
开发语言·python·django
遥遥江上月9 天前
Node.js + Stagehand + Python 部署
开发语言·python·node.js
m0_531237179 天前
C语言-数组练习进阶
c语言·开发语言·算法
Railshiqian9 天前
给android源码下的模拟器添加两个后排屏的修改
android·开发语言·javascript
雪人不是菜鸡9 天前
简单工厂模式
开发语言·算法·c#