Consider
printf "%-40s : %s\n", $_->@* for @rows;
The intention is to print a nice neat table on the terminal.
This works fine in ASCII but gets all confused if any ->[0] element
contains Unicode text. While Perl will count in Unicode codepoints,
this won't help if there are combining chars (because combining chars
count as codepoints but do not consume terminal columns), or if there
are any emoji or other double-width characters (because these single
graphemes count as two columns).
I propose a new printf flag, perhaps `|`, to tell (s)printf to count
these strings by terminal width instead. Thus
printf "%-|40s : %s\n", $_->@* for @rows;
would now print a neat table even in the presence of Weird Unicode.
If no objections I'll write up an RFC.
--
Paul "LeoNerd" Evans
leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
printf "%-40s : %s\n", $_->@* for @rows;
The intention is to print a nice neat table on the terminal.
This works fine in ASCII but gets all confused if any ->[0] element
contains Unicode text. While Perl will count in Unicode codepoints,
this won't help if there are combining chars (because combining chars
count as codepoints but do not consume terminal columns), or if there
are any emoji or other double-width characters (because these single
graphemes count as two columns).
I propose a new printf flag, perhaps `|`, to tell (s)printf to count
these strings by terminal width instead. Thus
printf "%-|40s : %s\n", $_->@* for @rows;
would now print a neat table even in the presence of Weird Unicode.
If no objections I'll write up an RFC.
--
Paul "LeoNerd" Evans
leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/