Permalink
Browse files

version 1.2.1

  • Loading branch information...
gaborcsardi committed May 17, 2015
1 parent 5c8d737 commit 72b56a09cd4cbc787eb90a31d88f736d280af8b5
Showing with 163 additions and 9 deletions.
  1. +3 −3 DESCRIPTION
  2. +6 −2 MD5
  3. +3 −4 R/has_color.r
  4. BIN inst/ANSI-256-OSX.png
  5. BIN inst/ANSI-8-OSX.png
  6. +25 −0 inst/NEWS.md
  7. +126 −0 inst/README.markdown
@@ -1,6 +1,6 @@
Package: crayon
Title: Colored Terminal Output
Version: 1.2.0
Version: 1.2.1
Authors@R: person("Gabor", "Csardi", , "csardi.gabor@gmail.com", role = c("aut", "cre"))
Description: Colored terminal output on
terminals that support ANSI color and highlight codes.
@@ -19,8 +19,8 @@ Collate: 'ansi-256.r' 'combine.r' 'utils.r' 'string.r'
Imports: memoise
Suggests: testthat
NeedsCompilation: no
Packaged: 2015-04-08 17:15:06 UTC; gaborcsardi
Packaged: 2015-05-17 12:43:03 UTC; gaborcsardi
Author: Gabor Csardi [aut, cre]
Maintainer: Gabor Csardi <csardi.gabor@gmail.com>
Repository: CRAN
Date/Publication: 2015-04-09 00:30:34
Date/Publication: 2015-05-18 01:23:52
8 MD5
@@ -1,12 +1,12 @@
879f6ed36b313e263afe2a4c97f21dbf *DESCRIPTION
e783f5b200f0237d33cafc952c472fac *DESCRIPTION
dd9b9a646c92126c8c99c14a7a11753a *LICENSE
7b7eb426cb2d8570ceb483d4f7369aad *NAMESPACE
543232857afba7f0d460a36fb950e85a *R/ansi-256.r
d91d95b5a9db91ec97b5b1c03a2eb01d *R/combine.r
722a272258c2dcc30ffe7ae958c7b7b7 *R/crayon-package.r
496af82e4a6310abb0dcb530c5cd728f *R/disposable.r
b501573c5d249cd7971bc2815deab815 *R/has_ansi.r
1c18f5e38da550e9940b2590911d6df1 *R/has_color.r
18933d549af527b5c4a90bf2bebd214b *R/has_color.r
979d31d8df46eec80e6f35645464fbb8 *R/machinery.r
d60aa06633288dddff27c30abbd93ae5 *R/print.r
34e9b27d9d071a9b910510ff544bcfb1 *R/show.r
@@ -15,6 +15,10 @@ aa58827122f4e5028398684ae4860d65 *R/string_operations.r
7733b7a4e19f8ac091c59a5d1308b637 *R/style-var.r
7117857a16121744d8ab7e5bddfec9f9 *R/styles.r
39205d785652c83f9ff70924b3152211 *R/utils.r
175d390058b8a9b12995525725218cf4 *inst/ANSI-256-OSX.png
5a18e3dc240c1f6cfffd6059c8de5345 *inst/ANSI-8-OSX.png
232de648bf7331c128404b8f87dbb0c8 *inst/NEWS.md
51454c415a280eee6802d63d9558ddf5 *inst/README.markdown
8f114430b2ffc7cb56946a4b7e6f5ef3 *man/chr.Rd
7dc3b9d87afa497694470d5ba5f784e4 *man/col_nchar.Rd
f8d57a59e8cc2dd00fb79689216008a3 *man/col_strsplit.Rd
@@ -76,10 +76,9 @@ num_colors <- function(forget = FALSE) {

i_num_colors <- memoise::memoise(function() {
if (!has_color()) { return(1) }
cols <- try(silent = TRUE,
system("tput colors", intern = TRUE))
if (inherits(cols, "try-error")) { return(8) }
cols <- as.numeric(cols)
cols <- suppressWarnings(try(silent = TRUE,
as.numeric(system("tput colors", intern = TRUE))))
if (inherits(cols, "try-error") || is.na(cols)) { return(8) }
if (cols %in% c(0, 1)) { return(1) }
cols
})
BIN +457 KB inst/ANSI-256-OSX.png
Binary file not shown.
BIN +68.6 KB inst/ANSI-8-OSX.png
Binary file not shown.
@@ -0,0 +1,25 @@
# 1.2.1

* Fix detecting number of colors when `tput` exists, but
fails with an error and/or does not return anything useful.
(@jimhester, #18, #19)

# 1.2.0

* Fix detection of number of colors, it was cached from
installation time (#17).

* Color aware string operations. They are slow and experimental
currently.

# 1.1.0

* `show_ansi_colors()` prints all supported colors on the screen.

* 256 colors, on terminals that support it.

* Disable colors on Windows, they are not supported in the default setup.

# 1.0.0

* First released version.
@@ -0,0 +1,126 @@

# Crayon - stylish terminal output in R

[![Linux Build Status](https://travis-ci.org/gaborcsardi/crayon.svg?branch=master)](https://travis-ci.org/gaborcsardi/crayon)
[![Windows Build status](https://ci.appveyor.com/api/projects/status/github/gaborcsardi/crayon?svg=true)](https://ci.appveyor.com/project/gaborcsardi/crayon)
[![](http://www.r-pkg.org/badges/version/crayon)](http://cran.rstudio.com/web/packages/crayon/index.html)
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/crayon)](http://cran.r-project.org/web/packages/crayon/index.html)

With crayon it is easy to add color to terminal output, create styles
for notes, warnings, errors; and combine styles.

ANSI color support is automatically detected and used. Crayon was largely
inspired by [chalk](https://github.com/sindresorhus/chalk).

## Installation

```r
devtools::install_github("gaborcsardi/crayon")
library(crayon)
```

## Styles

Crayon defines several styles, that can be combined. Each style in the list
has a corresponding function with the same name.

### General styles

* `reset`
* `bold`
* `blurred` (usually called `dim`, renamed to avoid name clash)
* `italic` (not widely supported)
* `underline`
* `inverse`
* `hidden`
* `strikethrough` (not widely supported)

### Text colors

* `black`
* `red`
* `green`
* `yellow`
* `blue`
* `magenta`
* `cyan`
* `white`
* `silver` (usually called `gray`, renamed to avoid name clash)

### Background colors

* `bgBlack`
* `bgRed`
* `bgGreen`
* `bgYellow`
* `bgBlue`
* `bgMagenta`
* `bgCyan`
* `bgWhite`

### Screenshot on OSX

![](/inst/ANSI-8-OSX.png)

## Usage

The styling functions take any number of character vectors as arguments,
and they concatenate and style them:

```r
library(crayon)
cat(blue("Hello", "world!\n"))
```

Crayon defines the `%+%` string concatenation operator, to make it easy
to assemble stings with different styles.

```r
cat("... to highlight the " %+% red("search term") %+% " in a block of text\n")
```

Styles can be combined using the `$` operator:

```r
cat(yellow$bgMagenta$bold('Hello world!\n'))
```

Styles can also be nested, and then inner style takes precedence:

```r
cat(green(
'I am a green line ' %+%
blue$underline$bold('with a blue substring') %+%
' that becomes green again!\n'
))
```

It is easy to define your own themes:

```r
error <- red $ bold
warn <- magenta $ underline
note <- cyan
cat(error("Error: subscript out of bounds!\n"))
cat(warn("Warning: shorter argument was recycled.\n"))
cat(note("Note: no such directory.\n"))
```

## 256 colors

Most modern terminals support the ANSI standard for 256 colors,
and you can define new styles that make use of them. The `make_style`
function defines a new style. It can handle R's built in color names
(see the output of `colors()`), and also RGB specifications, via the
`rbg()` function. It automatically chooses the ANSI colors that
are closest to the specified R and RGB colors, and it also has
a fallback to terminals with 8 ANSI colors only.

```r
ivory <- make_style("ivory")
bgMaroon <- make_style("maroon", bg = TRUE)
fancy <- combine_styles(ivory, bgMaroon)
cat(fancy("This will have some fancy colors"), "\n")
```

![](/inst/ANSI-256-OSX.png)

0 comments on commit 72b56a0

Please sign in to comment.