cli icon indicating copy to clipboard operation
cli copied to clipboard

"Quiet" progress bars

Open hadley opened this issue 2 years ago • 3 comments

It's pretty common to have an option that controls whether or not progress bars appears, which leads to code like this:

  if (!quiet) {
    cli::cli_progress_bar(
      format = "Running job {x} [:spin] :elapsed",
      total = NA,
      clear = FALSE
    )
  }

  repeat {
    if (!quiet) cli::cli_progress_update()
    # https://cloud.google.com/bigquery/docs/error-messages
    # Switch to req_retry() when we move to httr2
    status <- tryCatch(
      bq_job_status(x),
      bigrquery_http_503 = function(err) NULL
    )
    if (!quiet) cli::cli_progress_update()

    if (!is.null(status) && status$state == "DONE") break
    Sys.sleep(pause)
  }
  if (!quiet) cli::cli_progress_done()

It'd be nice if there was an option to cli_progress_bar() that generated a quiet bar.

hadley avatar Nov 09 '23 18:11 hadley

If you are considering this then I would value a global option to completely suppress progress bar output, mostly so I can switch progress bars off when I move from interactively running markdown chunks in RStudio to knitting a rmarkdown document, when I want to suppress the progress bars in the output.

maybe the new parameter in cli_progress_bar() could reference a global option , e.g.

cli_progress_bar = function( <snip>, quiet = getOption("cli.disable_progress",FALSE) ,  <snip> ) { <snip> }

robchallen avatar May 15 '24 19:05 robchallen

N.B. my particular use case overlaps with #583

robchallen avatar May 15 '24 19:05 robchallen

@robchallen IMO we should do that automatically for you

hadley avatar May 16 '24 13:05 hadley