Skip to content
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

C API: progress variables don't work in format_done #337

Closed
gaborcsardi opened this issue Aug 18, 2021 · 1 comment
Closed

C API: progress variables don't work in format_done #337

gaborcsardi opened this issue Aug 18, 2021 · 1 comment
Labels
bug an unexpected problem or unintended behavior

Comments

@gaborcsardi
Copy link
Member

E.g. format_done = "Completed in {cli::pb_elapsed}".

@gaborcsardi gaborcsardi added the bug an unexpected problem or unintended behavior label Aug 18, 2021
@jimhester
Copy link
Member

jimhester commented Aug 18, 2021

Here is a reprex. Sorry for the cpp11 stuff, but it was easier for me to write it like this than trying to remember how to create a named list with the C API functions.

This would need the dev version of cpp11, as there is a bug in the current CRAN release related to the use of cpp11::linking_to.

cpp11::cpp_source(code = '#include <cpp11.hpp>
 #include <cli/progress.h>
[[cpp11::linking_to("cli")]]
[[cpp11::register]]
void pb() {
  int i;
  using namespace cpp11::literals;
  cpp11::writable::list config({"clear"_nm = false, "format_done"_nm = "Completed in {cli::pb_elapsed}."});
  SEXP bar = PROTECT(cli_progress_bar(1000, config));
  for (i = 0; i < 1000; i++) {
    cli_progress_sleep(0, 4 * 1000 * 1000);
    if (CLI_SHOULD_TICK) cli_progress_set(bar, i);
  }
  cli_progress_done(bar);
  UNPROTECT(1);
}')

pb()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants