Skip to content

Commit 72b56a0

Browse files
committed
version 1.2.1
1 parent 5c8d737 commit 72b56a0

7 files changed

+163
-9
lines changed

DESCRIPTION

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: crayon
22
Title: Colored Terminal Output
3-
Version: 1.2.0
3+
Version: 1.2.1
44
Authors@R: person("Gabor", "Csardi", , "csardi.gabor@gmail.com", role = c("aut", "cre"))
55
Description: Colored terminal output on
66
terminals that support ANSI color and highlight codes.
@@ -19,8 +19,8 @@ Collate: 'ansi-256.r' 'combine.r' 'utils.r' 'string.r'
1919
Imports: memoise
2020
Suggests: testthat
2121
NeedsCompilation: no
22-
Packaged: 2015-04-08 17:15:06 UTC; gaborcsardi
22+
Packaged: 2015-05-17 12:43:03 UTC; gaborcsardi
2323
Author: Gabor Csardi [aut, cre]
2424
Maintainer: Gabor Csardi <csardi.gabor@gmail.com>
2525
Repository: CRAN
26-
Date/Publication: 2015-04-09 00:30:34
26+
Date/Publication: 2015-05-18 01:23:52

MD5

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
879f6ed36b313e263afe2a4c97f21dbf *DESCRIPTION
1+
e783f5b200f0237d33cafc952c472fac *DESCRIPTION
22
dd9b9a646c92126c8c99c14a7a11753a *LICENSE
33
7b7eb426cb2d8570ceb483d4f7369aad *NAMESPACE
44
543232857afba7f0d460a36fb950e85a *R/ansi-256.r
55
d91d95b5a9db91ec97b5b1c03a2eb01d *R/combine.r
66
722a272258c2dcc30ffe7ae958c7b7b7 *R/crayon-package.r
77
496af82e4a6310abb0dcb530c5cd728f *R/disposable.r
88
b501573c5d249cd7971bc2815deab815 *R/has_ansi.r
9-
1c18f5e38da550e9940b2590911d6df1 *R/has_color.r
9+
18933d549af527b5c4a90bf2bebd214b *R/has_color.r
1010
979d31d8df46eec80e6f35645464fbb8 *R/machinery.r
1111
d60aa06633288dddff27c30abbd93ae5 *R/print.r
1212
34e9b27d9d071a9b910510ff544bcfb1 *R/show.r
@@ -15,6 +15,10 @@ aa58827122f4e5028398684ae4860d65 *R/string_operations.r
1515
7733b7a4e19f8ac091c59a5d1308b637 *R/style-var.r
1616
7117857a16121744d8ab7e5bddfec9f9 *R/styles.r
1717
39205d785652c83f9ff70924b3152211 *R/utils.r
18+
175d390058b8a9b12995525725218cf4 *inst/ANSI-256-OSX.png
19+
5a18e3dc240c1f6cfffd6059c8de5345 *inst/ANSI-8-OSX.png
20+
232de648bf7331c128404b8f87dbb0c8 *inst/NEWS.md
21+
51454c415a280eee6802d63d9558ddf5 *inst/README.markdown
1822
8f114430b2ffc7cb56946a4b7e6f5ef3 *man/chr.Rd
1923
7dc3b9d87afa497694470d5ba5f784e4 *man/col_nchar.Rd
2024
f8d57a59e8cc2dd00fb79689216008a3 *man/col_strsplit.Rd

R/has_color.r

+3-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ num_colors <- function(forget = FALSE) {
7676

7777
i_num_colors <- memoise::memoise(function() {
7878
if (!has_color()) { return(1) }
79-
cols <- try(silent = TRUE,
80-
system("tput colors", intern = TRUE))
81-
if (inherits(cols, "try-error")) { return(8) }
82-
cols <- as.numeric(cols)
79+
cols <- suppressWarnings(try(silent = TRUE,
80+
as.numeric(system("tput colors", intern = TRUE))))
81+
if (inherits(cols, "try-error") || is.na(cols)) { return(8) }
8382
if (cols %in% c(0, 1)) { return(1) }
8483
cols
8584
})

inst/ANSI-256-OSX.png

457 KB
Loading

inst/ANSI-8-OSX.png

68.6 KB
Loading

inst/NEWS.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# 1.2.1
2+
3+
* Fix detecting number of colors when `tput` exists, but
4+
fails with an error and/or does not return anything useful.
5+
(@jimhester, #18, #19)
6+
7+
# 1.2.0
8+
9+
* Fix detection of number of colors, it was cached from
10+
installation time (#17).
11+
12+
* Color aware string operations. They are slow and experimental
13+
currently.
14+
15+
# 1.1.0
16+
17+
* `show_ansi_colors()` prints all supported colors on the screen.
18+
19+
* 256 colors, on terminals that support it.
20+
21+
* Disable colors on Windows, they are not supported in the default setup.
22+
23+
# 1.0.0
24+
25+
* First released version.

inst/README.markdown

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
2+
# Crayon - stylish terminal output in R
3+
4+
[![Linux Build Status](https://travis-ci.org/gaborcsardi/crayon.svg?branch=master)](https://travis-ci.org/gaborcsardi/crayon)
5+
[![Windows Build status](https://ci.appveyor.com/api/projects/status/github/gaborcsardi/crayon?svg=true)](https://ci.appveyor.com/project/gaborcsardi/crayon)
6+
[![](http://www.r-pkg.org/badges/version/crayon)](http://cran.rstudio.com/web/packages/crayon/index.html)
7+
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/crayon)](http://cran.r-project.org/web/packages/crayon/index.html)
8+
9+
With crayon it is easy to add color to terminal output, create styles
10+
for notes, warnings, errors; and combine styles.
11+
12+
ANSI color support is automatically detected and used. Crayon was largely
13+
inspired by [chalk](https://github.com/sindresorhus/chalk).
14+
15+
## Installation
16+
17+
```r
18+
devtools::install_github("gaborcsardi/crayon")
19+
library(crayon)
20+
```
21+
22+
## Styles
23+
24+
Crayon defines several styles, that can be combined. Each style in the list
25+
has a corresponding function with the same name.
26+
27+
### General styles
28+
29+
* `reset`
30+
* `bold`
31+
* `blurred` (usually called `dim`, renamed to avoid name clash)
32+
* `italic` (not widely supported)
33+
* `underline`
34+
* `inverse`
35+
* `hidden`
36+
* `strikethrough` (not widely supported)
37+
38+
### Text colors
39+
40+
* `black`
41+
* `red`
42+
* `green`
43+
* `yellow`
44+
* `blue`
45+
* `magenta`
46+
* `cyan`
47+
* `white`
48+
* `silver` (usually called `gray`, renamed to avoid name clash)
49+
50+
### Background colors
51+
52+
* `bgBlack`
53+
* `bgRed`
54+
* `bgGreen`
55+
* `bgYellow`
56+
* `bgBlue`
57+
* `bgMagenta`
58+
* `bgCyan`
59+
* `bgWhite`
60+
61+
### Screenshot on OSX
62+
63+
![](/inst/ANSI-8-OSX.png)
64+
65+
## Usage
66+
67+
The styling functions take any number of character vectors as arguments,
68+
and they concatenate and style them:
69+
70+
```r
71+
library(crayon)
72+
cat(blue("Hello", "world!\n"))
73+
```
74+
75+
Crayon defines the `%+%` string concatenation operator, to make it easy
76+
to assemble stings with different styles.
77+
78+
```r
79+
cat("... to highlight the " %+% red("search term") %+% " in a block of text\n")
80+
```
81+
82+
Styles can be combined using the `$` operator:
83+
84+
```r
85+
cat(yellow$bgMagenta$bold('Hello world!\n'))
86+
```
87+
88+
Styles can also be nested, and then inner style takes precedence:
89+
90+
```r
91+
cat(green(
92+
'I am a green line ' %+%
93+
blue$underline$bold('with a blue substring') %+%
94+
' that becomes green again!\n'
95+
))
96+
```
97+
98+
It is easy to define your own themes:
99+
100+
```r
101+
error <- red $ bold
102+
warn <- magenta $ underline
103+
note <- cyan
104+
cat(error("Error: subscript out of bounds!\n"))
105+
cat(warn("Warning: shorter argument was recycled.\n"))
106+
cat(note("Note: no such directory.\n"))
107+
```
108+
109+
## 256 colors
110+
111+
Most modern terminals support the ANSI standard for 256 colors,
112+
and you can define new styles that make use of them. The `make_style`
113+
function defines a new style. It can handle R's built in color names
114+
(see the output of `colors()`), and also RGB specifications, via the
115+
`rbg()` function. It automatically chooses the ANSI colors that
116+
are closest to the specified R and RGB colors, and it also has
117+
a fallback to terminals with 8 ANSI colors only.
118+
119+
```r
120+
ivory <- make_style("ivory")
121+
bgMaroon <- make_style("maroon", bg = TRUE)
122+
fancy <- combine_styles(ivory, bgMaroon)
123+
cat(fancy("This will have some fancy colors"), "\n")
124+
```
125+
126+
![](/inst/ANSI-256-OSX.png)

0 commit comments

Comments
 (0)