summaryrefslogtreecommitdiff
path: root/bin/hafas-m
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-12-26 13:03:33 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2023-12-26 13:03:33 +0100
commit3d4d74b7922aed22993f07b3aab42a22b05bf4ef (patch)
tree07f5af60511027d50e2308687721cd7f6a13332d /bin/hafas-m
parent8eb02b82e48bf9f7a9ca5270648cad6e928c6bda (diff)
hafas-m: journey details: mark next stop in bold
Diffstat (limited to 'bin/hafas-m')
-rwxr-xr-xbin/hafas-m22
1 files changed, 20 insertions, 2 deletions
diff --git a/bin/hafas-m b/bin/hafas-m
index 4b71ca6..dd5336f 100755
--- a/bin/hafas-m
+++ b/bin/hafas-m
@@ -30,6 +30,9 @@ for my $arg (@ARGV) {
$arg = decode( 'UTF-8', $arg );
}
+my $output_bold = -t STDOUT ? "\033[1m" : q{};
+my $output_reset = -t STDOUT ? "\033[0m" : q{};
+
GetOptions(
'a|arrivals' => \$arrivals,
'd|date=s' => \$date,
@@ -404,6 +407,19 @@ elsif ( $opt{journey} ) {
$delay_fmt = $delay_len + 3;
}
+ my $now = DateTime->now( time_zone => 'Europe/Berlin' );
+ my $mark_stop = 0;
+ for my $i ( reverse 1 .. scalar $result->route ) {
+ my $stop = ( $result->route )[ $i - 1 ];
+ if ( not $stop->dep_cancelled and $stop->dep and $now <= $stop->dep ) {
+ $mark_stop = $stop;
+ }
+ elsif ( not $stop->arr_cancelled and $stop->arr and $now <= $stop->arr )
+ {
+ $mark_stop = $stop;
+ }
+ }
+
my $message_id = 1;
for my $stop ( $result->route ) {
@@ -421,7 +437,8 @@ elsif ( $opt{journey} ) {
}
}
printf(
-"%5s %s %5s %-${delay_fmt}s%${occupancy_len}s%-${occupancy_len}s %s%s%s\n",
+"%s%5s %s %5s %-${delay_fmt}s%${occupancy_len}s%-${occupancy_len}s %s%s%s%s\n",
+ $stop == $mark_stop ? $output_bold : q{},
$stop->arr_cancelled ? '--:--'
: ( $stop->arr ? $stop->arr->strftime('%H:%M') : q{} ),
( $stop->arr and $stop->dep ) ? '→' : q{ },
@@ -433,7 +450,8 @@ elsif ( $opt{journey} ) {
$stop->load->{SECOND} ? display_occupancy( $stop->load->{SECOND} )
: q{},
$stop->loc->name,
- $stop->direction ? sprintf( ' → %s', $stop->direction ) : q{},
+ $stop == $mark_stop ? $output_reset : q{},
+ $stop->direction ? sprintf( ' → %s', $stop->direction ) : q{},
$msg_line,
);
}