numeric inline parameters override value input
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 3 Oct 2019 21:51:57 +0000 (23:51 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 4 Oct 2019 02:38:14 +0000 (04:38 +0200)
Commandline shorthand for simple manual entry with unambiguous numbers.

barcat
t/t0101-value_parameters_--_1_4_8_2_6_3_9_5_2.out [new file with mode: 0644]

diff --git a/barcat b/barcat
index 9cfe3e3df3330b69a2f762372e76ee2af606db54..fc4cb3c73afd869f6c1cb7080c8c6c54db3cc835 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -112,6 +112,7 @@ $opt{'value-length'} = 1 if $opt{unmodified};
 $opt{'signal-stat'} //= exists $SIG{INFO} ? 'INFO' : 'QUIT';
 $opt{markers} //= '=avg >31.73v <68.27v +50v |0';
 $opt{palette} //= $opt{color} && [31, 90, 32];
+$opt{input} = @ARGV && $ARGV[0] =~ m/\A[-0-9]/ ? \@ARGV : undef;
 
 my (@lines, @values, @order);
 
@@ -133,7 +134,7 @@ if (defined $opt{interval}) {
 }
 
 my $valmatch = qr/$opt{anchor} ( \h* -? [0-9]* \.? [0-9]+ (?: e[+-]?[0-9]+ )? |)/x;
-while (readline) {
+while (defined ($_ = $opt{input} ? shift @{ $opt{input} } : readline)) {
        s/\r?\n\z//;
        s/^\h*// unless $opt{unmodified};
        push @values, s/$valmatch/\n/ && $1;
@@ -305,11 +306,12 @@ barcat - graph to visualize input values
 
 =head1 SYNOPSIS
 
-B<barcat> [<options>] [<input>]
+B<barcat> [<options>] [<file>... | <numbers>]
 
 =head1 DESCRIPTION
 
-Visualizes relative sizes of values read from input (file(s) or STDIN).
+Visualizes relative sizes of values read from input
+(parameters, file(s) or STDIN).
 Contents are concatenated similar to I<cat>,
 but numbers are reformatted and a bar graph is appended to each line.
 
diff --git a/t/t0101-value_parameters_--_1_4_8_2_6_3_9_5_2.out b/t/t0101-value_parameters_--_1_4_8_2_6_3_9_5_2.out
new file mode 100644 (file)
index 0000000..e844d75
--- /dev/null
@@ -0,0 +1,9 @@
+1 ----
+4 -----------<---+-
+8 -----------<---+-=---->-----------
+2 --------
+6 -----------<---+-=---->--
+3 -----------<-
+9 -----------<---+-=---->---------------
+5 -----------<---+-=---
+2 --------