dotfiles

$HOME is where the <3 is
git clone git://git.alexkarle.com/dotfiles.git
Log | Files | Refs | Submodules | README

irccolor (910B) [raw]


      1 #!/usr/bin/env perl
      2 # irccolor -- filter to colorize the output of irclogs
      3 #   usage: irclogs sr.ht | irccolor | less -R
      4 use strict;
      5 use warnings;
      6 use Term::ANSIColor;
      7 
      8 # No black (bg), white (text/msg), bright white, or bright black (time)
      9 my @colors = qw(
     10 	red
     11 	green
     12 	yellow
     13 	blue
     14 	magenta
     15 	cyan
     16 	bright_red
     17 	bright_green
     18 	bright_yellow
     19 	bright_blue
     20 	bright_magenta
     21 	bright_cyan
     22 );
     23 
     24 my $i = 0;
     25 my %user_colors;
     26 while (my $line = <>) {
     27 	if ($line =~ m{(\d\d\d\d-\d\d-\d\d).log:\[(\d\d:\d\d:\d\d)]\s*(<[^>]+>)(.*)}) {
     28 		my ($date, $time, $user, $msg) = ($1, $2, $3, $4);
     29 		print color("bright_black");
     30 		print "[$date $time] ";
     31 		print color("reset");
     32 		if (!exists $user_colors{$user}) {
     33 			$user_colors{$user} = $colors[$i % @colors];
     34 			$i++;
     35 		}
     36 		print color("$user_colors{$user}");
     37 		print $user;
     38 		print color("reset");
     39 		print "$msg\n";
     40 	} else {
     41 		# Don't know how to colorize!
     42 		print "$line";
     43 	}
     44 }