Skip to content
Snippets Groups Projects
Commit 90a653d7 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

db-ris: Do not make output columns (train route etc.) wider than necessary

parent 8d1e7ef8
No related branches found
No related tags found
No related merge requests found
...@@ -6,13 +6,14 @@ use 5.010; ...@@ -6,13 +6,14 @@ use 5.010;
our $VERSION = '0.0'; our $VERSION = '0.0';
use Getopt::Long; use Getopt::Long;
use List::Util qw(first); use List::Util qw(first max);
use Travel::Status::DE::DeutscheBahn; use Travel::Status::DE::DeutscheBahn;
my ( $date, $time ); my ( $date, $time );
my $types = q{}; my $types = q{};
my %train_type; my %train_type;
my $filter_via; my $filter_via;
my @output;
binmode( STDOUT, ':encoding(utf-8)' ); binmode( STDOUT, ':encoding(utf-8)' );
...@@ -39,6 +40,27 @@ my $status = Travel::Status::DE::DeutscheBahn->new( ...@@ -39,6 +40,27 @@ my $status = Travel::Status::DE::DeutscheBahn->new(
time => $time, 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() ) { for my $d ( $status->departures() ) {
my ( @via, @via_main, @via_show ); my ( @via, @via_main, @via_show );
...@@ -79,13 +101,18 @@ for my $d ( $status->departures() ) { ...@@ -79,13 +101,18 @@ for my $d ( $status->departures() ) {
$stop =~ s{ ?Hbf}{}; $stop =~ s{ ?Hbf}{};
} }
printf( push(
"%5s %-10s %-80s %-20s %-2s %s\n", @output,
$d->time, $d->train, join( q{ }, @via_show ), [
$d->destination, $d->platform, $d->info $d->time, $d->train,
join( q{ }, @via_show ), $d->destination,
$d->platform, $d->info
]
); );
} }
display_result(@output);
__END__ __END__
=head1 NAME =head1 NAME
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment