-
Notifications
You must be signed in to change notification settings - Fork 95
Quiet progress bars #840
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
Quiet progress bars #840
Changes from all commits
041f5fc
8cf7c41
273e48c
36e2fbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docs still say 'TRUE' or am I missing something here? |
||||||
| #' @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), | ||||||
|
jacciz marked this conversation as resolved.
|
||||||
| 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) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not seem correct to me. If we are creating a new progress bar, then that should be the current progress bar, whether it is quiet or not. |
||||||
| 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){ | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [air] reported by reviewdog 🐶
Suggested change
|
||||||
| 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) | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -216,3 +216,21 @@ test_that("cli_progress_bar handles Inf like NA", { | |||||||||||||||||||||||||||||||||||||
| capture_cli_messages(fun(total = Inf)) | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| test_that("no progress bar when quiet = TRUE", { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| fun <- function() { | ||||||||||||||||||||||||||||||||||||||
| bar <- cli_progress_bar( | ||||||||||||||||||||||||||||||||||||||
| name = "name", | ||||||||||||||||||||||||||||||||||||||
| quiet = TRUE | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| for (i in 1:100) { | ||||||||||||||||||||||||||||||||||||||
| Sys.sleep(5/100) | ||||||||||||||||||||||||||||||||||||||
| cli_progress_update(id = bar) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+221
to
+230
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [air] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [air] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| # No messages to display | ||||||||||||||||||||||||||||||||||||||
| expect_snapshot(capture_cli_messages(fun())) | ||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+233
to
+236
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [air] reported by reviewdog 🐶
Suggested change
|
||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.