Skip to content

Commit

Permalink
Do not use \r if not a dynamic tty
Browse files Browse the repository at this point in the history
Closes #94.
  • Loading branch information
gaborcsardi committed May 7, 2019
1 parent e9c4f5b commit 432958a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Suggests:
testthat
Imports:
callr (>= 3.1.1.9000),
cli,
cli (>= 1.1.0),
crayon,
desc (>= 1.2.0),
digest,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 24 additions & 0 deletions R/callback.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
4 changes: 2 additions & 2 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 432958a

Please # to comment.