Skip to content
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

Colour in handler_progress #106

Closed
FedericoTrifoglio opened this issue Mar 10, 2021 · 4 comments
Closed

Colour in handler_progress #106

FedericoTrifoglio opened this issue Mar 10, 2021 · 4 comments
Labels
question Further information is requested

Comments

@FedericoTrifoglio
Copy link

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?

@HenrikBengtsson
Copy link
Collaborator

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 HenrikBengtsson added the question Further information is requested label Apr 7, 2021
@HenrikBengtsson
Copy link
Collaborator

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. r-lib/progress#78

@FedericoTrifoglio
Copy link
Author

FedericoTrifoglio commented Apr 8, 2021

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.

@HenrikBengtsson
Copy link
Collaborator

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. r-lib/progress#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants