highlight cell which changed
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 17 Jun 2016 09:02:33 +0000 (11:02 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 17 Jun 2016 09:02:33 +0000 (11:02 +0200)
gpio.pl

diff --git a/gpio.pl b/gpio.pl
index 95425a3..69390e2 100755 (executable)
--- a/gpio.pl
+++ b/gpio.pl
@@ -4,9 +4,9 @@ my @last;
 
 while(1) {
 
-my @o;
 my @pcf = `gpio -x pcf8591:120:0x48 readall`;
 my @gpio = `gpio -g readall`;
+my $i = 0;
 foreach (@gpio) {
        chomp;
 #      next unless /\d\s/;
@@ -18,8 +18,20 @@ foreach (@gpio) {
        s/([ \d]{2})(...GPIO.)../$1$2$1/;
        s/(GPIO.)..(...)(\s*\d+)/$1$3$2$3/;
 
-       push @o, $_;
-       print $_, shift @pcf || "\n";
+       my $line = $_ . ( shift @pcf || '');
+       chomp $line;
+       if ( $last[$i] && $line ne $last[$i] ) {
+               my @l = split(/\|/, $line);
+               my @o = split(/\|/, $last[$i]);
+               foreach my $i ( 0 .. $#l ) {
+                       $l[$i] = "\e[33;7;1m$l[$i]\e[0m" if $l[$i] ne $o[$i];
+               }
+               print join('|', @l), "|\n";
+       } else {
+               print "$line\n";
+       }
+       $last[$i] = $line;
+       $i++;
 }
 
 my $cmd = <STDIN>;