Skip Menu |
 

This queue is for tickets about the Text-Tabs+Wrap CPAN distribution.

Report information
The Basics
Id: 129144
Status: open
Priority: 0/
Queue: Text-Tabs+Wrap

People
Owner: Nobody in particular
Requestors: leonerd-cpan [...] leonerd.org.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 2013.0523
Fixed in: (no value)



Subject: Text::Wrap counts in graphemes, not columns
Download (untitled) / with headers
text/plain 979b
Some unicode grapheme clusters are wider than others. Not all occupy a single column. By setting $columns to a small value the effect can easily be seen. First a comparison using a regular ASCII letter. Setting $columns=5 asks for atmost 4 columns of output per line. Wrapping a sequence of 10 "A"s gives us two lines of 4 and one line of the remaining 2: $ perl -CS -Mstrict -MText::Wrap -E'$Text::Wrap::columns=5; say wrap("", "", "A"x10)' AAAA AAAA AA This was expected. But now using a "full-width" emoji character such as 'šŸ™‚' [U+1f642] - SLIGHTLY SMILING FACE we get: $ perl -CS -Mstrict -MText::Wrap -E'$Text::Wrap::columns=5; say wrap("", "", "\x{1F642}"x10)' šŸ™‚šŸ™‚šŸ™‚šŸ™‚ šŸ™‚šŸ™‚šŸ™‚šŸ™‚ šŸ™‚šŸ™‚ This is unexpected; each line of output occupies 8 columns, not the 4 we had asked for. If wrap() was counting in columns we'd get five lines of two faces each; a.la: šŸ™‚šŸ™‚ šŸ™‚šŸ™‚ šŸ™‚šŸ™‚ šŸ™‚šŸ™‚ šŸ™‚šŸ™‚ -- Paul Evans
Download (untitled) / with headers
text/plain 1.4k
On 2019-04-12 09:13:23, PEVANS wrote: Show quoted text
> Some unicode grapheme clusters are wider than others. Not all occupy a > single column. > > By setting $columns to a small value the effect can easily be seen. > First a comparison using a regular ASCII letter. Setting $columns=5 > asks for atmost 4 columns of output per line. Wrapping a sequence of > 10 "A"s gives us two lines of 4 and one line of the remaining 2: > > $ perl -CS -Mstrict -MText::Wrap -E'$Text::Wrap::columns=5; say > wrap("", "", "A"x10)' > AAAA > AAAA > AA > > This was expected. > > But now using a "full-width" emoji character such as > > 'šŸ™‚' [U+1f642] - SLIGHTLY SMILING FACE > > we get: > > $ perl -CS -Mstrict -MText::Wrap -E'$Text::Wrap::columns=5; say > wrap("", "", "\x{1F642}"x10)' > šŸ™‚šŸ™‚šŸ™‚šŸ™‚ > šŸ™‚šŸ™‚šŸ™‚šŸ™‚ > šŸ™‚šŸ™‚ > > This is unexpected; each line of output occupies 8 columns, not the 4 > we had asked for. If wrap() was counting in columns we'd get five > lines of two faces each; a.la: > > šŸ™‚šŸ™‚ > šŸ™‚šŸ™‚ > šŸ™‚šŸ™‚ > šŸ™‚šŸ™‚ > šŸ™‚šŸ™‚
Possibly related: some escape sequences (e.g. color escapes produced by Term::ANSIColor) should probably be treated as zero length, otherwise wrapping happens too early/too often: $ perl -MTerm::ANSIColor '-MText::Wrap=wrap,$columns' -E '$columns=10; $txt = "123 456 789 ABC"; say wrap("", "", $txt); say wrap("", "", colored(["red on_black"], $txt))' 123 456 789 ABC 1 23 456 789 ABC


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.