From d1233367d656f1cf26985d722fdb65139e8023bb Mon Sep 17 00:00:00 2001 From: olivroy Date: Tue, 2 Jul 2024 12:34:58 -0400 Subject: [PATCH] Use cli instead of fansi. --- DESCRIPTION | 1 - NEWS.md | 2 ++ R/diff.R | 8 ++++---- R/utils.R | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 77bceca..0ec19b7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,6 @@ Depends: Imports: cli, diffobj (>= 0.3.4), - fansi, glue, methods, rematch2, diff --git a/NEWS.md b/NEWS.md index 0931d9d..f814799 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # waldo (development version) +* waldo no longer imports fansi (@olivroy, #192). + # waldo 0.5.2 * Fixes for upcoming R-devel changes. diff --git a/R/diff.R b/R/diff.R index ebea0b8..c333d65 100644 --- a/R/diff.R +++ b/R/diff.R @@ -140,10 +140,10 @@ format_diff_matrix <- function(diff, x, y, paths, mat_out <- mat_out[, seq_len(n + 1)] mat_out <- cbind(mat_out, c(paste0("and ", n_trunc, " more..."), "...")) } - out <- apply(mat_out, 2, fansi_align, justify = justify) + out <- apply(mat_out, 2, ansi_align, justify = justify) rows <- apply(out, 1, paste, collapse = " ") - if (fansi::nchar_ctl(rows[[1]]) <= width) { + if (cli::ansi_nchar(rows[[1]]) <= width) { return(paste0(rows, collapse = "\n")) } } @@ -168,10 +168,10 @@ format_diff_matrix <- function(diff, x, y, paths, format(c("", y_idx_out), justify = "left") ) - out <- apply(mat_out, 1, fansi_align, justify = "left") + out <- apply(mat_out, 1, ansi_align, justify = "left") rows <- apply(out, 1, paste, collapse = " ") - if (fansi::nchar_ctl(rows[[1]]) <= width) { + if (cli::ansi_nchar(rows[[1]]) <= width) { return(paste0(rows, collapse = "\n")) } diff --git a/R/utils.R b/R/utils.R index 94befe4..cf0f3e3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -122,10 +122,10 @@ if (getRversion() < "3.3.0") { } } -fansi_align <- function(x, width = NULL, justify = c("left", "right")) { +ansi_align <- function(x, width = NULL, justify = c("left", "right")) { justify <- arg_match(justify) - nchar <- fansi::nchar_ctl(x) + nchar <- cli::ansi_nchar(x) width <- width %||% max(nchar) padding <- strrep(" ", pmax(0, width - nchar))