Skip to content

Progress bars behind callr processes #755

@wlandau

Description

@wlandau

I'm really enjoying cli progress bars, but I'm struggling with an edge case. For ropensci/targets#1442, I need to run the progress bar behind a non-interactive callr process. Unfortunately, the non-interactivity seems to make the progress bar slightly less responsive, and it seems to spill over into multiple lines. This is the desired behavior when writing to a fixed log file, but it's counterintuitive when the parent session is interactive. Are there any workarounds etc.?

out <- callr::r(
  \() {
    library(cli)
    clean <- function() {
      options(cli.num_colors = 256)
      cli_progress_bar("Cleaning data", total = 100)
      for (i in 1:100) {
        Sys.sleep(5/100)
        cli_progress_update()
      }
      cli_progress_done()
    }
    clean()
  },
  show = TRUE,
  stderr = "2>&1"
)
#> Cleaning data ■■■■■■■                           19% | ETA:  4s
#> Cleaning data ■■■■■■■■■■■■■■■■■                 55% | ETA:  2s
#> Cleaning data ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■  100% | #> ETA:  0s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions