color default depends on stdout being isatty
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 5 Sep 2019 16:06:53 +0000 (18:06 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 5 Sep 2019 21:56:49 +0000 (23:56 +0200)
graph

diff --git a/graph b/graph
index 423f5cbede3cb3881f3401dd1b93070aa236b97e..14b717310a819c4272fd1cf4911f5ff6432feea5 100755 (executable)
--- a/graph
+++ b/graph
@@ -18,8 +18,9 @@ GetOptions(\my %opt,
        'usage|h' => sub { podexit() },
        'help'    => sub { podexit(-verbose => 2) },
 ) or exit 64;  # EX_USAGE
+
 $opt{width} ||= $ENV{COLUMNS} || 80;
-$opt{color} //= 1;
+$opt{color} //= -t *STDOUT;  # enable on tty
 
 if (defined $opt{follow}) {
        $opt{follow} ||= 1;
@@ -108,9 +109,11 @@ Each line starting with a number is given a bar to visualise relative sizes.
 
 =over
 
-=item --no-color
+=item -c, --[no-]color
 
-Disable colored output of values and bar markers.
+Force colored output of values and bar markers.
+Defaults on if output is a tty,
+disabled otherwise such as when piped or redirected.
 
 =item -f, --follow[=<seconds>]