summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-06-27 01:50:35 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-06-27 01:50:35 +0200
commit90a653d7ec45a2e96547035c2968d6e2223d85b5 (patch)
treec4247d76aa424121bc1b4220e467486a7fb3723e
parent8d1e7ef8e8e05e052772eccf3beabfc461d85ec3 (diff)
db-ris: Do not make output columns (train route etc.) wider than necessary
-rwxr-xr-xbin/db-ris37
1 files changed, 32 insertions, 5 deletions
diff --git a/bin/db-ris b/bin/db-ris
index 8514831..554d19d 100755
--- a/bin/db-ris
+++ b/bin/db-ris
@@ -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