From: Geoffrey Thomas Date: Fri, 20 Feb 2009 08:30:49 +0000 (-0500) Subject: Hash personals recipients and pick random colors based on the hash. X-Git-Url: https://sipb.mit.edu/gitweb.cgi/snippets/.git/commitdiff_plain/44f8db5d57c370f9ac8ef2dace7343ff23053e30 Hash personals recipients and pick random colors based on the hash. Needs some work... --- diff --git a/barnowl/personal-colors.pl b/barnowl/personal-colors.pl new file mode 100644 index 0000000..0e40c42 --- /dev/null +++ b/barnowl/personal-colors.pl @@ -0,0 +1,28 @@ +# Automatically colors personals by hashing the username. Inspired by geofft's +# .bashrc. Needs a lot of tweaking to make perfect... +# +# To use: +# :perl do '/mit/snippets/barnowl/personal-colors.pl' +# :view -s colors + +package BarnOwl::Style::Colors; +our @ISA=qw(BarnOwl::Style::Default); +use Digest::MD5; + +sub description {"Colors for personals";} + +sub format_chat { + my $self = shift; + my $m = shift; + my $body = $self->indent_body($m); + if ($m->is_personal) { + my @colors = qw{red green blue yellow magenta cyan}; + my $hash = ord Digest::MD5::md5(($m->direction eq "out") ? $m->pretty_recipient : $m->pretty_sender); + $body = '@[@color(' . $colors[$hash % scalar @colors] . ")$body]"; + } + return $self->chat_header($m) . "\n". $body; +} + +BarnOwl::create_style("colors", "BarnOwl::Style::Colors"); + +1;