From 0805868da411e08ef1b0f180f39bd49943984537 Mon Sep 17 00:00:00 2001 From: Joey Schulze Date: Wed, 10 Jul 2019 22:18:32 +0200 Subject: [PATCH] Colorise list output --- src/InfoCon/stempel/stempel | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/InfoCon/stempel/stempel b/src/InfoCon/stempel/stempel index 7bb7bbc..ad7bb0a 100755 --- a/src/InfoCon/stempel/stempel +++ b/src/InfoCon/stempel/stempel @@ -23,6 +23,7 @@ use warnings; use DBI; use Getopt::Long; use Term::ReadLine; +use Term::ANSIColor; my $table = "stempel"; my $engine = "dbi:Pg:dbname=infocon"; @@ -273,12 +274,25 @@ sub list 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 ($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}; - 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"; } } } -- 2.20.1