forked from r-lib/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
200 lines (155 loc) · 4.27 KB
/
README.Rmd
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
---
title: cli
output:
md_document:
variant: markdown_github
always_allow_html: yes
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE, cache = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README",
out.width = "100%",
cache = TRUE
)
Sys.setenv(CLI_TICK_TIME = "100")
# Turn on ANSI colors
options(cli.num_colors = 256L)
asciicast::init_knitr_engine(
startup = quote({
library(cli)
set.seed(1) }),
echo = TRUE,
echo_input = FALSE,
options = list(
asciicast_end_wait = 3
)
)
```
# cli
> Helpers for Developing Command Line Interfaces
<!-- badges: start -->
[![R build status](https://github.com/r-lib/cli/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/cli/actions)
[![](https://www.r-pkg.org/badges/version/cli)](https://www.r-pkg.org/pkg/cli)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/cli)](https://www.r-pkg.org/pkg/cli)
[![Coverage Status](https://img.shields.io/codecov/c/github/r-lib/cli/main.svg)](https://codecov.io/github/r-lib/cli?branch=main)
<!-- badges: end -->
A suite of tools to build attractive command line interfaces
(CLIs), from semantic elements: headers, lists, alerts, paragraphs,
etc. Supports theming via a CSS-like language. It also contains a
number of lower level CLI elements: rules, boxes, trees, and
Unicode symbols with ASCII alternatives. It supports ANSI markup
for terminal colors and font styles.
---
# Features
* Build a CLI using semantic elements: headings, lists, alerts, paragraphs.
* Theming via a CSS-like language.
* Terminal colors and font styles.
* All cli text can contain interpreted string literals, via the
[glue](https://github.com/tidyverse/glue) package.
* Progress bars from R and C code.
* Error and warning messages with rich text formatting.
* Support for pluralized messages.
* ANSI styled string manipulation.
# Installation
Install the stable version from CRAN:
```r
install.packages("cli")
```
## Short tour
Some of the more commonly used cli elements, and features.
### Short alert messages
One liner messages to inform or warn.
```{asciicast alert-success}
pkgs <- c("foo", "bar", "foobar")
cli_alert_success("Downloaded {length(pkgs)} packages.")
```
```{asciicast alert-info}
db_url <- "example.com:port"
cli_alert_info("Reopened database {.url {db_url}}.")
```
```{asciicast alert-warning}
cli_alert_warning("Cannot reach GitHub, using local database cache.")
```
```{asciicast alert-danger}
cli_alert_danger("Failed to connect to database.")
```
```{asciicast alert}
cli_alert("A generic alert")
```
### Headings
Three levels of headings.
```{asciicast h1}
cli_h1("Heading 1")
```
```{asciicast h2}
cli_h2("Heading 2")
```
```{asciicast h3}
cli_h3("Heading 3")
```
### Lists
Ordered, unordered and description lists, that can be nested.
```{asciicast lists}
fun <- function() {
cli_ol()
cli_li("Item 1")
ulid <- cli_ul()
cli_li("Subitem 1")
cli_li("Subitem 2")
cli_end(ulid)
cli_li("Item 2")
cli_end()
}
fun()
```
### Themes
Theming via a CSS-like language.
```{asciicast themes}
fun <- function() {
cli_div(theme = list(span.emph = list(color = "orange")))
cli_text("This is very {.emph important}")
cli_end()
cli_text("Back to the {.emph previous theme}")
}
fun()
```
### Command substitution
Automatic command substitution via the
[glue](https://github.com/tidyverse/glue) package.
```{asciicast glue}
size <- 123143123
dt <- 1.3454
cli_alert_info(c(
"Downloaded {prettyunits::pretty_bytes(size)} in ",
"{prettyunits::pretty_sec(dt)}"))
```
### Pluralization
Pluralization support.
```{asciicast plurals}
nfiles <- 3
ndirs <- 1
cli_alert_info("Found {nfiles} file{?s} and {ndirs} director{?y/ies}.")
```
### Progress bars
```{asciicast progress-setup, include = FALSE, cache = FALSE}
options(cli.progress_show_after = 0)
options(cli.progress_clear = FALSE)
```
```{asciicast progress, R.options = list(asciicast_at = NULL)}
clean <- function() {
cli_progress_bar("Cleaning data", total = 100)
for (i in 1:100) {
Sys.sleep(5/100)
cli_progress_update()
}
}
clean()
```
## Documentation
See at [`https://cli.r-lib.org/`](https://cli.r-lib.org/reference/index.html)
and also in the installed package: `help(package = "cli")`.
# License
MIT © RStudio