Showing 5 of 6 files from the diff.

@@ -1,6 +1,6 @@
Loading
1 1
2 2
check_for_private_lib <- function(
3 -
    pkgs = c("crayon", "ps", "processx", "callr")) {
3 +
    pkgs = c("glue", "cli", "ps", "processx", "callr")) {
4 4
  lib <- private_lib_dir()
5 5
  if (!file.exists(lib) || !is_dir(lib)) stop("No private lib")
6 6
  for (pkg in pkgs) {

@@ -19,9 +19,10 @@
Loading
19 19
  } else if (worker == "true") {
20 20
    ## In the worker process
21 21
    Sys.setenv("R_PKG_PKG_WORKER" = "false")
22 +
    # We don't use the env vars that cli supports, on purpose, because
23 +
    # they are inherited in the subprocess of the subprocess
22 24
    options(
23 -
      crayon.enabled = (Sys.getenv("R_PKG_PKG_COLORS") == "TRUE"),
24 -
      crayon.colors = as.numeric(Sys.getenv("R_PKG_PKG_NUM_COLORS", "1")),
25 +
      cli.num_colors = as.numeric(Sys.getenv("R_PKG_NUM_COLORS", "1")),
25 26
      rlib_interactive = (Sys.getenv("R_PKG_INTERACTIVE") == "TRUE"),
26 27
      cli.dynamic = (Sys.getenv("R_PKG_DYNAMIC_TTY") == "TRUE")
27 28
    )

@@ -22,7 +22,7 @@
Loading
22 22
#   the error, e.g. `.Last.error$trace`. The trace of the last error is
23 23
#   also at `.Last.error.trace`.
24 24
# - Can merge errors and traces across multiple processes.
25 -
# - Pretty-print errors and traces, if the crayon package is loaded.
25 +
# - Pretty-print errors and traces, if the cli package is loaded.
26 26
# - Automatically hides uninformative parts of the stack trace when
27 27
#   printing.
28 28
#
@@ -85,6 +85,10 @@
Loading
85 85
#
86 86
# * Add the `call` argument to `catch_rethrow()` and `rethrow()`, to be
87 87
#   able to omit calls.
88 +
#
89 +
# ### 1.2.3 -- 2021-03-06
90 +
#
91 +
# * Use cli instead of crayon
88 92
89 93
err <- local({
90 94
@@ -590,8 +594,8 @@
Loading
590 594
  }
591 595
592 596
  capture_output <- function(expr) {
593 -
    if (has_crayon()) {
594 -
      opts <- options(crayon.enabled = crayon::has_color())
597 +
    if (has_cli()) {
598 +
      opts <- options(cli.num_colors = cli::num_ansi_colors())
595 599
      on.exit(options(opts), add = TRUE)
596 600
    }
597 601
@@ -698,22 +702,22 @@
Loading
698 702
699 703
  # -- printing, styles -------------------------------------------------
700 704
701 -
  has_crayon <- function() "crayon" %in% loadedNamespaces()
705 +
  has_cli <- function() "cli" %in% loadedNamespaces()
702 706
703 707
  style_numbers <- function(x) {
704 -
    if (has_crayon()) crayon::silver(x) else x
708 +
    if (has_cli()) cli::col_silver(x) else x
705 709
  }
706 710
707 711
  style_advice <- function(x) {
708 -
    if (has_crayon()) crayon::silver(x) else x
712 +
    if (has_cli()) cli::col_silver(x) else x
709 713
  }
710 714
711 715
  style_srcref <- function(x) {
712 -
    if (has_crayon()) crayon::italic(crayon::cyan(x))
716 +
    if (has_cli()) cli::style_italic(cli::col_cyan(x))
713 717
  }
714 718
715 719
  style_error <- function(x) {
716 -
    if (has_crayon()) crayon::bold(crayon::red(x)) else x
720 +
    if (has_cli()) cli::style_bold(cli::col_ed(x)) else x
717 721
  }
718 722
719 723
  style_error_msg <- function(x) {
@@ -726,15 +730,15 @@
Loading
726 730
  }
727 731
728 732
  style_process <- function(x) {
729 -
    if (has_crayon()) crayon::bold(x) else x
733 +
    if (has_cli()) cli::style_bold(x) else x
730 734
  }
731 735
732 736
  style_call <- function(x) {
733 -
    if (!has_crayon()) return(x)
737 +
    if (!has_cli()) return(x)
734 738
    call <- sub("^([^(]+)[(].*$", "\\1", x)
735 739
    rest <- sub("^[^(]+([(].*)$", "\\1", x)
736 740
    if (call == x || rest == x) return(x)
737 -
    paste0(crayon::yellow(call), rest)
741 +
    paste0(cli::col_yellow(call), rest)
738 742
  }
739 743
740 744
  err_env <- environment()

@@ -262,73 +262,3 @@
Loading
262 262
na_omit <- function(x) {
263 263
  x[!is.na(x)]
264 264
}
265 -
266 -
is_dynamic_tty <- function(stream = stdout()) {
267 -
  ## Option?
268 -
  if (!is.null(x <- getOption("cli.dynamic"))) {
269 -
    return(isTRUE(x))
270 -
  }
271 -
272 -
  ## Env var?
273 -
  if ((x <- Sys.getenv("R_CLI_DYNAMIC", "")) != "") {
274 -
    return(isTRUE(as.logical(x)))
275 -
  }
276 -
277 -
  ## Autodetect...
278 -
  ## RGui has isatty(stdout()) and isatty(stderr()), so we don't need
279 -
  ## to check that explicitly
280 -
  isatty(stream) ||
281 -
    is_rstudio_dynamic_tty(stream) ||
282 -
    is_rapp_stdx(stream) ||
283 -
    is_rkward_stdx(stream)
284 -
}
285 -
286 -
is_rstudio_dynamic_tty <- function(stream) {
287 -
  rstudio$detect()[["dynamic_tty"]] &&
288 -
    (is_stdout(stream) || is_stderr(stream))
289 -
}
290 -
291 -
is_stdout <- function(stream) {
292 -
  identical(stream, stdout()) && sink.number() == 0
293 -
}
294 -
295 -
is_stderr <- function(stream) {
296 -
  identical(stream, stderr()) && sink.number("message") == 2
297 -
}
298 -
299 -
is_rapp <- function() {
300 -
  Sys.getenv("R_GUI_APP_VERSION") != ""
301 -
}
302 -
303 -
is_rapp_stdx <- function(stream) {
304 -
  interactive() &&
305 -
    is_rapp() &&
306 -
    (is_stdout(stream) || is_stderr(stream))
307 -
}
308 -
309 -
is_rkward <- function() {
310 -
  "rkward" %in% (.packages())
311 -
}
312 -
313 -
is_rkward_stdx <- function(stream) {
314 -
  interactive() &&
315 -
    is_rkward() &&
316 -
    (is_stdout(stream) || is_stderr(stream))
317 -
}
318 -
319 -
myseq <- function(from, to, by = 1) {
320 -
  stopifnot(by != 0)
321 -
  if (by > 0) {
322 -
    if (to < from) {
323 -
      integer()
324 -
    } else {
325 -
      seq(from, to, by = by)
326 -
    }
327 -
  } else {
328 -
    if (to > from) {
329 -
      integer()
330 -
    } else {
331 -
      seq(from, to, by = by)
332 -
    }
333 -
  }
334 -
}

@@ -84,14 +84,13 @@
Loading
84 84
  get_private_lib(create = create)
85 85
  load_private_packages(create = create)
86 86
  callr <- pkg_data$ns$callr
87 -
  crayon <- pkg_data$ns$crayon
87 +
  cli <- pkg_data$ns$cli
88 88
  opts <- callr$r_session_options(stderr = NULL,  stdout = NULL)
89 89
  opts$env <- c(
90 90
    opts$env, R_PKG_SHOW_PROGRESS = is_verbose(),
91 91
    R_PKG_PKG_WORKER = "true",
92 -
    R_PKG_PKG_COLORS = as.character(crayon$has_color()),
93 -
    R_PKG_PKG_NUM_COLORS = as.character(crayon$num_colors()),
94 -
    R_PKG_DYNAMIC_TTY = is_dynamic_tty()
92 +
    R_PKG_NUM_COLORS = as.character(cli$num_ansi_colors()),
93 +
    R_PKG_DYNAMIC_TTY = cli$is_dynamic_tty()
95 94
  )
96 95
  pkg_data$remote <- callr$r_session$new(opts, wait = FALSE)
97 96
}
@@ -123,7 +122,8 @@
Loading
123 122
}
124 123
125 124
load_private_packages <- function(create = TRUE) {
126 -
  load_private_package("crayon", create = create)
125 +
  load_private_package("glue", create = create)
126 +
  load_private_package("cli", create = create)
127 127
  load_private_package("ps", create = create)
128 128
  load_private_package("processx", "c_", create = create)
129 129
  load_private_package("callr", create = create)
@@ -263,9 +263,9 @@
Loading
263 263
## This is a workaround for R CMD check
264 264
265 265
r_cmd_check_fix <- function() {
266 +
  glue::glue
266 267
  callr::r
267 268
  cli::rule
268 -
  crayon::red
269 269
  filelock::lock
270 270
  invisible()
271 271
}
Files Coverage
R 13.44%
Project Totals (24 files) 13.44%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
        informational: true
10
    patch:
11
      default:
12
        target: auto
13
        threshold: 1%
14
        informational: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading