From cc05013833976d298779fc5341d9989c82ced85e Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Fri, 3 Oct 2025 14:10:05 -0400 Subject: [PATCH] Fix ansi_strwrap() issue with \r in the string --- NEWS.md | 1 + R/ansiex.R | 11 ++++++----- tests/testthat/test-ansiex.R | 5 +++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index e1a1cf4f..23ebb9e7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ * New `{.num}` and `{.bytes}` inline styles to format numbers and bytes (@m-muecke, #644, #588, #643). +* Fix issues with `ansi_strwrap()` having `\r` in the string (#667) # cli 3.6.5 diff --git a/R/ansiex.R b/R/ansiex.R index 7accebe8..5fe2674a 100644 --- a/R/ansiex.R +++ b/R/ansiex.R @@ -589,7 +589,7 @@ ansi_strwrap <- function( # First we need to remove the multiple spaces, to make it easier to # map the strings later on. We do this per paragraph, to keep paragraphs. - pars <- strsplit(x, "\n[ \t\n]*\n", perl = TRUE) + pars <- strsplit(x, "\r?\n[ \t\n\r]*\r?\n", perl = TRUE) pars <- lapply(pars, ansi_trimws) # Within paragraphs, replace multiple spaces with one, except when there @@ -598,11 +598,11 @@ ansi_strwrap <- function( # some is outside, but for now, we'll live with this limitation. pars <- lapply(pars, function(s) { # First replace multiple spaces that are not at the end of a sentence - s <- gsub("(?