Skip to content
Open
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* New `{.num}` and `{.bytes}` inline styles to format numbers
and bytes (@m-muecke, #644, #588, #643).

* Silently ignore the `clear` argument if used in `cli_progress_step()`
(@mcol, #785).

# cli 3.6.5

* `code_highlight()` supports long strings and symbols
Expand Down
29 changes: 16 additions & 13 deletions R/progress-client.R
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,8 @@ cli_progress_message <- function(
#' @param current Passed to [cli_progress_bar()].
#' @param .auto_close Passed to [cli_progress_bar()].
#' @param .envir Passed to [cli_progress_bar()].
#' @param ... Passed to [cli_progress_bar()].
#' @param ... Passed to [cli_progress_bar()] (with the exclusion of `clear`,
#' which is always `FALSE`).
#'
#' @seealso This function supports [inline markup][inline-markup].
#' @family progress bar functions
Expand Down Expand Up @@ -819,18 +820,20 @@ cli_progress_step <- function(

opt <- options(cli.progress_show_after = 0)
on.exit(options(opt), add = TRUE)
id <- cli_progress_bar(
type = "custom",
format = format,
format_done = format_done,
format_failed = format_failed,
clear = FALSE,
current = current,
.auto_close = .auto_close,
.envir = .envir,
...
)

cli_progress_bar_strip_clear <- function(..., clear) {
cli_progress_bar(
type = "custom",
format = format,
format_done = format_done,
format_failed = format_failed,
clear = FALSE,
current = current,
.auto_close = .auto_close,
.envir = .envir,
...
)
}
id <- cli_progress_bar_strip_clear(...)
cli_progress_update(id = id, force = TRUE, .envir = .envir)

invisible(id)
Expand Down
3 changes: 2 additions & 1 deletion man/cli_progress_step.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/_snaps/progress-message.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
[3] "\n" "\ri Second step\033[K\r"
[5] "\rv Second step [1s]\033[K\r" "\n"

# cli_progress_step ignores clear

Code
msgs
Output
[1] "\ri First step\033[K\r" "\rv First step [1s]\033[K\r"
[3] "\n" "\ri Second step\033[K\r"
[5] "\rv Second step [1s]\033[K\r" "\n"

# cli_progress_step error

Code
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-progress-message.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ test_that("cli_progress_step", {
expect_snapshot(msgs)
})

test_that("cli_progress_step ignores clear", {
withr::local_options(cli.dynamic = TRUE, cli.ansi = TRUE)
suppressWarnings(testthat::local_reproducible_output())
fun <- function() {
cli_progress_step("First step", clear = TRUE)
cli_progress_step("Second step", clear = FALSE)
}
msgs <- fix_times(capture_cli_messages(fun()))
expect_snapshot(msgs)
})

test_that("cli_progress_step error", {
if (getRversion() < "3.5.0") skip("Needs R 3.5.0")
fun <- function() {
Expand Down
Loading