• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

R/H26-Oct-2021-2,2421,100

man/H26-Oct-2021-1,000897

tests/H08-Feb-2021-618476

tools/H03-May-2022-

DESCRIPTIONH A D29-Oct-20211.4 KiB3635

LICENSEH A D13-Sep-201747 32

MD5H A D29-Oct-20213.2 KiB6362

NAMESPACEH A D26-Oct-20211.2 KiB6664

NEWS.mdH A D26-Oct-20212.7 KiB11365

README.mdH A D28-Jan-20213.6 KiB143106

README.md

1
2<h1 align="center">
3    <br>
4    <br>
5    <img width="400" src="https://user-images.githubusercontent.com/660288/102484487-41cd2900-405e-11eb-87d4-65793ad9db6a.png" alt="crayon">
6    <br>
7    <br>
8    <br>
9</h1>
10
11> Stylish terminal output in R
12
13<!-- badges: start -->
14
15[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/)
16[![R build status](https://github.com/r-lib/crayon/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/crayon/actions)
17[![](https://www.r-pkg.org/badges/version/crayon)](https://r-pkg.org/pkg/crayon)
18[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/crayon)](https://r-pkg.org/pkg/crayon)
19[![Coverage Status](https://img.shields.io/codecov/c/github/r-lib/crayon/master.svg)](https://codecov.io/github/r-lib/crayon?branch=master)
20
21<!-- badges: end -->
22
23With crayon it is easy to add color to terminal output, create styles for notes, warnings, errors; and combine styles.
24
25ANSI color support is automatically detected and used. Crayon was largely
26inspired by [chalk](https://github.com/chalk/chalk).
27
28## Installation
29
30```r
31install.packages("crayon")
32```
33
34## Styles
35
36Crayon defines several styles that can be combined. Each style in the list
37has a corresponding function with the same name.
38
39### General styles
40
41* `reset`
42* `bold`
43* `blurred` (usually called `dim`, renamed to avoid name clash)
44* `italic` (not widely supported)
45* `underline`
46* `inverse`
47* `hidden`
48* `strikethrough` (not widely supported)
49
50### Text colors
51
52* `black`
53* `red`
54* `green`
55* `yellow`
56* `blue`
57* `magenta`
58* `cyan`
59* `white`
60* `silver` (usually called `gray`, renamed to avoid name clash)
61
62### Background colors
63
64* `bgBlack`
65* `bgRed`
66* `bgGreen`
67* `bgYellow`
68* `bgBlue`
69* `bgMagenta`
70* `bgCyan`
71* `bgWhite`
72
73### Screenshot on OSX
74
75![](https://user-images.githubusercontent.com/660288/102484516-4d205480-405e-11eb-93fa-37a6cd6d4066.png)
76
77## Usage
78
79The styling functions take any number of character vectors as arguments,
80and they concatenate and style them:
81
82```r
83library(crayon)
84cat(blue("Hello", "world!\n"))
85```
86
87Crayon defines the `%+%` string concatenation operator to make it easy
88to assemble strings with different styles.
89
90```r
91cat("... to highlight the " %+% red("search term") %+% " in a block of text\n")
92```
93
94Styles can be combined using the `$` operator:
95
96```r
97cat(yellow$bgMagenta$bold('Hello world!\n'))
98```
99
100Styles can also be nested, and then inner style takes precedence:
101
102```r
103cat(green(
104  'I am a green line ' %+%
105  blue$underline$bold('with a blue substring') %+%
106  ' that becomes green again!\n'
107))
108```
109
110It is easy to define your own themes:
111
112```r
113error <- red $ bold
114warn <- magenta $ underline
115note <- cyan
116cat(error("Error: subscript out of bounds!\n"))
117cat(warn("Warning: shorter argument was recycled.\n"))
118cat(note("Note: no such directory.\n"))
119```
120
121## 256 colors
122
123Most modern terminals support the ANSI standard for 256 colors,
124and you can define new styles that make use of them. The `make_style`
125function defines a new style. It can handle R's built in color names
126(see the output of `colors()`) as well as RGB specifications via the
127`rgb()` function. It automatically chooses the ANSI colors that
128are closest to the specified R and RGB colors, and it also has
129a fallback to terminals with 8 ANSI colors only.
130
131```r
132ivory <- make_style("ivory")
133bgMaroon <- make_style("maroon", bg = TRUE)
134fancy <- combine_styles(ivory, bgMaroon)
135cat(fancy("This will have some fancy colors"), "\n")
136```
137
138![](https://user-images.githubusercontent.com/660288/102484539-53aecc00-405e-11eb-9f24-85b4c10b5e38.png)
139
140## License
141
142MIT @ Gábor Csárdi
143