Detect whether STDOUT is a tty unless --force-oolor is given
authorJoey Schulze <joey@infodrom.org>
Thu, 9 Jun 2016 17:41:17 +0000 (19:41 +0200)
committerJoey Schulze <joey@infodrom.org>
Sat, 25 Jun 2016 10:48:31 +0000 (12:48 +0200)
src/InfoCon/buch/vorsteueranmeldung

index 94c0949..9429ca2 100755 (executable)
@@ -31,6 +31,7 @@ use constant CONFIG => '/etc/infocon.cfg';
 
 my $opt_mode = 'month';
 my $opt_nocolor = 0;
+my $opt_forcecolor = 0;
 my $opt_start;
 my $opt_end;
 my $cfg;
@@ -275,6 +276,7 @@ GetOptions ('help|h' => \&help,
            'quarter|q' => sub {$opt_mode = 'quarter'},
            'month|m' => sub {$opt_mode = 'month'},
            'no-color|nocolor|raw' => \$opt_nocolor,
+           'force-color' => \$opt_forcecolor,
            'start' => \$opt_start,
            'end' => \$opt_end)
     or die("Error in command line arguments\n");
@@ -283,6 +285,8 @@ $cfg = new Config::Simple(CONFIG);
 
 die "Cannot read config file\n" unless $cfg;
 
+$opt_nocolor = !(-t STDOUT) unless $opt_forcecolor;
+
 if (!defined $opt_start || !defined $opt_end) {
     calculate_start_end @ARGV;
 }