Skip Menu |
 

This queue is for tickets about the Text-ASCIITable CPAN distribution.

Report information
The Basics
Id: 77462
Status: rejected
Priority: 0/
Queue: Text-ASCIITable

People
Owner: Nobody in particular
Requestors: purification [...] ukr.net
Cc:
AdminCc:

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



Download (untitled) / with headers
text/plain 1.8k
Table layout breaks when added rows contain unicode characters: $ cat tab.pl #!/usr/bin/perl use strict; use warnings; use Text::ASCIITable; my $t = Text::ASCIITable->new({ headingText => 'test table' }); $t->setCols('Id','Name','Price'); $t->addRow(1,'黒黒黒黒黒黒黒',24.4); $t->addRow(2,'ラララララ', 5.2); $t->addRow(3,'実行実行実行',12.3); $t->addRowLine(); $t->addRow('','Total',57.9); print $t; $ ./tab.pl .----------------------. | test table | +----+---------+-------+ | Id | Name | Price | +----+---------+-------+ | 1 | 黒黒黒黒黒黒黒 | 24.4 | | 2 | ラララララ | 5.2 | | 3 | 実行実行実行 | 12.3 | +----+---------+-------+ | | Total | 57.9 | '----+---------+-------' It can be fixed if instead of length() Text::ASCIITable::count() used columns() from Unicode::GCString Simple proof of concept: $ cat tab.pl #!/usr/bin/perl use strict; use warnings; use Text::ASCIITable; use Unicode::GCString; {no warnings 'redefine'; sub Text::ASCIITable::count { my ($self, $str) = @_; my $gc = Unicode::GCString->new(Encode::decode('UTF-8',$str)); return $gc->columns; }} my $t = Text::ASCIITable->new({ headingText => 'test table' }); $t->setCols('Id','Name','Price'); $t->addRow(1,'黒黒黒黒黒黒黒',24.4); $t->addRow(2,'ラララララ', 5.2); $t->addRow(3,'実行実行実行',12.3); $t->addRowLine(); $t->addRow('','Total',57.9); print $t; $ ./tab.pl .-----------------------------. | test table | +----+----------------+-------+ | Id | Name | Price | +----+----------------+-------+ | 1 | 黒黒黒黒黒黒黒 | 24.4 | | 2 | ラララララ | 5.2 | | 3 | 実行実行実行 | 12.3 | +----+----------------+-------+ | | Total | 57.9 | '----+----------------+-------' Table looks correct in terminal.
From: purification [...] ukr.net
The same issue also applies to table heading text.
Download (untitled) / with headers
text/plain 920b
On Sat May 26 23:12:03 2012, Lumiera wrote: Show quoted text
> Table layout breaks when added rows contain unicode characters: > > {no warnings 'redefine'; > sub Text::ASCIITable::count > { > my ($self, $str) = @_; > my $gc = Unicode::GCString->new(Encode::decode('UTF-8',$str)); > return $gc->columns; > }} >
You don't need to redefine the function. Text::ASCIITable already has a function for defining your own 'count code' as the documentation states: User-defined subroutines for counting This is a feature to use if you are not happy with the internal allowHTML or allowANSI support. Given is an example of how you make a count-callback that makes ASCIITable support ANSI codes inside the table. (would make the same result as setting allowANSI to 1) $t->setOptions('cb_count',\&myallowansi_cb); sub myallowansi_cb { $_=shift; s/\33\[(\d+(;\d+)?)?[musfwhojBCDHRJK]//g; return length($_); }
Can be solved with $t->setOptions('cb_count', CODE)


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.