Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • derf/travel-routing-de-efa
1 result
Show changes
Commits on Source (2)
Birte Kristina Friesel <derf@chaosdorf.de>
Birte Kristina Friesel <derf@finalrewind.org>
Birte Kristina Friesel <derf@derf.homelinux.org>
...@@ -10,7 +10,7 @@ use Encode qw(decode); ...@@ -10,7 +10,7 @@ use Encode qw(decode);
use Travel::Routing::DE::EFA; use Travel::Routing::DE::EFA;
use Exception::Class; use Exception::Class;
use Getopt::Long qw/:config no_ignore_case/; use Getopt::Long qw/:config no_ignore_case/;
use List::Util qw(first); use List::Util qw(first max);
our $VERSION = '2.23'; our $VERSION = '2.23';
my $ignore_info; my $ignore_info;
...@@ -30,6 +30,9 @@ my $opt = { ...@@ -30,6 +30,9 @@ my $opt = {
binmode( STDOUT, ':encoding(utf-8)' ); binmode( STDOUT, ':encoding(utf-8)' );
binmode( STDERR, ':encoding(utf-8)' ); binmode( STDERR, ':encoding(utf-8)' );
my $output_bold = -t STDOUT ? "\033[1m" : q{};
my $output_reset = -t STDOUT ? "\033[0m" : q{};
sub show_help { sub show_help {
my ($exit_status) = @_; my ($exit_status) = @_;
...@@ -170,6 +173,14 @@ sub format_footpath { ...@@ -170,6 +173,14 @@ sub format_footpath {
return $str; return $str;
} }
sub format_delay {
my ( $delay, $len ) = @_;
if ( $delay and $len ) {
return sprintf( "(%+${len}d)", $delay );
}
return q{};
}
sub display_routes { sub display_routes {
my (@routes) = @_; my (@routes) = @_;
...@@ -189,8 +200,19 @@ sub display_routes { ...@@ -189,8 +200,19 @@ sub display_routes {
} }
} }
my $delay_len = 0;
for my $c ( $route->parts ) { for my $c ( $route->parts ) {
display_connection($c); if ( $c->departure_delay ) {
$delay_len
= max( $delay_len, length( $c->departure_delay ) + 1 );
}
if ( $c->arrival_delay ) {
$delay_len = max( $delay_len, length( $c->arrival_delay ) + 1 );
}
}
for my $c ( $route->parts ) {
display_connection( $c, $delay_len );
} }
# last one needs to be shown separately # last one needs to be shown separately
...@@ -209,22 +231,13 @@ sub display_routes { ...@@ -209,22 +231,13 @@ sub display_routes {
} }
sub display_connection { sub display_connection {
my ($c) = @_; my ( $c, $delay_len ) = @_;
my $delay_fmt = $delay_len ? $delay_len + 2 : 0;
if ( $c->is_cancelled ) { if ( $c->is_cancelled ) {
say '# FAHRT FÄLLT AUS'; say '# FAHRT FÄLLT AUS';
} }
elsif ( $c->delay ) {
printf( "# +%d, Plan: %s -> %s\n",
$c->delay, $c->departure_stime, $c->arrival_stime );
}
for my $note ( $c->regular_notes ) {
my $text = $note->summary;
if ( not( length $ignore_info and $text =~ /$ignore_info/i ) ) {
say "# $text";
}
}
my $occupancy = q{}; my $occupancy = q{};
...@@ -240,15 +253,6 @@ sub display_connection { ...@@ -240,15 +253,6 @@ sub display_connection {
} }
} }
for my $notice ( $c->current_notes ) {
if ( $notice->subtitle ne $notice->subject ) {
printf( "# %s - %s\n", $notice->subtitle, $notice->subject );
}
else {
printf( "# %s\n", $notice->subtitle );
}
}
if ( $opt->{maps} ) { if ( $opt->{maps} ) {
for my $m ( $c->departure_routemaps, $c->departure_stationmaps ) { for my $m ( $c->departure_routemaps, $c->departure_stationmaps ) {
say "# $m"; say "# $m";
...@@ -256,22 +260,49 @@ sub display_connection { ...@@ -256,22 +260,49 @@ sub display_connection {
} }
printf( printf(
"%-5s ab %-30s %-20s %s\n", "${output_bold}%s${output_reset} %s %s\n",
$c->train_line || $c->train_product,
$c->train_destination ? q{→} : q{ },
$c->train_destination
);
printf(
"%-5s %-${delay_fmt}s ab %-30s\n",
$c->departure_time, $c->departure_time,
format_delay( $c->departure_delay, $delay_len ),
$c->departure_stop_and_platform, $c->departure_stop_and_platform,
$c->train_line || $c->train_product,
$c->train_destination,
); );
if ( $opt->{'full-route'} ) { if ( $opt->{'full-route'} ) {
for my $via_stop ( $c->via ) { for my $via_stop ( $c->via ) {
printf( "%-5s %-30s %s\n", printf( "%-5s %-${delay_fmt}s %-30s %s\n",
$via_stop->[1], $via_stop->[2], $via_stop->[3] ); $via_stop->[1], q{}, $via_stop->[2], $via_stop->[3] );
}
}
printf(
"%-5s %-${delay_fmt}s an %-30s %s\n",
$c->arrival_time,
format_delay( $c->arrival_delay, $delay_len ),
$c->arrival_stop_and_platform, $occupancy
);
for my $notice ( $c->current_notes ) {
if ( $notice->subtitle ne $notice->subject ) {
printf( "# %s - %s\n", $notice->subtitle, $notice->subject );
}
else {
printf( "# %s\n", $notice->subtitle );
}
}
for my $note ( $c->regular_notes ) {
my $text = $note->summary;
if ( not( length $ignore_info and $text =~ /$ignore_info/i ) ) {
say "# $text";
} }
} }
printf( "%-5s an %-30s %s\n",
$c->arrival_time, $c->arrival_stop_and_platform, $occupancy );
print "\n"; print "\n";
if ( $opt->{'extended-info'} if ( $opt->{'extended-info'}
......