summaryrefslogtreecommitdiff
path: root/bin/dbris-m
diff options
context:
space:
mode:
Diffstat (limited to 'bin/dbris-m')
-rwxr-xr-xbin/dbris-m115
1 files changed, 114 insertions, 1 deletions
diff --git a/bin/dbris-m b/bin/dbris-m
index 545d696..ef3325b 100755
--- a/bin/dbris-m
+++ b/bin/dbris-m
@@ -10,7 +10,7 @@ use DateTime;
use Encode qw(decode);
use JSON;
use Getopt::Long qw(:config no_ignore_case);
-use List::Util qw(max);
+use List::Util qw(min max);
use Travel::Status::DE::DBRIS;
my ( $date, $time );
@@ -32,6 +32,11 @@ for my $arg (@ARGV) {
my $output_bold = -t STDOUT ? "\033[1m" : q{};
my $output_reset = -t STDOUT ? "\033[0m" : q{};
+my $cf_first = "\e[38;5;11m";
+my $cf_mixed = "\e[38;5;208m";
+my $cf_second = "\e[0m"; #"\e[38;5;9m";
+my $cf_reset = "\e[0m";
+
GetOptions(
'd|date=s' => \$date,
'h|help' => sub { show_help(0) },
@@ -430,6 +435,114 @@ elsif ( $opt{locationSearch} ) {
}
}
+if ($train_no) {
+ $status = Travel::Status::DE::DBRIS->new(
+ cache => $cache,
+ developer_mode => $developer_mode,
+ formation => $train_no
+ );
+
+ my $wr = $status->result;
+
+ printf(
+ "\n%s → %s\n",
+ join( ' / ',
+ map { $wr->train_type . ' ' . $_->{name} } $wr->train_numbers ),
+ join(
+ ' / ',
+ map {
+ sprintf( '%s (%s)',
+ $_->{name}, join( q{}, @{ $_->{sectors} } ) )
+ } $wr->destinations
+ ),
+ );
+
+ printf( "Gleis %s\n\n", $wr->platform );
+
+ for my $sector ( $wr->sectors ) {
+ my $sector_length = $sector->length_percent;
+ my $spacing_left = int( ( $sector_length - 2 ) / 2 ) - 1;
+ my $spacing_right = int( ( $sector_length - 2 ) / 2 );
+
+ if ( $sector_length % 2 ) {
+ $spacing_left++;
+ }
+
+ printf( "▏%s%s%s▕",
+ ( $spacing_left >= 0 ) ? ' ' x $spacing_left : q{},
+ $sector->name,
+ ( $spacing_right >= 0 ) ? ' ' x $spacing_right : q{} );
+ }
+ print "\n";
+
+ my @start_percentages = map { $_->start_percent } $wr->carriages;
+ if ( my $min_percentage = min @start_percentages ) {
+ print ' ' x ( $min_percentage - 1 );
+ }
+ print $wr->direction == 100 ? '>' : '<';
+
+ for my $wagon ( $wr->carriages ) {
+ my $wagon_length = $wagon->length_percent;
+ my $spacing_left = int( $wagon_length / 2 ) - 2;
+ my $spacing_right = int( $wagon_length / 2 ) - 1;
+
+ if ( $wagon_length % 2 ) {
+ $spacing_left++;
+ }
+
+ my $wagon_desc = $wagon->number || '?';
+
+ if ( $wagon->is_closed ) {
+ $wagon_desc = 'X';
+ }
+
+ if ( $wagon->is_locomotive or $wagon->is_powercar ) {
+ $wagon_desc = ' ■ ';
+ }
+
+ my $class_color = '';
+ if ( $wagon->class_type == 1 ) {
+ $class_color = $cf_first;
+ }
+ elsif ( $wagon->class_type == 2 ) {
+ $class_color = $cf_second;
+ }
+ elsif ( $wagon->class_type == 12 ) {
+ $class_color = $cf_mixed;
+ }
+
+ printf( "%s%s%3s%s%s",
+ ' ' x $spacing_left, $class_color, $wagon_desc,
+ $cf_reset, ' ' x $spacing_right );
+ }
+ print $wr->direction == 100 ? '>' : '<';
+ print "\n\n";
+
+ for my $group ( $wr->groups ) {
+ printf( "%s%s%s\n",
+ $group->description || 'Zug',
+ $group->designation ? ' „' . $group->designation . '“' : q{},
+ $group->has_sectors
+ ? ' (' . join( q{}, $group->sectors ) . ')'
+ : q{} );
+ printf( "%s %s → %s\n\n",
+ $group->train_type, $group->train_no, $group->destination );
+
+ for my $wagon ( $group->carriages ) {
+ printf(
+ "%3s: %3s %10s %s\n",
+ $wagon->is_closed ? 'X'
+ : $wagon->is_locomotive ? 'Lok'
+ : $wagon->number || '?',
+ $wagon->model || '???',
+ $wagon->type,
+ join( q{ }, $wagon->attributes )
+ );
+ }
+ say "";
+ }
+}
+
__END__
=head1 NAME