progressr icon indicating copy to clipboard operation
progressr copied to clipboard

Colour in handler_progress

Open FedericoTrifoglio opened this issue 3 years ago • 3 comments

Is there a way to change the colour of the progress bar in handler_progress? Or another handler?

Possibly something like this?

handler_progress(format = ":spin :current/:total (:message) [:bar] :percent in :elapsed ETA: :eta", width = 60, complete = "+", color = function(s) crayon::black(s))

Or perhaps by adding "format", "width" and "complete_char" arguments to handler_pbcol?

FedericoTrifoglio avatar Mar 10 '21 12:03 FedericoTrifoglio

I added handler_pbcol() as a proof of concept and as a teaser for what can be done.

I think rendering progress as foreground/background color is a good candidate for a feature request for the progress package. If added there, it'll be automatically supported by handler_progress().

HenrikBengtsson avatar Apr 07 '21 19:04 HenrikBengtsson

Forgot to say, progress supports coloring the format string with crayon (e.g. #76). Unfortunately, it gives an error if you attempt the same for complete and incomplete, cf. https://github.com/r-lib/progress/issues/78

HenrikBengtsson avatar Apr 08 '21 02:04 HenrikBengtsson

Gotcha re handler_pbcol and thanks for pointing me in the right direction. I'm pretty sure I must have tried what you suggested to the OP in #76 but didn't work for me. I should have been a bit more patient and trust my gut feeling.

Anyway wrapping the value of the argument format inside a crayon's style works!

The only disadvantage (and sorry this is a bit out of topic here) in using crayon is that the styles don't change depending on the RStudio theme. Eg if using crayon::black() but the user's theme is dark they won't see it. I currently get the theme's info with rstudioapi::getThemeInfo() and then make a crayon style out of it, but not sure it's the best approach.

FedericoTrifoglio avatar Apr 08 '21 07:04 FedericoTrifoglio

Support for cli has been added for the next release (#123).

Support for background colors with progress has to be fixed in the progress package, which pending a bug fix, cf. https://github.com/r-lib/progress/issues/78.

Or perhaps by adding "format", "width" and "complete_char" arguments to handler_pbcol?

I looked at the handler_pbcol() again. The width is agile to R option width, like most other progress handlers reporting to the terminal. It does not really make sense to have a complete_char gibehaviorven that it's designed to relay progress via the background color, e.g.

image

That leaves the format option. The current output is hard-coded to something that would correspond to format = " { :message }{ :pad-width } :percent :spin". The handler_pbcol() was just a proof-of-concept and to add progress-like support for customizing the output format, is quite a bit of work. If someone wish to do this, see the internal pbcol() function. I don't really want to get into the business of designing and maintaining progress reporters per se. The idea with the progressr package is to pass that task on to whatever progress reporter existing in R.

HenrikBengtsson avatar Nov 29 '22 18:11 HenrikBengtsson