Skip to content
Permalink
Browse files
#64 - implement NO_COLOR (#65)
* implement NO_COLOR

* Update roxygen comment

* roxygenise

* test and NEWS

* Unset crayon option in NO_COLOR test
  • Loading branch information
nfultz authored and gaborcsardi committed Feb 8, 2018
1 parent b5221ab commit 700800135d04408bf1c99426b3fec9a4073b8a97
Showing with 21 additions and 0 deletions.
  1. +6 −0 R/has_color.r
  2. +3 −0 inst/NEWS.md
  3. +2 −0 man/has_color.Rd
  4. +10 −0 tests/testthat/test-has-color.r
@@ -9,6 +9,8 @@
#' with [options()], then `TRUE` is returned. If it is
#' set to something else than `TRUE` (typically `FALSE`),
#' then `FALSE` is returned.
#' \item Otherwise, if the `NO_COLOR` environment variable is
#' set, `FALSE` is returned.
#' \item Otherwise, if the standard output is not a terminal, then
#' `FALSE` is returned.
#' \item Otherwise, if the platform is Windows, `TRUE` is returned
@@ -49,6 +51,10 @@ has_color <- function() {
enabled <- getOption("crayon.enabled")
if (!is.null(enabled)) { return(isTRUE(enabled)) }

if (!is.na(Sys.getenv("NO_COLOR", NA))) {
return(FALSE)
}

## RStudio with (potential) ANSI support?
if (rstudio_with_ansi_support() && sink.number() == 0) {
return(TRUE)
@@ -1,3 +1,6 @@
# Next

* `NO_COLOR` enviroment variable disables color (#64)

# 1.3.4

Some generated files are not rendered by default. Learn more.

@@ -89,3 +89,13 @@ test_that("tput errors are handled gracefully", {
mockery::stub(get_terminal_colors, "system", function(...) 16)
expect_equal(get_terminal_colors(), 16)
})

test_that("has_color, NO_COLOR=1", {
withr::with_options(
list(crayon.enabled = NULL),
withr::with_envvar(
c(NO_COLOR="1"),
expect_false(has_color())
)
)
})

0 comments on commit 7008001

Please sign in to comment.