File: README.md

package info (click to toggle)
r-cran-cli 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,780 kB
  • sloc: sh: 13; makefile: 2
file content (392 lines) | stat: -rw-r--r-- 9,314 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
cli
================


> Helpers for Developing Command Line Interfaces

[![Linux Build Status](https://api.travis-ci.org/r-lib/cli.svg?branch=master)](https://travis-ci.org/r-lib/cli)
[![Windows Build status](https://ci.appveyor.com/api/projects/status/github/r-lib/cli?svg=true)](https://ci.appveyor.com/project/gaborcsardi/cli)
[![](http://www.r-pkg.org/badges/version/cli)](http://www.r-pkg.org/pkg/cli)
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/cli)](http://www.r-pkg.org/pkg/cli)
[![Coverage Status](https://img.shields.io/codecov/c/github/r-lib/cli/master.svg)](https://codecov.io/github/r-lib/cli?branch=master)

It integrates well with `crayon` for coloring the boxes or their content,
It can draw rules and boxes to make headers or footers in console output,
and tree structures. It includes a set of Unicode characters, with fallbacks
on systems that do not support them.

---

-   [Installation](#installation)
-   [Usage](#usage)
    -   [Unicode characters](#unicode-characters)
    -   [Spinners](#spinners)
    -   [Rules](#rules)
    -   [Boxes](#boxes)
    -   [Trees](#trees)
-   [License](#license)

---

# Installation

Install the stable version from CRAN:

``` r
install.packages("cli")
```

Install the development version from GitHub:

``` r
source("https://install-github.me/r-lib/cli")
```

# Usage

``` r
library(cli)
```

## Unicode characters

Inspired by (and mostly copied from) the
[figures](https://github.com/sindresorhus/figures) JavaScript project.

    #> ✔    tick                      ☐ checkbox_off           
    #> ✖    cross                     ⓧ checkbox_circle_on     
    #> ★    star                      Ⓘ checkbox_circle_off    
    #> ▇    square                    ❓ fancy_question_mark    
    #> ◻    square_small              ≠ neq                    
    #> ◼    square_small_filled       ≥ geq                    
    #> ◯    circle                    ≤ leq                    
    #> ◉    circle_filled             × times                  
    #> ◌    circle_dotted             ▔ upper_block_1          
    #> ◎    circle_double             ▀ upper_block_4          
    #> ⓞ    circle_circle             ▁ lower_block_1          
    #> ⓧ    circle_cross              ▂ lower_block_2          
    #> Ⓘ    circle_pipe               ▃ lower_block_3          
    #> ?⃝   circle_question_mark      ▄ lower_block_4          
    #> ●    bullet                    ▅ lower_block_5          
    #> ․    dot                       ▆ lower_block_6          
    #> ─    line                      ▇ lower_block_7          
    #> ═    double_line               █ lower_block_8          
    #> …    ellipsis                  █ full_block             
    #> …    continue                  ⁰ sup_0                  
    #> ❯    pointer                   ¹ sup_1                  
    #> ℹ    info                      ² sup_2                  
    #> ⚠    warning                   ³ sup_3                  
    #> ☰    menu                      ⁴ sup_4                  
    #> ☺    smiley                    ⁵ sup_5                  
    #> ෴    mustache                  ⁶ sup_6                  
    #> ♥    heart                     ⁷ sup_7                  
    #> ↑    arrow_up                  ⁸ sup_8                  
    #> ↓    arrow_down                ⁹ sup_9                  
    #> ←    arrow_left                ⁻ sup_minus              
    #> →    arrow_right               ⁺ sup_plus               
    #> ◉    radio_on                  ▶ play                   
    #> ◯    radio_off                 ■ stop                   
    #> ☒    checkbox_on               ● record

## Spinners

See `list_spinners()` and `get_spinner()`. From the awesome
[cli-spinners](https://github.com/sindresorhus/cli-spinners#readme)
project.

![](man/figures/spinners.gif)

## Rules

Simple rule

``` r
rule()
```

![](man/figures/rule-1.png)<!-- -->

Double rule

``` r
rule(line = 2)
```

![](man/figures/rule-double-1.png)<!-- -->

Bars

``` r
rule(line = "bar2")
```

![](man/figures/rule-bars-1.png)<!-- -->

``` r
rule(line = "bar5")
```

![](man/figures/rule-bars-2.png)<!-- -->

Left label

``` r
rule(left = "Results")
```

![](man/figures/rule-left-1.png)<!-- -->

Centered label

``` r
rule(center = " * RESULTS * ")
```

![](man/figures/rule-center-1.png)<!-- -->

Colored labels

``` r
rule(center = crayon::red(" * RESULTS * "))
```

![](man/figures/rule-color-label-1.png)<!-- -->

Colored label and line

``` r
rule(center = " * RESULTS * ", col = "red")
```

![](man/figures/rule-color-1.png)<!-- -->

Colored line

``` r
rule(center = " * RESULTS * ", line_col = "red")
```

![](man/figures/rule-color-line-1.png)<!-- -->

Custom line

``` r
rule(center = "TITLE", line = "~")
```

![](man/figures/rule-line-custom-1.png)<!-- -->

More custom line

``` r
rule(center = "TITLE", line = "~-", line_col = "blue")
```

![](man/figures/rule-line-custom-2-1.png)<!-- -->

Even more custom
line

``` r
rule(center = crayon::bgRed(" ", symbol$star, "TITLE", symbol$star, " "),
  line = "\u2582", line_col = "orange")
```

![](man/figures/rule-line-custom-3-1.png)<!-- -->

## Boxes

Default box

``` r
boxx("Hello there!")
```

![](man/figures/box-1.png)<!-- -->

Change border style

``` r
boxx("Hello there!", border_style = "double")
```

![](man/figures/box-border-style-1.png)<!-- -->

Multiple lines

``` r
boxx(c("Hello", "there!"), padding = 1)
```

![](man/figures/box-lines-1.png)<!-- -->

Padding

``` r
boxx("Hello there!", padding = 1)
```

![](man/figures/box-padding-1.png)<!-- -->

``` r
boxx("Hello there!", padding = c(1, 5, 1, 5))
```

![](man/figures/box-padding-2.png)<!-- -->

Margin

``` r
boxx("Hello there!", margin = 1)
```

![](man/figures/box-margin-1.png)<!-- -->

``` r
boxx("Hello there!", margin = c(1, 5, 1, 5))
```

![](man/figures/box-margin-2.png)<!-- -->

``` r
boxx("Hello there!", padding = 1, margin = c(1, 5, 1, 5))
```

![](man/figures/box-margin-3.png)<!-- -->

Floating

``` r
boxx("Hello there!", padding = 1, float = "center")
```

![](man/figures/box-floating-1.png)<!-- -->

``` r
boxx("Hello there!", padding = 1, float = "right")
```

![](man/figures/box-floating-2.png)<!-- -->

Text color

``` r
boxx(crayon::cyan("Hello there!"), padding = 1, float = "center")
```

![](man/figures/box-color-1.png)<!-- -->

Backgorund color

``` r
boxx("Hello there!", padding = 1, background_col = "brown")
```

![](man/figures/box-bgcolor-1.png)<!-- -->

``` r
boxx("Hello there!", padding = 1, background_col = crayon::bgRed)
```

![](man/figures/box-bgcolor-2.png)<!-- -->

Border color

``` r
boxx("Hello there!", padding = 1, border_col = "green")
```

![](man/figures/box-border-color-1.png)<!-- -->

``` r
boxx("Hello there!", padding = 1, border_col = crayon::red)
```

![](man/figures/box-border-color-2.png)<!-- -->

Label alignment

``` r
boxx(c("Hi", "there", "you!"), padding = 1, align = "left")
```

![](man/figures/box-label-align-1.png)<!-- -->

``` r
boxx(c("Hi", "there", "you!"), padding = 1, align = "center")
```

![](man/figures/box-label-align-2.png)<!-- -->

``` r
boxx(c("Hi", "there", "you!"), padding = 1, align = "right")
```

![](man/figures/box-label-align-3.png)<!-- -->

A very customized box

``` r
star <- symbol$star
label <- c(paste(star, "Hello", star), "  there!")
boxx(
  crayon::white(label),
  border_style="round",
  padding = 1,
  float = "center",
  border_col = "tomato3",
  background_col="darkolivegreen"
)
```

![](man/figures/box-customized-1.png)<!-- -->

## Trees

You can specify the tree with a two column data frame, containing the
node ids/labels, and the list of their children.

``` r
data <- data.frame(
  stringsAsFactors = FALSE,
  package = c("processx", "backports", "assertthat", "Matrix",
    "magrittr", "rprojroot", "clisymbols", "prettyunits", "withr",
    "desc", "igraph", "R6", "crayon", "debugme", "digest", "irlba",
    "rcmdcheck", "callr", "pkgconfig", "lattice"),
  dependencies = I(list(
    c("assertthat", "crayon", "debugme", "R6"), character(0),
    character(0), "lattice", character(0), "backports", character(0),
    c("magrittr", "assertthat"), character(0),
    c("assertthat", "R6", "crayon", "rprojroot"),
    c("irlba", "magrittr", "Matrix", "pkgconfig"), character(0),
    character(0), "crayon", character(0), "Matrix",
    c("callr", "clisymbols", "crayon", "desc", "digest", "prettyunits",
      "R6", "rprojroot", "withr"),
    c("processx", "R6"), character(0), character(0)
  ))
)
tree(data, root = "rcmdcheck")
```

![](man/figures/tree-1.png)<!-- -->

An optional third column may contain custom labels. These can be colored
as well:

``` r
data$label <- paste(data$package,
  crayon::blurred(paste0("(", c("2.0.0.1", "1.1.1", "0.2.0", "1.2-11",
    "1.5", "1.2", "1.2.0", "1.0.2", "2.0.0", "1.1.1.9000", "1.1.2",
    "2.2.2", "1.3.4", "1.0.2", "0.6.12", "2.2.1", "1.2.1.9002",
    "1.0.0.9000", "2.0.1", "0.20-35"), ")"))
  )
roots <- ! data$package %in% unlist(data$dependencies)
data$label[roots] <- crayon::cyan(crayon::italic(data$label[roots]))
tree(data, root = "rcmdcheck")
```

![](man/figures/tree-color-1.png)<!-- -->

# License

MIT © RStudio