diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2023-11-11 08:40:00 +0100 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2023-11-11 08:40:00 +0100 |
commit | 31e231d16cb7d40f3db8b9800e53f6e6412bea1e (patch) | |
tree | e47cf1acd3d2d7b145410409a02823ed964a4575 | |
parent | 20c8859cafec934fdca7fe8229200ab637a47ca2 (diff) |
Only use formatting escapes when connected to a terminal
-rwxr-xr-x | bin/hafas | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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'), |