File: htcolor

package info (click to toggle)
httest 2.4.23-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,876 kB
  • sloc: ansic: 19,553; sh: 10,550; xml: 1,047; makefile: 510; lisp: 145; perl: 31
file content (46 lines) | stat: -rwxr-xr-x 1,267 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/perl
# colors httest output, just pipe into this script...
# $ httest block.htt | htcolor
# $ cat block.htt.out | htcolor
# color both stdout and stderr...
# $ { { httest $@ 1>&3 2>&4; } 4>&1 | htcolor -e; } 3>&1 1>&2 | htcolor
if ($ARGV[0] eq "-e") {
  while (<STDIN>) {
    my $line = $_;
    chomp($line);
    # failed: strong
    $line =~ s/failed/\033[1;31m$&\033[0;31m/i;
    # stderr: red
    print "\033[0;31m$line\033[0m\n";
  }
} else {
  while (<STDIN>) {
    my $line = $_;
    chomp($line);
    if ($line =~ m/^([0-9]+:)? *([<>])/) {
      # out: strong, in: light
      $strong = ($2 eq ">") ? "1" : "0";
      if ($line =~ m/^([0-9]+:)?[<>]/) {
        # client: blue
        $color="34";
      } elsif ($line =~ m/^([0-9]+:)? {1,24}[<>]/) {
        # server: green
        $color="32";
      } elsif ($line =~ m/^([0-9]+:)? {25,48}[<>]/) {
        # server 2: purple
        $color="35";
      } else {
        # more servers: brown
        $color="33";
      }
      print "\033[$strong;${color}m$line\033[0m\n";
    } elsif ($line =~ m/^ *\_[_-]/) {
      # data: normal
      print "$line\n";
    } else {
      # rest: normal (keywords bold)
      $line =~ s/^ *[A-Z_][A-Z_:]*[ \t]/\033[1m$&\033[0m/;
      print "$line\n";
    }
  }
}