color option to disable formatting codes
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 4 Sep 2019 18:22:23 +0000 (20:22 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 5 Sep 2019 03:11:33 +0000 (05:11 +0200)
graph

diff --git a/graph b/graph
index 5b61e53a5c8d978b3b0922c10d49e66c43f7aac0..093ed65d90c99b8eba8c99a81a944b2aca320e20 100755 (executable)
--- a/graph
+++ b/graph
@@ -8,11 +8,13 @@ our $VERSION = '1.00';
 use Getopt::Long '2.33';
 sub podexit { require Pod::Usage; Pod::Usage::pod2usage(-exitval => 0, @_) }
 GetOptions(\my %opt,
+       'color|c!',
        'width|w=i',
        'usage|h' => sub { podexit() },
        'help'    => sub { podexit(-verbose => 2) },
 ) or exit 64;  # EX_USAGE
 $opt{width} ||= $ENV{COLUMNS} || 80;
+$opt{color} //= 1;
 
 my @lines = readline or exit;
 chomp for @lines;
@@ -26,11 +28,11 @@ sub orderpos { ($order[$_[0]] + $order[$_[0] + .5]) / 2 * $size }
 my @barmark;
 $barmark[ sum(@values) / @values * $size ] = '=';  # average
 $barmark[ orderpos($#order / 2) ] = '+';  # mean
-defined and $_ = "\e[36m$_\e[0m" for @barmark;
+defined and $opt{color} and $_ = "\e[36m$_\e[0m" for @barmark;
 
 for my $nr (0 .. $#lines) {
        my $val = $values[$nr];
-       my $color =
+       my $color = !$opt{color} ? 0 :
                $val == $order[0] ? 32 : # max
                $val == $order[-1] ? 31 : # min
                90;
@@ -60,6 +62,10 @@ Each line starting with a number is given a bar to visualise relative sizes.
 
 =over
 
+=item --no-color
+
+Disable colored output of values and bar markers.
+
 =item -w, --width=<columns>
 
 Override the maximum number of columns to use.