Skip to content

Commit

Permalink
Drop crayon dependency
Browse files Browse the repository at this point in the history
Use cli instead.
  • Loading branch information
gaborcsardi committed Nov 20, 2023
1 parent a1ac687 commit 3ba537a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ Description: Provides functions used to build R packages. Locates
License: MIT + file LICENSE
URL: https://github.com/r-lib/pkgbuild, https://pkgbuild.r-lib.org
BugReports: https://github.com/r-lib/pkgbuild/issues
Depends:
Depends:
R (>= 3.5)
Imports:
callr (>= 3.2.0),
cli (>= 3.4.0),
crayon,
desc,
prettyunits,
processx,
Expand Down
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ importFrom(R6,R6Class)
importFrom(callr,rcmd_process)
importFrom(callr,rcmd_process_options)
importFrom(cli,symbol)
importFrom(crayon,bold)
importFrom(crayon,green)
importFrom(crayon,make_style)
importFrom(crayon,red)
importFrom(prettyunits,pretty_dt)
importFrom(utils,head)
importFrom(utils,tail)
6 changes: 4 additions & 2 deletions R/compiler-flags.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ compiler_flags <- function(debug = FALSE) {
)
}

if (crayon::has_color() && has_compiler_colored_diagnostics()) {
if (cli::num_ansi_colors() > 1 && has_compiler_colored_diagnostics()) {
flags <- c(
"CFLAGS", "CXXFLAGS", "CXX11FLAGS",
"CXX14FLAGS", "CXX17FLAGS", "CXX20FLAGS"
Expand All @@ -60,7 +60,9 @@ compiler_flags <- function(debug = FALSE) {

has_compiler_colored_diagnostics <- function() {
val <- interpret_envvar_flag("PKG_BUILD_COLOR_DIAGNOSTICS", NA_character_)
if (!is.na(val)) return(val)
if (!is.na(val)) {
return(val)
}

if (cache_exists("has_compiler_colored_diagnostics")) {
return(cache_get("has_compiler_colored_diagnostics"))
Expand Down
14 changes: 6 additions & 8 deletions R/styles.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#' @importFrom crayon red green make_style bold

# This is from https://github.com/r-lib/rcmdcheck/blob/7ee14764c2b17ee2c2f4131a9e19d1b56a66ed0f/R/styles.R
style <- function(..., sep = "") {
args <- list(...)
st <- names(args)

styles <- list(
"ok" = green,
"note" = make_style("orange"),
"warn" = make_style("orange")$ bold,
"err" = red,
"pale" = make_style("darkgrey"),
"timing" = make_style("cyan")
"ok" = cli::col_green,
"note" = cli::make_ansi_style("orange"),
"warn" = function(x) cli::style_bold(cli::make_ansi_style("orange")(x)),
"err" = cli::col_red,
"pale" = cli::make_ansi_style("darkgrey"),
"timing" = cli::make_ansi_style("cyan")
)

nms <- names(args)
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/_snaps/style.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# style

Code
cat(style(ok = "OK", "\n", note = "NOTE", "\n", warn = "WARN", "\n", err = "ERROR",
"\n", pale = "Not important", "\n", timing = "[1m]", "\n"))
Output
OK
NOTE
WARN
ERROR
Not important
[1m]

13 changes: 13 additions & 0 deletions tests/testthat/test-style.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test_that("style", {
withr::local_options(cli.num_colors = 256)
expect_snapshot(
cat(style(
ok = "OK", "\n",
note = "NOTE", "\n",
warn = "WARN", "\n",
err = "ERROR", "\n",
pale = "Not important", "\n",
timing = "[1m]", "\n"
))
)
})

0 comments on commit 3ba537a

Please sign in to comment.