Skip Menu |
 

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

Report information
The Basics
Id: 22371
Status: resolved
Priority: 0/
Queue: Text-SimpleTable

People
Owner: Nobody in particular
Requestors: bricas [...] cpan.org
Cc:
AdminCc:

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



Subject: Adding horizontal rule (hr) capability
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
X-RT-Original-Encoding: utf-8
Content-Type: multipart/mixed; boundary="----------=_1161366226-355-6"
Content-Length: 0
Content-Type: text/plain; charset="utf8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
Content-Length: 457
Download (untitled) / with headers
text/plain 457b
Attached it a patch (including tests) that adds a generic horizontal rule (hr) capability. It basically formalizes the line between the title row and the first row of data, and allows you to insert them anywhere. E.g. my $t = Text::SimpleTable->new(5); $t->row('Everything works!'); $t->hr; $t->row('Everything works!'); print $->draw; gives: .-------. | Ever- | | ythi- | | ng w- | | orks! | +-------+ | Ever- | | ythi- | | ng w- | | orks! | '-------'
Subject: simpletable.patch
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----------=_1161366226-355-5"
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Length: 0
Content-Type: text/plain; charset="utf8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 0
Content-Type: text/x-patch; name="simpletable.patch"
Content-Disposition: inline; filename="simpletable.patch"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: ascii
Content-Length: 3320
Download simpletable.patch
text/x-diff 3.2k
=== Changes ================================================================== --- Changes (revision 13598) +++ Changes (local) @@ -1,5 +1,8 @@ Tis file documents the revision history for Perl extension Text::SimpleTable. +0.04 2006-10-19 + - Added horizontal rule (hr) method + 0.03 2006-01-17 22:00:00 - Fixed bug where text items of '0' were not displayed. === lib/Text/SimpleTable.pm ================================================================== --- lib/Text/SimpleTable.pm (revision 13598) +++ lib/Text/SimpleTable.pm (local) @@ -2,7 +2,7 @@ use strict; -our $VERSION = '0.03'; +our $VERSION = '0.04'; our $TOP_LEFT = '.-'; our $TOP_BORDER = '-'; @@ -96,6 +96,17 @@ return $self; } +=item $table->hr + +=cut + +sub hr { + my ( $self ) = @_; + for( 0..@{ $self->{columns} } - 1 ) { + push @{ $self->{columns}->[ $_ ]->[ 1 ] }, undef; + } +} + =item $table->row( @texts ) =cut @@ -127,6 +138,28 @@ return $self; } +sub _draw_hr { + my $self = shift; + my $columns = @{ $self->{columns} } - 1; + my $output = ''; + + for my $j ( 0 .. $columns ) { + my $column = $self->{columns}->[$j]; + my $width = $column->[0]; + my $text = $MIDDLE_BORDER x $width; + if ( ( $j == 0 ) && ( $columns == 0 ) ) { + $text = "$MIDDLE_LEFT$text$MIDDLE_RIGHT"; + } + elsif ( $j == 0 ) { $text = "$MIDDLE_LEFT$text$MIDDLE_SEPARATOR" } + elsif ( $j == $columns ) { $text = "$text$MIDDLE_RIGHT" } + else { $text = "$text$MIDDLE_SEPARATOR" } + $output .= $text; + } + $output .= "\n"; + + return $output; +} + =item $table->draw =cut @@ -179,25 +212,18 @@ } # Title separator - for my $j ( 0 .. $columns ) { - my $column = $self->{columns}->[$j]; - my $width = $column->[0]; - my $text = $MIDDLE_BORDER x $width; - if ( ( $j == 0 ) && ( $columns == 0 ) ) { - $text = "$MIDDLE_LEFT$text$MIDDLE_RIGHT"; - } - elsif ( $j == 0 ) { $text = "$MIDDLE_LEFT$text$MIDDLE_SEPARATOR" } - elsif ( $j == $columns ) { $text = "$text$MIDDLE_RIGHT" } - else { $text = "$text$MIDDLE_SEPARATOR" } - $output .= $text; - } - $output .= "\n"; - + $output .= $self->_draw_hr; } # Rows for my $i ( 0 .. $rows ) { + # Check for horizontal rule + if( !grep { defined $self->{columns}->[$_]->[1]->[$i] } 0..$columns ) { + $output .= $self->_draw_hr; + next; + } + for my $j ( 0 .. $columns ) { my $column = $self->{columns}->[$j]; my $width = $column->[0]; === t/04tables.t ================================================================== --- t/04tables.t (revision 13598) +++ t/04tables.t (local) @@ -1,4 +1,4 @@ -use Test::More tests => 4; +use Test::More tests => 5; use_ok('Text::SimpleTable'); @@ -44,3 +44,21 @@ | orks! | '-------' EOF + +my $t4 = Text::SimpleTable->new(5); +$t4->row('Everything works!'); +$t4->hr; +$t4->row('Everything works!'); +is( $t4->draw, <<"EOF"); +.-------. +| Ever- | +| ythi- | +| ng w- | +| orks! | ++-------+ +| Ever- | +| ythi- | +| ng w- | +| orks! | +'-------' +EOF
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Charset: utf8
Content-Type: text/plain
Message-ID: <rt-3.6.HEAD-25318-1246545872-1664.22371-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 15
Thanks applied.


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.