Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use textwidth for string display truncation #55442

Merged
merged 6 commits into from
Oct 24, 2024
Merged

Conversation

stevengj
Copy link
Member

@stevengj stevengj commented Aug 10, 2024

This uses the new textwidth-based string-truncation functions from #55351 (with some additional refactoring) for truncating strings in the 3-argument show, replacing the codepoint-based method implemented by @StefanKarpinski in #40736.

It makes a big difference when displaying strings that have width-2 or width-0 characters. For example, in the previous implementation, you got very unequal-length displays for different character widths:

julia> "x"^1000 # width-1 chars
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"  459 bytes  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

julia> ""^1000 # contains width-0 chars
"x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂"  2190 bytes  "x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂"

julia> "🍕"^1000 # width-2 chars
"🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕" ⋯ 1840 bytes ⋯ "🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕"

Now, you get:

julia> "x"^1000 # width-1 chars
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"  460 bytes  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

julia> ""^1000 # contains width-0 chars
"x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂" ⋯ 1378 bytes ⋯ "̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂x̂"

julia> "🍕"^1000 # width-2 chars
"🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕" ⋯ 2920 bytes ⋯ "🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕🍕"

(They look more equal in my terminal. In my browser, 🍕 is slightly more than 2 columns wide 😕.)

@stevengj stevengj added unicode Related to unicode characters and encodings strings "Strings!" display and printing Aesthetics and correctness of printed representations of objects. labels Aug 10, 2024
@fingolfin fingolfin merged commit bc66047 into master Oct 24, 2024
9 checks passed
@fingolfin fingolfin deleted the ctruncate_string_show branch October 24, 2024 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects. strings "Strings!" unicode Related to unicode characters and encodings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants