From 9886aeeead61d2117082e10a5e59e3f532af48ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 8 Dec 2021 21:44:51 +0100 Subject: [PATCH] Use cli::is_dynamic_tty() do decide on dynamic output This can be forced or suppressed with the `cli.dynamic` option and the `R_CLI_DYNAMIC` env var. See `?cli::is_dynamic_tty` for details. Now pkgbuild output looks OK in Rmds, by default. Closes #64. --- R/callback.R | 7 +++++++ R/rcmd.R | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/R/callback.R b/R/callback.R index 4370c85..bb8e536 100644 --- a/R/callback.R +++ b/R/callback.R @@ -105,3 +105,10 @@ block_callback <- function(quiet) { is_new_check <- function(x) { grepl("^\\* ", x) } + +simple_callback <- function(quiet) { + function(x) { + if (quiet) return() + cat(x) + } +} diff --git a/R/rcmd.R b/R/rcmd.R index 976c0c4..fa96269 100644 --- a/R/rcmd.R +++ b/R/rcmd.R @@ -23,9 +23,15 @@ rcmd_build_tools <- function(..., env = character(), required = TRUE, quiet = FA warn_for_potential_errors() + callback <- if (cli::is_dynamic_tty()) { + block_callback(quiet) + } else { + simple_callback(quiet) + } + res <- with_build_tools( callr::rcmd_safe(..., env = env, spinner = FALSE, show = FALSE, - echo = FALSE, block_callback = block_callback(quiet), stderr = "2>&1"), + echo = FALSE, block_callback = callback, stderr = "2>&1"), required = required )