summaryrefslogtreecommitdiff
path: root/bin/hafas
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-11-11 08:40:00 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2023-11-11 08:40:00 +0100
commit31e231d16cb7d40f3db8b9800e53f6e6412bea1e (patch)
treee47cf1acd3d2d7b145410409a02823ed964a4575 /bin/hafas
parent20c8859cafec934fdca7fe8229200ab637a47ca2 (diff)
Only use formatting escapes when connected to a terminal
Diffstat (limited to 'bin/hafas')
-rwxr-xr-xbin/hafas6
1 files changed, 5 insertions, 1 deletions
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'),