siccolor (1206B) [raw]
1 #!/usr/bin/env perl 2 # siccolor -- colorize sic(1) output 3 use strict; 4 use warnings; 5 use Term::ANSIColor; 6 7 # No black (bg), white (text/msg), bright white, or bright black (time) 8 my @colors = qw( 9 green 10 yellow 11 blue 12 magenta 13 cyan 14 bright_green 15 bright_yellow 16 bright_blue 17 bright_magenta 18 bright_cyan 19 ); 20 21 our $i = 0; 22 our %user_colors; 23 main(); 24 25 sub main { 26 while (my $line = <>) { 27 if ($line =~ m{^([^:]+):\s+(\d\d\d\d-\d\d-\d\d \d\d:\d\d) (<[^>]+>)(.*)}) { 28 my ($channel, $time, $user, $msg) = ($1, $2, $3, $4); 29 print get_color($channel) . "$channel"; 30 print color("bright_black"); 31 print ": $time "; 32 print get_color($user) . "$user"; 33 print color("reset"); 34 print "$msg\n"; 35 } else { 36 # Don't know how to colorize! 37 print color("bright_black"); 38 print "$line"; 39 print color("reset"); 40 } 41 } 42 } 43 44 sub get_color { 45 my ($val) = @_; 46 if (!exists $user_colors{$val}) { 47 $user_colors{$val} = $colors[$i % @colors]; 48 $i++; 49 } 50 return color($user_colors{$val}); 51 }