shlomif / Text-Table

CPAN Distribution to render text / ASCII-art / Unicode tables
https://metacpan.org/release/Text-Table
ISC License
4 stars 6 forks source link

"align" property on columns is being ignored #2

Open shlomif opened 8 years ago

shlomif commented 8 years ago

Just so I won't forget and misplace this bug. Read the email below:

> 
> 
> Hi.
> I cant seem to get the module to respect right,left,center request for the
> data being presented in the very first column. Columns other than the first
> seem to respect the aliment request just fine.
> 
> Here is the sample code...
> 
> @pValLst=(0, 0.0, 1.2345, 2.345, 3.45, 4.5, 1.2345e-2, 1.2345e2, "fail",
> "na", "FAIL", "NA");
> 
> my $tb = Text::Table->new("paramName\n&center", "value1\n&center",
> "value2\n&center");
>    foreach $pVal (@pValLst) {
>     $tb->add("label", "data1", "data2");
>    }
> 
>    print $tb;
> 
> The result is that that the word "label" under header "paramName" wont
> center align. However the words "data1" and "data2" do center align under
> headers "value1" & "value2"
> 
> Any ideas?  

That doesn't seem to be the case here. It seems that the "align" property of the
columns (which is also specifiable as the "&" lines) is getting completely
ignored in favour of "align_title", which in earlier versions of Text-Table was
always 'left'. This is a serious and ancient bug that in large part happened
due to lack of testing. See:

< SHELL >

shlomif@telaviv1:~$ cat test-Text-Table-1.pl
#!/usr/bin/perl

use strict;
use warnings;

use Text::Table;

my @pValLst=(0, 0.0, 1.2345, 2.345, 3.45, 4.5, 1.2345e-2, 1.2345e2, "fail",
"na", "FAIL", "NA");

# my $tb = Text::Table->new("paramName\n&center\n",
"value1234567890\n&center\n", "value2\n&center"); my $tb =
Text::Table->new( { title => "paramName", align_title => 'center'}, { title =>
"value1234567890", align_title => 'center'}, { title => "value2", align_title
=> 'center'}); foreach my $pVal (@pValLst) { $tb->add("label", "data1",  
"data2"); } 
print $tb;                                                                      
shlomif@telaviv1:~$ perl test-Text-Table-1.pl                                
paramName value1234567890 value2                                                
  label        data1       data2                                                
  label        data1       data2                                                
  label        data1       data2                                                
  label        data1       data2                                                
  label        data1       data2
  label        data1       data2
  label        data1       data2
  label        data1       data2
  label        data1       data2
  label        data1       data2
  label        data1       data2
  label        data1       data2
shlomif@telaviv1:~$ cat test-Text-Table-2.pl
#!/usr/bin/perl

use strict;
use warnings;

use Text::Table;

my @pValLst=(0, 0.0, 1.2345, 2.345, 3.45, 4.5, 1.2345e-2, 1.2345e2, "fail",
"na", "FAIL", "NA");

# my $tb = Text::Table->new("paramName\n&center\n",
"value1234567890\n&center\n", "value2\n&center"); my $tb =
Text::Table->new( { title => "paramName", align => 'center'}, { title =>
"value1234567890", align => 'center'}, { title => "value2", align =>
'center'}); foreach my $pVal (@pValLst) { $tb->add("label", "data1", "data2"); }

print $tb;
shlomif@telaviv1:~$ perl test-Text-Table-2.pl
paramName value1234567890 value2
label     data1           data2 
label     data1           data2 
label     data1           data2 
label     data1           data2 
label     data1           data2 
label     data1           data2 
label     data1           data2 
label     data1           data2 
label     data1           data2 
label     data1           data2 
label     data1           data2 
label     data1           data2 
shlomif@telaviv1:~$ 

< / SHELL >

It's not really a priority for me to fix Text-Table this way, but I'll try to
dedicate some time to it. In the meanwhile pull-requests (with tests) to
https://github.com/shlomif/Text-Table are welcome.

Regards,

    Shlomi Fish