Skip to content

Respect width in ansi_collapse(style = "head") when no element fits - #843

Merged
gaborcsardi merged 1 commit into
r-lib:mainfrom
taekop:fix/ansi-collapse-head-width
Oct 2, 2026
Merged

gaborcsardi merged 1 commit into
r-lib:mainfrom
taekop:fix/ansi-collapse-head-width

Conversation

@taekop

@taekop taekop commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

ansi_collapse(style = "head") can return a string wider than width when not even the first element fits. In that branch the first element was trimmed to width and the ellipsis was then appended, so the result was width plus the ellipsis width.

x <- c("loooooooong", "healthy live the Penguin")
ansi_collapse(x, width = 2, style = "head")
#> "lo…"   (3 wide)
ansi_collapse(x, width = 3, style = "head")
#> "loo…"  (4 wide)

The element is now trimmed to width - ellipsis width, giving "l…" and "lo…". Output that already fit within width is unchanged.

Closes #570

@gaborcsardi
gaborcsardi merged commit 5bfebe1 into r-lib:main Oct 2, 2026
10 of 11 checks passed
@gaborcsardi

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent result width for ansi_collapse(style = "head")

2 participants