Skip to content

Commit c3ddc5b

Browse files
committed
ANSI coloring now conforms to NO_CODE. closes #90
1 parent b265e7a commit c3ddc5b

5 files changed

Lines changed: 20 additions & 5 deletions

File tree

pkg/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ URL: https://github.com/markvanderloo/tinytest
2323
BugReports: https://github.com/markvanderloo/tinytest/issues
2424
Depends: R (>= 3.0.0)
2525
Imports: parallel, utils
26-
RoxygenNote: 7.2.3
26+
RoxygenNote: 7.3.2
2727
Encoding: UTF-8

pkg/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
version 1.4.2
2+
- tt.pr.color is now set to FALSE when the NO_COLOR environment
3+
variable is set. See https://no-color.org/
24
- expect_<condition> now uses conditionMessage internally. This
35
should increase compatibility with packages defining custom
46
conditions. (thanks to Tim Taylor for suggesting and Etienne Bacher

pkg/R/init.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11

22

33
.onLoad <- function(libname, pkgname){
4-
# turn off color printing for dumb terminals
4+
# turn off color printing for dumb terminal
55
term <- tolower(trimws(Sys.getenv("TERM")))
6-
if ( identical( term, "dumb" ) ){
6+
# turn off color when NO_COLOR is set
7+
no_color <- Sys.getenv("NO_COLOR",unset=NA_character_)
8+
if ( identical(term, "dumb") ||
9+
identical(no_color, NA_character_)|| identical(no_color, "") ){
10+
711
options(tt.pr.color=FALSE)
812
}
913

pkg/R/methods.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ any_fail <- function(x){
117117
#' }
118118
#' which determines whether colored output is printed.
119119
#' If R is running in a dumb terminal (detected by comparing
120-
#' environment variable \code{"TERM"} to \code{"dumb"}), then
120+
#' environment variable \code{"TERM"} to \code{"dumb"}), or if the
121+
#' \code{NO_CODE} environment variable is set, then
121122
#' this option is set to \code{FALSE} when the package is loaded.
123+
#' See also \href{https://no-color.org}{https://no-color.org}.
122124
#'
123125
#' @rdname tinytests
124126
#' @export

pkg/inst/tinytest/test_init.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11

2-
oldterm <- Sys.getenv("TERM")
32
Sys.setenv(TERM = "dumb") # will be unset by tinytest
43
tinytest:::.onLoad()
54
expect_false(getOption("tt.pr.color"))
65

6+
7+
8+
options(tt.pr.color=NULL)
9+
Sys.setenv(NO_COLOR=1L)
10+
tinytest:::.onLoad()
11+
expect_false(getOption("tt.pr.color"))
12+
13+
714
# reset option set by .onLoad()
815
options(tt.pr.color=NULL)
916

0 commit comments

Comments
 (0)