File: ansi_columns.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 (80 lines) | stat: -rw-r--r-- 3,200 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ansiex.R
\name{ansi_columns}
\alias{ansi_columns}
\title{Format a character vector in multiple columns}
\usage{
ansi_columns(
  text,
  width = console_width(),
  sep = " ",
  fill = c("rows", "cols"),
  max_cols = 4,
  align = c("left", "center", "right"),
  type = "width",
  ellipsis = symbol$ellipsis
)
}
\arguments{
\item{text}{Character vector to format. Each element will formatted
as a cell of a table.}

\item{width}{Width of the screen.}

\item{sep}{Separator between the columns. It may have ANSI styles.}

\item{fill}{Whether to fill the columns row-wise or column-wise.}

\item{max_cols}{Maximum number of columns to use. Will not use more,
even if there is space for it.}

\item{align}{Alignment within the columns.}

\item{type}{Passed to \code{\link[=ansi_nchar]{ansi_nchar()}} and \code{\link[=ansi_align]{ansi_align()}}. Most probably
you want the default, \code{"width"}.}

\item{ellipsis}{The string to append to truncated strings. Supply an
empty string if you don't want a marker.}
}
\value{
ANSI string vector.
}
\description{
This function helps with multi-column output of ANSI styles strings.
It works well together with \code{\link[=boxx]{boxx()}}, see the example below.
}
\details{
If a string does not fit into the specified \code{width}, it will be
truncated using \code{\link[=ansi_strtrim]{ansi_strtrim()}}.

\if{html}{\out{<div class="sourceCode r">}}\preformatted{fmt <- ansi_columns(
  paste(col_red("foo"), 1:10),
  width = 50,
  fill = "rows",
  max_cols=10,
  align = "center",
  sep = "   "
)
boxx(fmt, padding = c(0,1,0,1), header = col_cyan("Columns"))
}\if{html}{\out{</div>}}\if{html}{\out{
<div class="asciicast" style="color: #172431;font-family: 'Fira Code',Monaco,Consolas,Menlo,'Bitstream Vera Sans Mono','Powerline Symbols',monospace;line-height: 1.300000"><pre>
#> ┌ <span style="color: #2AA198;">Columns</span> ───────────────────────────────────────────┐                          
#> │  <span style="color: #DC322F;">foo</span> 1     <span style="color: #DC322F;">foo</span> 2     <span style="color: #DC322F;">foo</span> 3     <span style="color: #DC322F;">foo</span> 4     <span style="color: #DC322F;">foo</span> 5     │                          
#> │  <span style="color: #DC322F;">foo</span> 6     <span style="color: #DC322F;">foo</span> 7     <span style="color: #DC322F;">foo</span> 8     <span style="color: #DC322F;">foo</span> 9     <span style="color: #DC322F;">foo</span> 10    │                          
#> └────────────────────────────────────────────────────┘                          
</pre></div>
}}
}
\seealso{
Other ANSI string operations: 
\code{\link{ansi_align}()},
\code{\link{ansi_nchar}()},
\code{\link{ansi_strsplit}()},
\code{\link{ansi_strtrim}()},
\code{\link{ansi_strwrap}()},
\code{\link{ansi_substr}()},
\code{\link{ansi_substring}()},
\code{\link{ansi_toupper}()},
\code{\link{ansi_trimws}()}
}
\concept{ANSI string operations}