[2923] in BarnOwl Developers
[PATCH] Sort the output of :irc-names
daemon@ATHENA.MIT.EDU (Nelson Elhage)
Wed Feb 23 21:00:11 2011
From: Nelson Elhage <nelhage@ksplice.com>
To: barnowl-dev@mit.edu
Cc: Nelson Elhage <nelhage@mit.edu>
Date: Wed, 23 Feb 2011 21:00:02 -0500
---
.../IRC/lib/BarnOwl/Module/IRC/Connection.pm | 15 ++++++++++++++-
1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm b/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
index ba4f0c3..7cd9693 100644
--- a/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
+++ b/perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
@@ -259,11 +259,24 @@ sub on_namreply {
$self->names_tmp([@{$self->names_tmp}, split(' ', [$evt->args]->[3])]);
}
+sub cmp_user {
+ my ($lhs, $rhs) = (@_);
+ my ($sigil_l) = ($lhs =~ m{^[+@]}g);
+ my ($sigil_r) = ($rhs =~ m{^[+@]}g);
+ my %rank = (
+ '@' => 2,
+ '+' => 1,
+ '' => -1
+ );
+ return (($rank{$sigil_r}||0) <=> ($rank{$sigil_l}||0)) ||
+ $rhs cmp $lhs;
+}
+
sub on_endofnames {
my ($self, $evt) = @_;
return unless $self->names_tmp;
my $names = BarnOwl::Style::boldify("Members of " . [$evt->args]->[1] . ":\n");
- for my $name (@{$self->names_tmp}) {
+ for my $name (sort {cmp_user($a, $b)} @{$self->names_tmp}) {
$names .= " $name\n";
}
BarnOwl::popless_ztext($names);
--
1.7.2.43.g36c08.dirty