#!/usr/bin/perl use strict; use warnings; use constant { MAX => 1, SIGIL => 0 }; $| = 1; chomp( my $term_lines = 0+`tput lines` ); chomp( my $term_columns = 0+`tput cols` ); @ARGV % 2 == 0 or die "$0: SIGIL SCALE ...\n"; my @trackers = map [ @ARGV[$_*2, 1+($_*2) ] ], 0 .. $#ARGV / 2; my @lines; while (<STDIN>) { my @F = /(\d+)/g or next; push @lines, \ @F; shift @lines if @lines >= $term_lines; # Drop my colored dots onto the field. my @cols = (' ') x $term_columns; for my $ix ( 0 .. $#trackers ) { my $tracker = $trackers[$ix]; my $max = \ $tracker->[MAX]; my $sigil = $tracker->[SIGIL]; my $datum = $F[$ix]; if ( $$max < $datum ) { $$max = $datum; } my $scale = $$max; my $adjusted = $scale == 0 ? 0 : $datum / $scale; my $start_col = $#cols * $adjusted; for my $char ( 0 .. length($sigil)-1 ) { $cols[ $start_col + $char ] = "\e[" . (31 + $ix) . 'm' . sub +str( $sigil, $char, 1 ) . "\e[0m"; } # print "ix:$ix,col:$$col,max:$$max,sigil:$sigil,datum:$datum, +scale:$scale,adjusted:$adjusted,col_idx:$col_idx\n"; } splice @cols, $term_columns - 1 if @cols > $term_columns; print join( '', @cols ) . "\n"; }
In reply to Lookee - Streaming graph for a console by diotalevi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |