r204 - in packages/libtext-formattable-perl/trunk: . debian lib/Text
Gunnar Wolf
gwolf@haydn.debian.org
Fri, 11 Jun 2004 16:37:50 -0600
Author: gwolf
Date: 2004-06-11 16:37:47 -0600 (Fri, 11 Jun 2004)
New Revision: 204
Added:
packages/libtext-formattable-perl/trunk/META.yml
Modified:
packages/libtext-formattable-perl/trunk/Changes
packages/libtext-formattable-perl/trunk/MANIFEST
packages/libtext-formattable-perl/trunk/debian/changelog
packages/libtext-formattable-perl/trunk/lib/Text/FormatTable.pm
Log:
Upgrading to 1.01
Modified: packages/libtext-formattable-perl/trunk/Changes
===================================================================
--- packages/libtext-formattable-perl/trunk/Changes 2004-06-11 21:58:17 UTC (rev 203)
+++ packages/libtext-formattable-perl/trunk/Changes 2004-06-11 22:37:47 UTC (rev 204)
@@ -1,7 +1,16 @@
Revision history for Perl extension Text::FormatTable.
+2004-06-10
+ * Fixed column width and bottom alignment (Veselin Slavov)
+
+2003-01-28
+ * add Text::ASCIITable to SEE ALSO
+
2002-11-05
+ * nicely format space rules
+2002-11-05
+
* released 1.00 (code seems to be stable, no problems since 1.5 years)
* small documentation fix
Modified: packages/libtext-formattable-perl/trunk/MANIFEST
===================================================================
--- packages/libtext-formattable-perl/trunk/MANIFEST 2004-06-11 21:58:17 UTC (rev 203)
+++ packages/libtext-formattable-perl/trunk/MANIFEST 2004-06-11 22:37:47 UTC (rev 204)
@@ -5,3 +5,4 @@
lib/Text/FormatTable.pm
example.pl
test.pl
+META.yml Module meta-data (added by MakeMaker)
Copied: packages/libtext-formattable-perl/trunk/META.yml (from rev 202, packages/libtext-formattable-perl/branches/upstream/current/META.yml)
Modified: packages/libtext-formattable-perl/trunk/debian/changelog
===================================================================
--- packages/libtext-formattable-perl/trunk/debian/changelog 2004-06-11 21:58:17 UTC (rev 203)
+++ packages/libtext-formattable-perl/trunk/debian/changelog 2004-06-11 22:37:47 UTC (rev 204)
@@ -1,3 +1,9 @@
+libtext-formattable-perl (1.01-1) unstable; urgency=low
+
+ * New upstream release
+
+ -- Gunnar Wolf <gwolf@debian.org> Fri, 11 Jun 2004 16:42:08 -0500
+
libtext-formattable-perl (1.00-2) unstable; urgency=low
* Initial Debian upload (Closes: #253641)
Modified: packages/libtext-formattable-perl/trunk/lib/Text/FormatTable.pm
===================================================================
--- packages/libtext-formattable-perl/trunk/lib/Text/FormatTable.pm 2004-06-11 21:58:17 UTC (rev 203)
+++ packages/libtext-formattable-perl/trunk/lib/Text/FormatTable.pm 2004-06-11 22:37:47 UTC (rev 204)
@@ -4,7 +4,7 @@
use strict;
use vars qw($VERSION);
-$VERSION = '1.00';
+$VERSION = '1.01';
=head1 NAME
@@ -21,7 +21,7 @@
=head1 DESCRIPTION
Text::FormatTable renders simple tables as text. You pass to the constructor
-(I<new>) a table format specification similar to LaTeX (e.g. C<r|l|l>) and you
+(I<new>) a table format specification similar to LaTeX (e.g. C<r|l|5l|R|20L>) and you
call methods to fill the table data and insert rules. After the data is filled,
you call the I<render> method and the table gets formatted as text.
@@ -89,12 +89,29 @@
}
elsif($t =~ /(.{$width,}?\S)\s+(\S.*?)$/) {
# nearest space > width
- push @t, $1;
- push @t, $2;
+ if ( length $1 > $width_m1 )
+ {
+ # hard hyphanation
+ my $left = substr($1,0,$width);
+ my $right= substr($1,$width);
+
+ push @t, $left;
+ push @t, $right;
+ push @t, $2;
+ }
+ else
+ {
+ push @t, $1;
+ push @t, $2;
+ }
}
else {
- # can't break
- push @t, $t;
+ # hard hyphanation
+ my $left = substr($t,0,$width);
+ my $right= substr($t,$width);
+
+ push @t, $left;
+ push @t, $right;
return \@t;
}
}
@@ -132,16 +149,26 @@
{
my ($self, $width) = @_;
my @widths = ();
-
# calculate min and max widths for each column
for my $r (@{$self->{data}})
{
$r->[0] eq 'data' or $r->[0] eq 'head' or next;
my $cn=0;
my ($max, $min) = (0,0);
+
for my $c (@{$r->[1]}) {
- $widths[$cn][0] = _max($widths[$cn][0], _min_width $c);
- $widths[$cn][1] = _max($widths[$cn][1], _max_width $c);
+
+ if ( $self->{fixed_widths}[$cn] )
+ {
+ # fixed width
+ $widths[$cn][0] = $self->{fixed_widths}[$cn];
+ $widths[$cn][1] = $self->{fixed_widths}[$cn];
+ }
+ else
+ {
+ $widths[$cn][0] = _max($widths[$cn][0], _min_width $c);
+ $widths[$cn][1] = _max($widths[$cn][1], _max_width $c);
+ }
$cn++;
}
}
@@ -220,12 +247,18 @@
my ($col,$data_col) = (0,0);
for my $c (@{$self->{format}}) {
if($c->[0] eq '|') {
- $out .= $char eq '-' ? '+' : $char;
+ if ($char eq '-') { $out .= '+' }
+ elsif($char eq ' ') { $out .= '|' }
+ else { $out .= $char }
}
elsif($c->[0] eq ' ') {
$out .= $char;
}
- elsif($c->[0] eq 'l' or $c->[0] eq 'r') {
+ elsif( $c->[0] eq 'l'
+ or $c->[0] eq 'L'
+ or $c->[0] eq 'r'
+ or $c->[0] eq 'R'
+ ) {
$out .= ($char)x($self->{widths}[$data_col]);
$data_col++;
}
@@ -243,19 +276,22 @@
# render every column and find out number of lines
my ($col, $data_col) = (0,0);
my $lines=0;
+ my @rows_in_column;
for my $c (@{$self->{format}}) {
- if($c->[0] eq 'l') {
+ if( ($c->[0] eq 'l') or ($c->[0] eq 'L') ) {
my $lb = _l_box($self->{widths}[$data_col], $data->[$data_col]);
$rdata[$data_col] = $lb;
my $l = scalar @$lb ;
$lines = $l if $lines < $l;
+ $rows_in_column[$data_col] = $l;
$data_col++;
}
- elsif($c->[0] eq 'r') {
+ elsif( ($c->[0] eq 'r') or ($c->[0] eq 'R' ) ) {
my $rb = _r_box($self->{widths}[$data_col], $data->[$data_col]);
$rdata[$data_col] = $rb;
my $l = scalar @$rb ;
$lines = $l if $lines < $l;
+ $rows_in_column[$data_col] = $l ;
$data_col++;
}
$col++;
@@ -272,7 +308,25 @@
elsif($c->[0] eq ' ') {
$out .= ' ';
}
+ elsif( $c->[0] eq 'L' or $c->[0] eq 'R')
+ {
+ # bottom align
+ my $start_print = $lines - $rows_in_column[$data_col];
+
+ if ( defined $rdata[$data_col][$l-$start_print]
+ and $l >= $start_print
+ )
+ {
+ $out .= $rdata[$data_col][$l-$start_print];
+ }
+ else
+ {
+ $out .= ' 'x($self->{widths}[$data_col]);
+ }
+ $data_col++;
+ }
elsif($c->[0] eq 'l' or $c->[0] eq 'r') {
+ # top align
if(defined $rdata[$data_col][$l]) {
$out .= $rdata[$data_col][$l];
}
@@ -293,10 +347,20 @@
my ($self, $format) = @_;
my @f = split(//, $format);
my @format = ();
+ my @width = ();
+
my ($col,$data_col) = (0,0);
+ my $wid;
for my $f (@f) {
- if($f eq 'l' or $f eq 'r') {
+ if ( $f =~ /(\d+)/)
+ {
+ $wid .= $f;
+ next;
+ }
+ if($f eq 'l' or $f eq 'L' or $f eq 'r' or $f eq 'R') {
$format[$col] = [$f, $data_col];
+ $width[$data_col] = $wid;
+ $wid = undef;
$data_col++;
}
elsif($f eq '|' or $f eq ' ') {
@@ -308,6 +372,7 @@
$col++;
}
$self->{format}=\@format;
+ $self->{fixed_widths}=\@width;
$self->{col}=$col;
$self->{data_col}=$data_col;
}
@@ -321,12 +386,25 @@
=item l
-Left-justified word-wrapped text.
+Left-justified top aligned word-wrapped text.
+=item L
+
+Left-justified bottom aligned word-wrapped text.
+
=item r
-Right-justified word-wrapped text.
+Right-justified top aligned word-wrapped text.
+=item R
+
+Right-justified bottom aligned word-wrapped text.
+
+=item 10R, 20r, 15L, 12l,
+
+Number is fixed width of the column.
+Justified and aligned word-wrapped text (see above).
+
=item ' '
A space.
@@ -387,6 +465,7 @@
my ($self, @data) = @_;
scalar @data == $self->{data_col} or
croak "number of columns must be $self->{data_col}";
+
$self->_preprocess_row_data(\@data);
$self->{data}[$self->{row}++] = ['data', \@data];
}
@@ -415,8 +494,10 @@
sub render($$)
{
my ($self, $width) = @_;
+
$width = 79 unless defined $width;
$self->_calculate_widths($width);
+
my $out = '';
for my $r (@{$self->{data}}) {
if($r->[0] eq 'rule') {
@@ -436,9 +517,13 @@
=back
+=head1 SEE ALSO
+
+Text::ASCIITable
+
=head1 COPYRIGHT
-Copyright (c) 2001,2002 Swiss Federal Institute of Technology, Zurich.
+Copyright (c) 2001-2004 Swiss Federal Institute of Technology, Zurich.
All Rights Reserved.
This module is free software; you can redistribute it and/or
@@ -446,8 +531,11 @@
=head1 AUTHOR
-David Schweikert <dws@ee.ethz.ch>
+S<David Schweikert <dws@ee.ethz.ch>>
+Fixed column width and bottom alignment written by
+S<Veselin Slavov <vslavov@creditreform.bg>>
+
=cut
# vi: et sw=4