File: ansi_strwrap.Rd

package info (click to toggle)
r-cran-cli 3.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,288 kB
  • sloc: ansic: 16,412; cpp: 37; sh: 13; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,553 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ansiex.R
\name{ansi_strwrap}
\alias{ansi_strwrap}
\title{Wrap an ANSI styled string to a certain width}
\usage{
ansi_strwrap(
  x,
  width = console_width(),
  indent = 0,
  exdent = 0,
  simplify = TRUE
)
}
\arguments{
\item{x}{ANSI string.}

\item{width}{Width to wrap to.}

\item{indent}{Indentation of the first line of each paragraph.}

\item{exdent}{Indentation of the subsequent lines of each paragraph.}

\item{simplify}{Whether to return all wrapped strings in a single
character vector, or wrap each element of \code{x} independently and return
a list.}
}
\value{
If \code{simplify} is \code{FALSE}, then a list of character vectors,
each an ANSI string. Otherwise a single ANSI string vector.
}
\description{
This function is similar to \code{\link[base:strwrap]{base::strwrap()}}, but works on ANSI
styled strings, and leaves the styling intact.
}
\examples{
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)

wrp <- ansi_strwrap(text, width = 40)
cat(wrp, sep = "\n")
}
\seealso{
Other ANSI string operations: 
\code{\link{ansi_align}()},
\code{\link{ansi_columns}()},
\code{\link{ansi_nchar}()},
\code{\link{ansi_strsplit}()},
\code{\link{ansi_strtrim}()},
\code{\link{ansi_substr}()},
\code{\link{ansi_substring}()},
\code{\link{ansi_toupper}()},
\code{\link{ansi_trimws}()}
}
\concept{ANSI string operations}