Skip to content

Commit 4449a2d

Browse files
pbcol() would not work produce colors in RStudio Console or when output was buffered in the terminal
(fixes #100)
1 parent 25d36f9 commit 4449a2d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

R/handler_pbcol.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#' @importFrom utils flush.console
2424
#' @export
2525
handler_pbcol <- function(adjust = 0.0, pad = 1L, done_col = "blue", todo_col = "cyan", intrusiveness = getOption("progressr.intrusiveness.terminal", 1), target = "terminal", ...) {
26+
crayon_enabled <- getOption("crayon.enabled", NA)
27+
if (is.na(crayon_enabled)) crayon_enabled <- crayon::has_color()
28+
2629
cat_ <- function(...) {
2730
cat(..., sep = "", collapse = "", file = stderr())
2831
flush.console()
@@ -34,6 +37,10 @@ handler_pbcol <- function(adjust = 0.0, pad = 1L, done_col = "blue", todo_col =
3437

3538
redraw_progress_bar <- function(ratio, message, spin = " ") {
3639
stop_if_not(ratio >= 0, ratio <= 1)
40+
if (crayon_enabled) {
41+
options(crayon.enabled = TRUE)
42+
on.exit(options(crayon.enabled = TRUE), add = TRUE)
43+
}
3744
pbstr <- pbcol(
3845
fraction = ratio,
3946
msg = message,

0 commit comments

Comments
 (0)