]> sipb.mit.edu Git - snippets/.git/commitdiff
Hash personals recipients and pick random colors based on the hash.
authorGeoffrey Thomas <geofft@mit.edu>
Fri, 20 Feb 2009 08:30:49 +0000 (03:30 -0500)
committerGeoffrey Thomas <geofft@mit.edu>
Fri, 20 Feb 2009 08:30:49 +0000 (03:30 -0500)
Needs some work...

barnowl/personal-colors.pl [new file with mode: 0644]

diff --git a/barnowl/personal-colors.pl b/barnowl/personal-colors.pl
new file mode 100644 (file)
index 0000000..0e40c42
--- /dev/null
@@ -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;