Colorise list output
authorJoey Schulze <joey@infodrom.org>
Wed, 10 Jul 2019 20:18:32 +0000 (22:18 +0200)
committerJoey Schulze <joey@infodrom.org>
Wed, 10 Jul 2019 20:18:32 +0000 (22:18 +0200)
src/InfoCon/stempel/stempel

index 7bb7bbc..ad7bb0a 100755 (executable)
@@ -23,6 +23,7 @@ use warnings;
 use DBI;
 use Getopt::Long;
 use Term::ReadLine;
 use DBI;
 use Getopt::Long;
 use Term::ReadLine;
+use Term::ANSIColor;
 
 my $table = "stempel";
 my $engine = "dbi:Pg:dbname=infocon";
 
 my $table = "stempel";
 my $engine = "dbi:Pg:dbname=infocon";
@@ -273,12 +274,25 @@ sub list
 
     my $sth = $dbh->prepare ($query);
 
 
     my $sth = $dbh->prepare ($query);
 
+    my $customer = '';
+    my @colors = qw/blue green yellow red cyan magenta/;
+    my $color = $#colors;
     if ($sth && $sth->execute > 0) {
        while ((my $row = $sth->fetchrow_hashref)) {
            if (defined $row->{time}) {
     if ($sth && $sth->execute > 0) {
        while ((my $row = $sth->fetchrow_hashref)) {
            if (defined $row->{time}) {
+               if ($customer ne $row->{customer}) {
+                   $customer = $row->{customer};
+                   if ($color == $#colors) {
+                       $color = 0;
+                   } else {
+                       $color++;
+                   }
+               }
                my $day = (split(/ /, $row->{start}))[0];
                my $time = min2hour $row->{time};
                my $day = (split(/ /, $row->{start}))[0];
                my $time = min2hour $row->{time};
-               printf "%-15s  %s  %s  %s\n", $row->{customer}, $day, $time, $row->{task};
+               print color($colors[$color]);
+               printf "%-15s  %s  %s  %s", $row->{customer}, $day, $time, $row->{task};
+               print color('reset'), "\n";
            }
        }
     }
            }
        }
     }