From 041f5fc80c385045af6334ba5354996172605a11 Mon Sep 17 00:00:00 2001 From: Jacci Ziebert Date: Thu, 17 Sep 2026 13:36:50 -0500 Subject: [PATCH 1/3] added quiet as an argument in cli_progress_bar, also added a unit test --- NEWS.md | 2 ++ R/progress-client.R | 29 ++++++++++++++++----------- tests/testthat/test-progress-client.R | 18 +++++++++++++++++ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/NEWS.md b/NEWS.md index bb4f73768..b63541660 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # cli (development version) +* `cli_progress_bar()` has a new argument `quiet`. If FALSE, then progress bar will be suppressed. + * `keypress()` improvements: - `timeout` argument to wait at most a given number of seconds for a key press. diff --git a/R/progress-client.R b/R/progress-client.R index edae4463b..2c5d91e8c 100644 --- a/R/progress-client.R +++ b/R/progress-client.R @@ -282,6 +282,8 @@ #' @param current Whether to use this progress bar as the current progress #' bar of the calling function. See more at 'The current progress bar' #' below. +#' @param quiet if `TRUE` suppresses output from this function. Defaults to the `cli.disable_progress` option, or +#' `TRUE` if unset. #' @param auto_terminate Whether to terminate the progress bar if the #' number of current units reaches the number of total units. #' @param extra Extra data to add to the progress bar. This can be @@ -320,6 +322,7 @@ cli_progress_bar <- function( format_failed = NULL, clear = getOption("cli.progress_clear", TRUE), current = TRUE, + quiet = getOption("cli.disable_progress", FALSE), auto_terminate = type != "download", extra = NULL, .auto_close = TRUE, @@ -359,7 +362,7 @@ cli_progress_bar <- function( bar$extra <- extra clienv$progress[[id]] <- bar if (current) { - if (!is.null(clienv$progress_ids[[envkey]])) { + if (!is.null(clienv$progress_ids[[envkey]]) && quiet == FALSE) { cli_progress_done( clienv$progress_ids[[envkey]], .envir = .envir, @@ -369,19 +372,21 @@ cli_progress_bar <- function( clienv$progress_ids[[envkey]] <- id } - if (.auto_close && envkey != clienv$globalenv) { - defer( - cli_progress_done(id = id, .envir = .envir, result = "auto"), - envir = .envir - ) - } + if( quiet == FALSE){ + if (.auto_close && envkey != clienv$globalenv) { + defer( + cli_progress_done(id = id, .envir = .envir, result = "auto"), + envir = .envir + ) + } - opt <- options(cli__pb = bar) - on.exit(options(opt), add = TRUE) + opt <- options(cli__pb = bar) + on.exit(options(opt), add = TRUE) - bar$handlers <- cli_progress_select_handlers(bar, .envir) - for (h in bar$handlers) { - if ("create" %in% names(h)) h$create(bar, .envir = .envir) + bar$handlers <- cli_progress_select_handlers(bar, .envir) + for (h in bar$handlers) { + if ("create" %in% names(h)) h$create(bar, .envir = .envir) + } } invisible(id) diff --git a/tests/testthat/test-progress-client.R b/tests/testthat/test-progress-client.R index f14cfaf91..c5d46faeb 100644 --- a/tests/testthat/test-progress-client.R +++ b/tests/testthat/test-progress-client.R @@ -205,3 +205,21 @@ test_that("cli_progress_bar handles Inf like NA", { capture_cli_messages(fun(total = Inf)) ) }) + +test_that("no progress bar when quiet = TRUE", { + withr::local_options(cli.dynamic = FALSE, cli.ansi = FALSE) + fun <- function() { + bar <- cli_progress_bar( + name = "name", + status = "status", + format = "{cli::pb_spin} {cli::pb_name}{cli::pb_status}{cli::pb_current}", + quiet = TRUE + ) + cli_progress_update(force = TRUE) + cli_progress_done(id = bar) + } + + # No messages to display + expect_snapshot(capture_cli_messages(fun())) + }) + From 8cf7c41c5f931a42dd2e5dc556063ee8e9988fa0 Mon Sep 17 00:00:00 2001 From: Jacci Ziebert Date: Thu, 17 Sep 2026 14:10:29 -0500 Subject: [PATCH 2/3] update unit test for when quiet = TRUE for cli_progress_bar --- tests/testthat/test-progress-client.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-progress-client.R b/tests/testthat/test-progress-client.R index c5d46faeb..ebb176522 100644 --- a/tests/testthat/test-progress-client.R +++ b/tests/testthat/test-progress-client.R @@ -207,16 +207,16 @@ test_that("cli_progress_bar handles Inf like NA", { }) test_that("no progress bar when quiet = TRUE", { - withr::local_options(cli.dynamic = FALSE, cli.ansi = FALSE) + fun <- function() { bar <- cli_progress_bar( name = "name", - status = "status", - format = "{cli::pb_spin} {cli::pb_name}{cli::pb_status}{cli::pb_current}", quiet = TRUE ) - cli_progress_update(force = TRUE) - cli_progress_done(id = bar) + for (i in 1:100) { + Sys.sleep(5/100) + cli_progress_update(id = bar) + } } # No messages to display From 273e48c1d1a868dc3ff28bd3177b71ef3f1336de Mon Sep 17 00:00:00 2001 From: Jacci Ziebert Date: Thu, 17 Sep 2026 14:58:34 -0500 Subject: [PATCH 3/3] Changed quiet == FALSE to !quiet, edited news to reflect arugment --- NEWS.md | 2 +- R/progress-client.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index b63541660..abd566ce7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # cli (development version) -* `cli_progress_bar()` has a new argument `quiet`. If FALSE, then progress bar will be suppressed. +* `cli_progress_bar()` has a new argument `quiet`. If TRUE, then progress bar will be suppressed. * `keypress()` improvements: - `timeout` argument to wait at most a given number of seconds for a diff --git a/R/progress-client.R b/R/progress-client.R index 2c5d91e8c..83df8d133 100644 --- a/R/progress-client.R +++ b/R/progress-client.R @@ -362,7 +362,7 @@ cli_progress_bar <- function( bar$extra <- extra clienv$progress[[id]] <- bar if (current) { - if (!is.null(clienv$progress_ids[[envkey]]) && quiet == FALSE) { + if (!is.null(clienv$progress_ids[[envkey]]) && !quiet) { cli_progress_done( clienv$progress_ids[[envkey]], .envir = .envir, @@ -372,7 +372,7 @@ cli_progress_bar <- function( clienv$progress_ids[[envkey]] <- id } - if( quiet == FALSE){ + if(!quiet){ if (.auto_close && envkey != clienv$globalenv) { defer( cli_progress_done(id = id, .envir = .envir, result = "auto"),