Unverified Commit 40218881 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

dbris-m: Add --colour={auto,always,never} option

parent d66fb794
Loading
Loading
Loading
Loading
+26 −7
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ my $developer_mode;
my $show_jid;
my $use_cache = 1;
my $cache;
my $use_colour = 'auto';
my ( $json_output, $raw_json_output, $with_polyline );

my %known_mot = map { $_ => 1 }
@@ -29,8 +30,8 @@ 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{};
my $output_bold  = "\033[1m";
my $output_reset = "\033[0m";

my $cf_first  = "\e[38;5;11m";
my $cf_mixed  = "\e[38;5;208m";
@@ -45,6 +46,8 @@ GetOptions(
	't|time=s'             => \$time,
	'V|version'            => \&show_version,
	'cache!'               => \$use_cache,
	'color=s'              => \$use_colour,
	'colour=s'             => \$use_colour,
	'devmode'              => \$developer_mode,
	'json'                 => \$json_output,
	'raw-json'             => \$raw_json_output,
@@ -52,6 +55,14 @@ GetOptions(

) or show_help(1);

if ( $use_colour eq 'auto'
	and ( not -t STDOUT or ( defined $ENV{TERM} and $ENV{TERM} eq 'dumb' ) )
	or $use_colour eq 'never' )
{
	$output_bold = $output_reset = q{};
	$cf_first    = $cf_mixed     = $cf_second = $cf_reset = q{};
}

if ($use_cache) {
	my $cache_path = ( $ENV{XDG_CACHE_HOME} // "$ENV{HOME}/.cache" )
	  . '/Travel-Status-DE-DBRIS';
@@ -515,19 +526,19 @@ if ($train_no) {
			$wagon_desc = '';
		}

		my $class_color = '';
		my $class_colour = '';
		if ( $wagon->class_type == 1 ) {
			$class_color = $cf_first;
			$class_colour = $cf_first;
		}
		elsif ( $wagon->class_type == 2 ) {
			$class_color = $cf_second;
			$class_colour = $cf_second;
		}
		elsif ( $wagon->class_type == 12 ) {
			$class_color = $cf_mixed;
			$class_colour = $cf_mixed;
		}

		printf( "%s%s%3s%s%s",
			' ' x $spacing_left, $class_color, $wagon_desc,
			' ' x $spacing_left, $class_colour, $wagon_desc,
			$cf_reset,           ' ' x $spacing_right );
	}
	print $wr->direction == 100 ? '>' : '<';
@@ -635,6 +646,14 @@ operating mode(s).

=over

=item B<--colour>, B<--color> B<always>|B<auto>|B<never>

By default, B<dbris-m> uses ANSI escape codes for output formatting whenever
the output is connected to a terminal and the TERM environment variable is not
set to C<< dumb >>. B<--colour=always> causes it to always use output
formatting regardless of terminal setup, and B<--colour=never> disables any
formatting. B<--colour=auto> restores the default behaviour.

=item B<-d>, B<--date> I<DD.MM.[YYYY]> (departure monitor)

Request departures on the specified date.