Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
* `ansi_collapse(style = "head")` no longer exceeds `width` when not even
the first element fits (#570, @taekop).

* `cli_progress_update(set = )` no longer fails with a deferred `on.exit()`
error when the progress bar is drawn with a value below zero or above
the total (#580, @taekop).

# cli 3.6.6

* New `{.num}` and `{.bytes}` inline styles to format numbers
Expand Down
2 changes: 1 addition & 1 deletion R/progress-bar.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
make_progress_bar <- function(percent, width = 30, style = list()) {
complete_len <- round(width * percent)
complete_len <- round(width * min(max(percent, 0), 1))

def <- default_progress_style()
chr_complete <- style[["progress-complete"]] %||% def[["complete"]]
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-progress-client.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ test_that("update set", {
expect_snapshot(capture_cli_messages(fun()))
})

test_that("update set outside of 0..total", {
withr::local_options(cli.dynamic = FALSE, cli.ansi = FALSE)
fun <- function(set) {
bar <- cli_progress_bar(total = 10, format = "{cli::pb_bar}")
cli_progress_update(force = TRUE, set = set)
cli_progress_done(id = bar)
}
expect_no_error(capture_cli_messages(fun(-1)))
expect_no_error(capture_cli_messages(fun(11)))
})

test_that("format changes if we (un)learn total", {
withr::local_options(cli.dynamic = FALSE, cli.ansi = FALSE)
fun <- function() {
Expand Down
Loading