]> sipb.mit.edu Git - snippets/.git/blob - barnowl/personal-colors.pl
barnowl/zcrypt.pl: Pass the unencrypted message to zcrypt
[snippets/.git] / barnowl / personal-colors.pl
1 # Automatically colors personals by hashing the username. Inspired by geofft's
2 # .bashrc. Needs a lot of tweaking to make perfect...
3 #
4 # To use:
5 #   :perl do '/mit/snippets/barnowl/personal-colors.pl'
6 #   :view -s colors
7
8 package BarnOwl::Style::Colors;
9 our @ISA=qw(BarnOwl::Style::Default);
10 use Digest::MD5;
11
12 sub description {"Colors for personals";}
13
14 sub format_chat {
15     my $self = shift;
16     my $m = shift;
17     my $body = $self->indent_body($m);
18     if ($m->is_personal) {
19       my @colors = qw{red green blue yellow magenta cyan};
20       my $hash = ord Digest::MD5::md5(($m->direction eq "out") ? $m->pretty_recipient : $m->pretty_sender);
21       $body = '@[@color(' . $colors[$hash % scalar @colors] . ")$body]";
22     }
23     return $self->chat_header($m) . "\n". $body;
24 }
25
26 BarnOwl::create_style("colors", "BarnOwl::Style::Colors");
27
28 1;