Skip to content

Commit 15065a2

Browse files
kevgsrobertbindar
authored andcommitted
MDEV-19531 Add colors to mtr
Colors possibility auto detected. [ such ] stuff is colored. Patch by Sergei Golubchik
1 parent 167da05 commit 15065a2

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

mysql-test/lib/mtr_report.pm

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ use POSIX qw[ _exit ];
3636
use IO::Handle qw[ flush ];
3737
use mtr_results;
3838

39+
use Term::ANSIColor;
40+
41+
my %color_map = qw/pass green
42+
retry-pass green
43+
fail red
44+
retry-fail red
45+
disabled bright_black
46+
skipped yellow
47+
reset reset/;
48+
sub xterm_color {
49+
if (-t STDOUT and defined $ENV{TERM} and $ENV{TERM} =~ /xterm/) {
50+
syswrite STDOUT, color($color_map{$_[0]});
51+
}
52+
}
53+
3954
my $tot_real_time= 0;
4055

4156
our $timestamp= 0;
@@ -494,7 +509,16 @@ sub mtr_print (@) {
494509
sub mtr_report (@) {
495510
if (defined $verbose)
496511
{
497-
print _name(). join(" ", @_). "\n";
512+
my @s = split /\[ (\S+) \]/, _name() . "@_\n";
513+
if (@s > 1) {
514+
print $s[0];
515+
xterm_color($s[1]);
516+
print "[ $s[1] ]";
517+
xterm_color('reset');
518+
print $s[2];
519+
} else {
520+
print $s[0];
521+
}
498522
}
499523
}
500524

0 commit comments

Comments
 (0)