r40608 - in /branches/upstream/libtext-formattable-perl/current: Changes MANIFEST META.yml Makefile.PL README lib/Text/FormatTable.pm test.pl

carnil-guest at users.alioth.debian.org carnil-guest at users.alioth.debian.org
Fri Jul 24 05:49:07 UTC 2009


Author: carnil-guest
Date: Fri Jul 24 05:48:30 2009
New Revision: 40608

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=40608
Log:
[svn-upgrade] Integrating new upstream version, libtext-formattable-perl (1.02)

Modified:
    branches/upstream/libtext-formattable-perl/current/Changes
    branches/upstream/libtext-formattable-perl/current/MANIFEST
    branches/upstream/libtext-formattable-perl/current/META.yml
    branches/upstream/libtext-formattable-perl/current/Makefile.PL
    branches/upstream/libtext-formattable-perl/current/README
    branches/upstream/libtext-formattable-perl/current/lib/Text/FormatTable.pm
    branches/upstream/libtext-formattable-perl/current/test.pl

Modified: branches/upstream/libtext-formattable-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-formattable-perl/current/Changes?rev=40608&op=diff
==============================================================================
--- branches/upstream/libtext-formattable-perl/current/Changes (original)
+++ branches/upstream/libtext-formattable-perl/current/Changes Fri Jul 24 05:48:30 2009
@@ -1,6 +1,12 @@
 Revision history for Perl extension Text::FormatTable.
 
-2004-06-10
+2009-07-23 (1.02)
+     * Added support for ASCII color sequences.  The escape codes are
+       no longer included when calculating column widths. (Trey
+       Harris)
+     * Trey Harris takes over maintainership.
+
+2004-06-10 (1.01)
      * Fixed column width and bottom alignment (Veselin Slavov)
 
 2003-01-28

Modified: branches/upstream/libtext-formattable-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-formattable-perl/current/MANIFEST?rev=40608&op=diff
==============================================================================
--- branches/upstream/libtext-formattable-perl/current/MANIFEST (original)
+++ branches/upstream/libtext-formattable-perl/current/MANIFEST Fri Jul 24 05:48:30 2009
@@ -1,8 +1,8 @@
 Changes
+example.pl
+lib/Text/FormatTable.pm
 Makefile.PL
-MANIFEST
+MANIFEST			This list of files
+META.yml
 README
-lib/Text/FormatTable.pm
-example.pl
 test.pl
-META.yml                                 Module meta-data (added by MakeMaker)

Modified: branches/upstream/libtext-formattable-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-formattable-perl/current/META.yml?rev=40608&op=diff
==============================================================================
--- branches/upstream/libtext-formattable-perl/current/META.yml (original)
+++ branches/upstream/libtext-formattable-perl/current/META.yml Fri Jul 24 05:48:30 2009
@@ -1,10 +1,13 @@
-# http://module-build.sourceforge.net/META-spec.html
-#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
-name:         Text-FormatTable
-version:      1.01
-version_from: lib/Text/FormatTable.pm
-installdirs:  site
-requires:
-
-distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.17
+--- #YAML:1.0
+name:                Text-FormatTable
+version:             1.02
+abstract:            Format text tables
+license:             perl
+author:              
+    - Trey Harris <treyharris at gmail.com>
+generated_by:        ExtUtils::MakeMaker version 6.42
+distribution_type:   module
+requires:     
+meta-spec:
+    url:     http://module-build.sourceforge.net/META-spec-v1.3.html
+    version: 1.3

Modified: branches/upstream/libtext-formattable-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-formattable-perl/current/Makefile.PL?rev=40608&op=diff
==============================================================================
--- branches/upstream/libtext-formattable-perl/current/Makefile.PL (original)
+++ branches/upstream/libtext-formattable-perl/current/Makefile.PL Fri Jul 24 05:48:30 2009
@@ -7,5 +7,6 @@
     'PREREQ_PM'		=> {}, # e.g., Module::Name => 1.1
     ($] >= 5.005 ?    ## Add these new keywords supported since 5.005
       (ABSTRACT_FROM => 'lib/Text/FormatTable.pm', # retrieve abstract from module
-       AUTHOR     => 'David Schweikert <dws at ee.ethz.ch>') : ()),
+       AUTHOR     => 'Trey Harris <treyharris at gmail.com>',
+       LICENSE    => 'perl') : ()),
 );

Modified: branches/upstream/libtext-formattable-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-formattable-perl/current/README?rev=40608&op=diff
==============================================================================
--- branches/upstream/libtext-formattable-perl/current/README (original)
+++ branches/upstream/libtext-formattable-perl/current/README Fri Jul 24 05:48:30 2009
@@ -26,6 +26,7 @@
 COPYRIGHT AND LICENCE
 
   Copyright (c) 2001, Swiss Federal Institute of Technology, Zurich.
+            (c) 2009 Trey Harris
   All Rights Reserved.
   
   This module is free software; you can redistribute it and/or

Modified: branches/upstream/libtext-formattable-perl/current/lib/Text/FormatTable.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-formattable-perl/current/lib/Text/FormatTable.pm?rev=40608&op=diff
==============================================================================
--- branches/upstream/libtext-formattable-perl/current/lib/Text/FormatTable.pm (original)
+++ branches/upstream/libtext-formattable-perl/current/lib/Text/FormatTable.pm Fri Jul 24 05:48:30 2009
@@ -4,7 +4,7 @@
 use strict;
 use vars qw($VERSION);
 
-$VERSION = '1.01';
+$VERSION = '1.02';
 
 =head1 NAME
 
@@ -31,13 +31,21 @@
 
 =cut
 
+# Remove ANSI color sequences when calculating length
+sub _uncolorized_length($)
+{
+    my $str = shift;
+    $str =~ s/\e \[ [^m]* m//xmsg;
+    return length $str;
+}
+
 # minimal width of $1 if word-wrapped
 sub _min_width($)
 {
     my $str = shift;
     my $min;
     for my $s (split(/\s+/,$str)) {
-        my $l = length $s;
+        my $l = _uncolorized_length $s;
         $min = $l if not defined $min or $l > $min;
     }
     return $min;
@@ -47,7 +55,7 @@
 sub _max_width($)
 {
     my $str = shift;
-    return length $str;
+    return _uncolorized_length $str;
 }
 
 sub _max($$)
@@ -76,7 +84,7 @@
     my @t = ($text);
     while(1) {
         my $t = pop @t;
-        my $l = length $t;
+        my $l = _uncolorized_length $t;
         if($l <= $width){
             # last line is ok => done
             push @t, $t;
@@ -89,7 +97,7 @@
         }
         elsif($t =~ /(.{$width,}?\S)\s+(\S.*?)$/) {
             # nearest space > width
-            if ( length $1 > $width_m1  )
+            if ( _uncolorized_length $1 > $width_m1  )
             {
                 # hard hyphanation 
                 my $left = substr($1,0,$width);
@@ -123,7 +131,7 @@
 {
     my ($width, $text) = @_;
     my $lines = _wrap($width, $text);
-    map { $_ .= ' 'x($width-length($_)) } @$lines;
+    map { $_ .= ' 'x($width-_uncolorized_length($_)) } @$lines;
     return $lines;
 }
 
@@ -132,7 +140,7 @@
 {
     my ($width, $text) = @_;
     my $lines = _wrap($width, $text);
-    map { $_ = (' 'x($width-length($_)).$_) } @$lines;
+    map { $_ = (' 'x($width-_uncolorized_length($_)).$_) } @$lines;
     return $lines;
 }
 
@@ -524,14 +532,21 @@
 =head1 COPYRIGHT
 
 Copyright (c) 2001-2004 Swiss Federal Institute of Technology, Zurich.
+          (c) 2009 Trey Harris
 All Rights Reserved.
 
 This module is free software; you can redistribute it and/or
 modify it under the same terms as Perl itself.
 
+=head1 CODE REPOSITORY
+
+Git - http://github.com/treyharris/Text-FormatTable/tree/master
+
 =head1 AUTHOR
 
 S<David Schweikert <dws at ee.ethz.ch>>
+
+Maintained by S<Trey Harris <treyharris at gmail.com>>
 
 Fixed column width and bottom alignment written by
 S<Veselin Slavov <vslavov at creditreform.bg>>

Modified: branches/upstream/libtext-formattable-perl/current/test.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtext-formattable-perl/current/test.pl?rev=40608&op=diff
==============================================================================
--- branches/upstream/libtext-formattable-perl/current/test.pl (original)
+++ branches/upstream/libtext-formattable-perl/current/test.pl Fri Jul 24 05:48:30 2009
@@ -1,18 +1,19 @@
 use Test;
-BEGIN { plan tests => 2 };
+BEGIN { plan tests => 4 };
 use Text::FormatTable;
 ok(1); # If we made it this far, we're ok.
 
-my $table = Text::FormatTable->new('r| l l');
+{
+    my $table = Text::FormatTable->new('r| l l');
 $table->head('a', 'b', 'c');
-$table->rule('=');
-$table->row('this a test, a nice test', 'oh, cool, a test!', 'yep');
-$table->rule;
-$table->row('you mean it\'s really a test?', 'yes, it is.', 'z');
-$table->rule('=');
-my $is = $table->render(15);
+    $table->rule('=');
+    $table->row('this a test, a nice test', 'oh, cool, a test!', 'yep');
+    $table->rule;
+    $table->row('you mean it\'s really a test?', 'yes, it is.', 'z');
+    $table->rule('=');
+    my $is = $table->render(15);
 
-my $shouldbe = <<'END';
+    my $shouldbe = <<'END';
      a| b     c  
 =================
 this a| oh,   yep
@@ -29,4 +30,31 @@
 =================
 END
 
-ok($is, $shouldbe);
+    ok($is, $shouldbe);
+}
+
+# Test behavior with ANSI-colored header
+{
+    my $colortable = Text::FormatTable->new('l l l');
+    my $RED = "\e[31m";
+    my $RESET = "\e[0m";
+    $colortable->head('foo', $RED . 'bar' . $RESET, 'bat');
+    $colortable->rule('=');
+    $colortable->row(qw(a b c));
+    my $output = $colortable->render();
+    my ($rule) = ($output =~ /(=+)/);
+    ok(length($rule), length("foo bar bat"));
+}
+
+# Test behavior with ANSI-colored row data
+{
+    my $colortable = Text::FormatTable->new('l l l');
+    my $RED = "\e[31m";
+    my $RESET = "\e[0m";
+    $colortable->head('foo', 'bar', 'bat');
+    $colortable->rule('=');
+    $colortable->row('a', $RED . 'b' . $RESET, 'c');
+    my $output = $colortable->render();
+    my ($rule) = ($output =~ /(=+)/);
+    ok(length($rule), length("foo bar bat"));
+}




More information about the Pkg-perl-cvs-commits mailing list