From a2e2c50c4a856492e980d0d3f9114573d06a5c1c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 26 Dec 2018 09:29:46 +0100 Subject: Use color-coding for class distinction --- bin/dbwagenreihung | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/bin/dbwagenreihung b/bin/dbwagenreihung index fe0961a..d15bf85 100755 --- a/bin/dbwagenreihung +++ b/bin/dbwagenreihung @@ -12,6 +12,11 @@ use Travel::Status::DE::DBWagenreihung; my ( $station, $train_number ) = @ARGV; +my $col_first = "\e[38;5;11m"; +my $col_mixed = "\e[38;5;208m"; +my $col_second = "\e[38;5;9m"; +my $col_reset = "\e[0m"; + my $res = Travel::Status::DE::IRIS->new( station => $station, with_related => 1 @@ -52,8 +57,7 @@ for my $section ( $wr->sections ) { print "\n"; my @start_percentages = map { $_->{position}{start_percent} } $wr->wagons; -print ' ' x ( ( min @start_percentages ) - 1 ); -print '['; +print ' ' x ( min @start_percentages ); for my $wagon ( $wr->wagons ) { my $wagon_length @@ -71,33 +75,23 @@ for my $wagon ( $wr->wagons ) { $wagon_desc = '<->'; } - printf( "%s%3s%s", ' ' x $spacing_left, $wagon_desc, ' ' x $spacing_right ); -} -print "]\n"; - -print ' ' x ( min @start_percentages ); -for my $wagon ( $wr->wagons ) { - my $wagon_length - = $wagon->{position}->{end_percent} - $wagon->{position}->{start_percent}; - my $spacing_left = int( $wagon_length / 2 ) - 2; - my $spacing_right = int( $wagon_length / 2 ) - 1; - - if ( $wagon_length % 2 ) { - $spacing_left++; + my $class_color = ''; + if ($wagon->class_type == 1 ) { + $class_color = $col_first; } - - my $class = ''; - - if ( $wagon->class_type == 1 ) { - $class = ' 1 '; + elsif ($wagon->class_type == 2 ) { + $class_color = $col_second; } - elsif ( $wagon->class_type == 2 ) { - $class = ' 2 '; - } - elsif ( $wagon->class_type == 12 ) { - $class = '1/2'; + elsif ($wagon->class_type == 12 ) { + $class_color = $col_mixed; } - printf( "%s%3s%s", ' ' x $spacing_left, $class, ' ' x $spacing_right ); + printf( "%s%s%3s%s%s", + ' ' x $spacing_left, + $class_color, + $wagon_desc, + $col_reset, + ' ' x $spacing_right + ); } print "\n"; -- cgit v1.2.3