From 44f8db5d57c370f9ac8ef2dace7343ff23053e30 Mon Sep 17 00:00:00 2001 From: Geoffrey Thomas Date: Fri, 20 Feb 2009 03:30:49 -0500 Subject: [PATCH] Hash personals recipients and pick random colors based on the hash. Needs some work... --- barnowl/personal-colors.pl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 barnowl/personal-colors.pl 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; -- 2.45.0