Skip to content

Commit 8128657

Browse files
handler_pbcol() gain argument 'text_col="white"'. Can't rely on the default foreground color being white, e.g. in the RStudio Console [ci skip]
1 parent 4449a2d commit 8128657

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

R/handler_pbcol.R

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#'
2323
#' @importFrom utils flush.console
2424
#' @export
25-
handler_pbcol <- function(adjust = 0.0, pad = 1L, done_col = "blue", todo_col = "cyan", intrusiveness = getOption("progressr.intrusiveness.terminal", 1), target = "terminal", ...) {
25+
handler_pbcol <- function(adjust = 0.0, pad = 1L, text_col = "white", done_col = "blue", todo_col = "cyan", intrusiveness = getOption("progressr.intrusiveness.terminal", 1), target = "terminal", ...) {
2626
crayon_enabled <- getOption("crayon.enabled", NA)
2727
if (is.na(crayon_enabled)) crayon_enabled <- crayon::has_color()
2828

@@ -46,6 +46,7 @@ handler_pbcol <- function(adjust = 0.0, pad = 1L, done_col = "blue", todo_col =
4646
msg = message,
4747
adjust = adjust,
4848
pad = pad,
49+
text_col = text_col,
4950
done_col = done_col,
5051
todo_col = todo_col,
5152
spin = spin,
@@ -93,7 +94,7 @@ handler_pbcol <- function(adjust = 0.0, pad = 1L, done_col = "blue", todo_col =
9394

9495

9596

96-
pbcol <- function(fraction = 0.0, msg = "", adjust = 0, pad = 1L, width = getOption("width") - 1L, done_col = "blue", todo_col = "cyan", spin = " ") {
97+
pbcol <- function(fraction = 0.0, msg = "", adjust = 0, pad = 1L, width = getOption("width") - 1L, text_col = "white", done_col = "blue", todo_col = "cyan", spin = " ") {
9798
bgColor <- function(s, col) {
9899
bgFcn <- switch(col,
99100
black = crayon::bgBlack,
@@ -109,6 +110,22 @@ pbcol <- function(fraction = 0.0, msg = "", adjust = 0, pad = 1L, width = getOpt
109110
bgFcn(s)
110111
}
111112

113+
fgColor <- function(s, col) {
114+
fgFcn <- switch(col,
115+
black = crayon::black,
116+
blue = crayon::blue,
117+
cyan = crayon::cyan,
118+
green = crayon::green,
119+
magenta = crayon::magenta,
120+
red = crayon::red,
121+
silver = crayon::silver,
122+
yellow = crayon::yellow,
123+
white = crayon::white,
124+
stop("Unknown 'crayon' foreground color: ", sQuote(col))
125+
)
126+
fgFcn(s)
127+
}
128+
112129
if (length(msg) == 0L) msg <- ""
113130
stop_if_not(length(msg) == 1L, is.character(msg))
114131

@@ -146,5 +163,9 @@ pbcol <- function(fraction = 0.0, msg = "", adjust = 0, pad = 1L, width = getOpt
146163
rmsg <- substr(pmsg, start = len + 1L, stop = nchar(pmsg))
147164
lmsg <- bgColor(lmsg, done_col)
148165
rmsg <- bgColor(rmsg, todo_col)
149-
paste(lmsg, rmsg, sep = "")
166+
lmsg <- fgColor(lmsg, text_col)
167+
rmsg <- fgColor(rmsg, text_col)
168+
bar <- paste(lmsg, rmsg, sep = "")
169+
170+
bar
150171
}

man/handler_pbcol.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)