From 432958a28d7ce53940a38703bfa3eaaae17f2510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Tue, 7 May 2019 09:36:29 +0100 Subject: [PATCH] Do not use \r if not a dynamic tty Closes #94. --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/build.R | 2 +- R/callback.R | 24 ++++++++++++++++++++++++ R/package.R | 4 ++-- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c82d60e..0d17752 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,7 +20,7 @@ Suggests: testthat Imports: callr (>= 3.1.1.9000), - cli, + cli (>= 1.1.0), crayon, desc (>= 1.2.0), digest, diff --git a/NAMESPACE b/NAMESPACE index 1c45271..799be19 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,6 +20,7 @@ importFrom(R6,R6Class) importFrom(callr,rcmd_process) importFrom(callr,rcmd_process_options) importFrom(callr,rcmd_safe) +importFrom(cli,is_dynamic_tty) importFrom(cli,symbol) importFrom(crayon,bgRed) importFrom(crayon,bold) diff --git a/R/build.R b/R/build.R index 48c0c7d..e74bf19 100644 --- a/R/build.R +++ b/R/build.R @@ -14,7 +14,7 @@ build_package <- function(path, tmpdir, build_args, libpath, quiet) { c("R_LIBS_USER" = paste(libpath, collapse = .Platform$path.sep)), { proc <- pkgbuild_process$new(path, tmpdir, args = build_args) on.exit(proc$kill(), add = TRUE) - callback <- block_callback() + callback <- detect_callback() while (proc$is_incomplete_output() || proc$is_incomplete_error()) { proc$poll_io(-1) out <- proc$read_output() diff --git a/R/callback.R b/R/callback.R index 149f72e..9d84881 100644 --- a/R/callback.R +++ b/R/callback.R @@ -238,3 +238,27 @@ to_status <- function(x) { is_new_check <- function(x) { grepl("^\\* ", x) } + +simple_callback <- function(top_line = TRUE) { + function(x) cat(x) +} + +detect_callback <- function() { + if (is_dynamic_tty2()) block_callback() else simple_callback() +} + +#' @importFrom cli is_dynamic_tty + +is_dynamic_tty2 <- function() { + ## This is to work around a cli bug: + ## https://github.com/r-lib/cli/issues/70 + if ((x <- Sys.getenv("R_CLI_DYNAMIC", "")) != "") { + isTRUE(x) + } else { + is_dynamic_tty() + } +} + +should_add_spinner <- function() { + is_dynamic_tty2() +} diff --git a/R/package.R b/R/package.R index 7fc5e17..2e892a3 100644 --- a/R/package.R +++ b/R/package.R @@ -134,8 +134,8 @@ do_check <- function(targz, package, args, libpath, repos, user_profile = TRUE, repos = repos, stderr = "2>&1", - block_callback = if (!quiet) block_callback(), - spinner = !quiet, + block_callback = if (!quiet) detect_callback(), + spinner = !quiet && should_add_spinner(), timeout = timeout, fail_on_status = FALSE )