Skip to content

Commit

Permalink
Use cli instead of fansi. (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy authored Jul 24, 2024
1 parent ff21cbb commit 43c9113
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Depends:
Imports:
cli,
diffobj (>= 0.3.4),
fansi,
glue,
methods,
rematch2,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# waldo (development version)

* waldo no longer imports fansi (@olivroy, #192).

# waldo 0.5.2

* Fixes for upcoming R-devel changes.
Expand Down
8 changes: 4 additions & 4 deletions R/diff.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
Expand All @@ -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"))
}

Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 43c9113

Please sign in to comment.