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.
相关推荐
LDR0068 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术8 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
码云数智-园园8 天前
C++20 Modules 模块详解
java·开发语言·spring
swordbob8 天前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
源分享8 天前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm
Luminous.8 天前
C语言--day30
c语言·开发语言
何以解忧,唯有..8 天前
Go语言循环语句详解:for、range与循环控制
开发语言·算法·golang
謓泽8 天前
C语言不是语法,是通往机器的地图。
c语言·开发语言
云水一下8 天前
从零开始学 PHP 系列(一):PHP 的前世今生与开发环境搭建
开发语言·php
飞天狗1118 天前
零基础JavaWeb入门——第五课第二小节:九大内置对象 · 第2个:response(响应对象)
java·开发语言