Commit a2e2c50c authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Use color-coding for class distinction

parent 3aec797b
Loading
Loading
Loading
Loading
+20 −26
Original line number Diff line number Diff line
@@ -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 = '';

	my $class_color = '';
	if ($wagon->class_type == 1 ) {
		$class = ' 1 ';
		$class_color = $col_first;
	}
	elsif ($wagon->class_type == 2 ) {
		$class = ' 2 ';
		$class_color = $col_second;
	}
	elsif ($wagon->class_type == 12 ) {
		$class = '1/2';
		$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";