From 6feb4b288f8fa9711ee580fe65562abef976a842 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 5 Sep 2019 18:06:53 +0200 Subject: [PATCH] color default depends on stdout being isatty --- graph | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/graph b/graph index 423f5cb..14b7173 100755 --- 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[=] -- 2.30.0