cli icon indicating copy to clipboard operation
cli copied to clipboard

A way to show progress bar even when total = 1?

Open mkalamarz opened this issue 1 year ago • 3 comments

When using cli_progress_bar(total = 1, clear = FALSE) I would expect to see the fully filled bar in the same way as I get it when the total is 2 or 2000. I've set progress_show_after=0.

The use case is that rarely a user can specify one element to iterate over but I still need to show the completed progress bar so they don't freak out that this function didn't process their data.

mkalamarz avatar Jul 11 '23 23:07 mkalamarz

Reprex, no output:

library(cli)
options(cli.progress_show_after = 0)
{
  cli_progress_bar(total = 1, clear = FALSE)
  cli_progress_update()
}

Correct output for two steps:

{
  cli_progress_bar(total = 2, clear = FALSE)
  cli_progress_update()
  cli_progress_update()
}
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■  100% | ETA:  0s

gaborcsardi avatar Jul 12 '23 07:07 gaborcsardi

TBH IDK how useful it is to show a progress bar that has a single step. But I agree that some consistency would be nice. Right now, the finished progress bar is not shown, even with force = TRUE.

gaborcsardi avatar Jul 12 '23 07:07 gaborcsardi

@gaborcsardi let me share an example. I use it in an internal package with functions that process survey data. There are different question types with corresponding functions. Sometimes there is only one question of a certain type in a survey. Each function has this progress bar because it can as well have to process a ton of these.

So peaople using the package will get used to having these bars show up after each function call. This way they can get confused as why an always appearing element is not present and maybe think that there is some kind of bug.

Also, these function can be used in a pipe so it would be weird to get a progress bar for each step of a pipe but suddenly miss one without any explanation.

As these function can be run separately I can't replace it with cli_progress_step().

mkalamarz avatar Jul 12 '23 21:07 mkalamarz