NO_COLOR environment as default --color
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 14 Nov 2022 15:42:11 +0000 (16:42 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 18 Nov 2022 00:25:46 +0000 (01:25 +0100)
Popular standard explained on: https://no-color.org/

barcat

diff --git a/barcat b/barcat
index 62c1dbc4f9210e26d3d8e2c119313b6d585f39cc..6ab610db6282e26f15996fb88605e96f2a5669ba 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -105,7 +105,7 @@ GetOptions(\%opt,
 }
 
 $opt{width} ||= $ENV{COLUMNS} || qx(tput cols) || 80 unless $opt{spark};
-$opt{color} //= -t *STDOUT;  # enable on tty
+$opt{color} //= $ENV{NO_COLOR} ? 0 : -t *STDOUT;  # enable on tty
 $opt{'graph-format'} //= '-';
 $opt{trim}   *= $opt{width} / 100 if $opt{trimpct};
 $opt{units}   = [split //, ' kMGTPEZYyzafpn'.($opt{ascii} ? 'u' : 'μ').'m']
@@ -435,6 +435,8 @@ Input is always interpreted as UTF-8 and shown as is.
 Force colored output of values and bar markers.
 Defaults on if output is a tty,
 disabled otherwise such as when piped or redirected.
+Can also be disabled by setting I<-C>
+or the I<NO_COLOR> environment variable.
 
 =item -f, --field=(<number> | <regexp>)