From 31e231d16cb7d40f3db8b9800e53f6e6412bea1e Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sat, 11 Nov 2023 08:40:00 +0100 Subject: Only use formatting escapes when connected to a terminal --- bin/hafas | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'bin/hafas') diff --git a/bin/hafas b/bin/hafas index 38ac2ad..7f8c289 100755 --- a/bin/hafas +++ b/bin/hafas @@ -39,6 +39,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( 'd|date=s' => \$date, 'h|help' => sub { show_help(0) }, @@ -314,7 +317,8 @@ for my $res ( @{ $hafas->{results} } ) { for my $sec ( $res->sections ) { if ( $sec->type eq 'JNY' ) { - printf( "\033[1m%s\033[0m → %s\n", $sec->name, $sec->direction ); + printf( "${output_bold}%s${output_reset} → %s\n", + $sec->name, $sec->direction ); printf( "%-5s %-${have_delay}s ab %s\n", $sec->dep_datetime->strftime('%H:%M'), -- cgit v1.2.3