-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for crayon styling in progress bar output #76
Comments
You're almost there; the following does what you want. library(progressr)
## The user specifies which progress handler(s) to use
handlers(handler_progress(format = crayon::silver(":spin [:bar] :percent :message")))
## Then these handler(s) are used whenever with_progress() is in place
with_progress({
pb <- progressor(steps = 5)
for (i in 1:5) {
pb()
Sys.sleep(1)
}
}) |
Hi Henrik,
Thanks for the reply, but I don’t think it addresses my issue, which is that the output styling from the crayon package isn’t applied in progressr, regardless of whether it is specified in the handler_progress format argument.
At least on my machine, when I run the code you sent me, the progress bar is NOT drawn in the colour specified by crayon::silver(), but instead remains in the default styling.
This is in contrast to the progress package, where the exact same format argument will draw the progress bar in silver text.
Please let me know if that clarifies the issue.
|
Aha... I been very puzzled for the last 20 minutes, because "it works for me". However, eventually, I tried with if (crayon:::has_color()) options(crayon.enabled = TRUE) in my So, for now, as a workaround, use: library(progressr)
if (crayon:::has_color()) options(crayon.enabled = TRUE)
handlers(handler_progress(format = crayon::red(":current of :total [:bar]")))
with_progress(slow_sum(1:5)) I'll see if I can apply this "workaround" to the internal code of
|
Here's an easier workaround - wrapping the library(progressr)
handlers(handler_progress(format = as.character(crayon::red(":current of :total [:bar]"))))
with_progress(slow_sum(1:5)) |
…xpressions while setting up the 'progress' handler. This is more future proof, in case 'progress' will support other data types later [#76]
This has been fixed for the next release. Until then, install as: remotes::install_github("HenrikBengtsson/progressr@develop") Thanks for inquiring/reporting. |
Thanks very much for the quick action on this! I’ve been very excited to see the progressr package develop.
|
:) ... only possible with feedback like yours |
progressr 0.6.0 on CRAN just now. |
I just installed progressr 0.6.0, and can confirm that crayon styling is working "out of the box" without needing to set the crayon.enabled option. Thanks again! |
As far as I can tell, progressr doesn't support using crayon styling to change the colour or weight of terminal output. This came up when I attempted to replicate a previous progress::progress_bar format using handler_progress().
So the following produces silver text:
pb <-
progress::progress_bar$new(
format = crayon::silver(":current of :total [:bar]"),
total = 5
)
for (i in 1:5) {
pb$tick()
Sys.sleep(1)
}
But the following does not produce styled text, even though it otherwise seems to support the
format
argument of progress::progress_bar. (It also doesn't thrown an error or warning that the crayon formatting is being ignored.)with_progress({
pb <- progressor(steps = 5)
for (i in 1:5) {
pb()
Sys.sleep(1)
}
},
handlers = handler_progress(
format = crayon::silver(":current of :total [:bar]")
))
Is there another way to apply terminal styling to progress bar output that I am missing? If not, is this a feature you'd consider supporting?
The text was updated successfully, but these errors were encountered: