diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-06-27 01:50:35 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-06-27 01:50:35 +0200 |
commit | 90a653d7ec45a2e96547035c2968d6e2223d85b5 (patch) | |
tree | c4247d76aa424121bc1b4220e467486a7fb3723e /bin | |
parent | 8d1e7ef8e8e05e052772eccf3beabfc461d85ec3 (diff) |
db-ris: Do not make output columns (train route etc.) wider than necessary
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/db-ris | 37 |
1 files changed, 32 insertions, 5 deletions
@@ -6,13 +6,14 @@ use 5.010; our $VERSION = '0.0'; use Getopt::Long; -use List::Util qw(first); +use List::Util qw(first max); use Travel::Status::DE::DeutscheBahn; my ( $date, $time ); my $types = q{}; my %train_type; my $filter_via; +my @output; binmode( STDOUT, ':encoding(utf-8)' ); @@ -39,6 +40,27 @@ my $status = Travel::Status::DE::DeutscheBahn->new( time => $time, ); +sub display_result { + my (@lines) = @_; + + my @line_length; + + if ( not @lines ) { + die("Nothing to show\n"); + } + + for my $i ( 0 .. 5 ) { + $line_length[$i] = max map { length( $_->[$i] ) } @lines; + } + + for my $line (@lines) { + printf( join( q{ }, ( map { "%-${_}s" } @line_length ) ) . "\n", + @{$line}, ); + } + + return; +} + for my $d ( $status->departures() ) { my ( @via, @via_main, @via_show ); @@ -79,13 +101,18 @@ for my $d ( $status->departures() ) { $stop =~ s{ ?Hbf}{}; } - printf( - "%5s %-10s %-80s %-20s %-2s %s\n", - $d->time, $d->train, join( q{ }, @via_show ), - $d->destination, $d->platform, $d->info + push( + @output, + [ + $d->time, $d->train, + join( q{ }, @via_show ), $d->destination, + $d->platform, $d->info + ] ); } +display_result(@output); + __END__ =head1 NAME |