Skip to content

Commit

Permalink
New options: noninteractive and notatty
Browse files Browse the repository at this point in the history
  • Loading branch information
jalvesaq committed Jun 10, 2015
1 parent f612cc6 commit 7829ef0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 7 additions & 3 deletions R/colorout.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
options(colorout.anyterm = FALSE)
if(is.null(getOption("colorout.dumb")))
options(colorout.dumb = FALSE)
if(is.null(getOption("colorout.noninteractive")))
options(colorout.noninteractive = FALSE)
if(is.null(getOption("colorout.notatty")))
options(colorout.notatty = FALSE)
if(is.null(getOption("colorout.verbose")))
options(colorout.verbose = 0)

Expand All @@ -40,10 +44,10 @@ testTermForColorOut <- function()
if(getOption("colorout.anyterm"))
return("OK")

if(interactive() == FALSE)
if(interactive() == FALSE && getOption("colorout.noninteractive") == FALSE)
return("Not in an interactive session.\n")

if(isatty(stdout()) == FALSE)
if(isatty(stdout()) == FALSE && getOption("colorout.notatty") == FALSE)
return("isatty(stdout()) returned FALSE.\n")

if(Sys.getenv("RSTUDIO") != "")
Expand Down Expand Up @@ -466,7 +470,7 @@ show256Colors <- function(outfile = "/tmp/table256.html")
"#d0d0d0", "#dadada", "#e4e4e4", "#eeeeee")

sink(file = outfile)
cat("<html>\n<head>\n <title>256 terminal emulator colors</title>\n")
cat("<!DOCTYPE HTML SYSTEM>\n<html>\n<head>\n <title>256 terminal emulator colors</title>\n")
cat("<style type=\"text/css\">\n table td { height: 20px; width: 20px; }\n</style>\n")
cat("</head>\n<body bgcolor=\"#000000\">\n")
cat("\n<p>&nbsp;</p>\n\n")
Expand Down
13 changes: 13 additions & 0 deletions man/colorout-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Colorize R output on terminal emulators
options(colorout.verbose = 0)
options(colorout.anyterm = TRUE)
options(colorout.dumb = TRUE)
options(colorout.noninteractive = TRUE)
options(colorout.notatty = TRUE)
}

With \code{colorout.anyterm == TRUE}, the package will not check the
Expand All @@ -64,6 +66,17 @@ Colorize R output on terminal emulators
}
}

And of course, you can use any arbitrary condition to decide whether to load
colorout or not. For instance:

\preformatted{
if((interactive() && Sys.getenv("RSTUDIO") == "") ||
(!interactive() && isatty(stdout()))){
options(colorout.anyterm = TRUE)
library(colorout)
}
}

If \code{colorout.verbose > 0}, the package will display a warning if the
output is not going to be colorized.

Expand Down

0 comments on commit 7829ef0

Please sign in to comment.