]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
update tmux-nicklist-portable
authorAilin Nemui <redacted>
Tue, 26 Apr 2016 21:14:54 +0000 (23:14 +0200)
committerAilin Nemui <redacted>
Tue, 26 Apr 2016 21:14:54 +0000 (23:14 +0200)
- implement documented but non-existant feature
- add gone sort option
- add support for realnames script

scripts/tmux-nicklist-portable.pl

index d4da3dc4596894c61f4bd422d336b0a58e1b850f..9bb9e1579e178649277e3d7175b36e116b09c669 100644 (file)
@@ -23,6 +23,8 @@
 # * colourise the nicks in the nicklist (required nickcolor script
 #   with get_nick_color2 and debug_ansicolour functions)
 # 
+# /set nicklist_gone_sort <ON|OFF>
+# * sort away people below
 #
 # It supports mouse scrolling and the following keys:
 # k/up arrow: up one line
@@ -43,7 +45,7 @@ use IO::Select;
 use POSIX;
 use File::Temp qw/ :mktemp  /;
 use File::Basename;
-our $VERSION = '0.1.3'; # 82c05732e50bb62
+our $VERSION = '0.1.4'; # f969473d9e99a9a
 our %IRSSI = (
   authors     => 'Thiago de Arruda',
   contact     => 'tpadilha84@gmail.com',
@@ -132,11 +134,12 @@ sub reset_nicklist {
     $channel_pattern = eval { qr/$channel_pattern/ };
     $channel_pattern = qr/(?!)/ if $@;
   }
-
+  my $smallest_main = Irssi::settings_get_int('nicklist_smallest_main');
   if (!$channel || !ref($channel)
       || !$channel->isa('Irssi::Channel')
       || !$channel->{'names_got'}
-      || $channel->{'name'} !~ $channel_pattern) {
+      || $channel->{'name'} !~ $channel_pattern
+      || ($smallest_main && $channel->window->{width} < $smallest_main)) {
     disable_nicklist;
   } else {
     my %colour;
@@ -151,21 +154,31 @@ sub reset_nicklist {
         $colour{$nick->{nick}} = ($ansifier && $colourer) ? $ansifier->($colourer->($active->{active}{server}{tag}, $channel->{name}, $nick->{nick}, 0)) : '';
       }
       print($fifo "BEGIN\n");
-      foreach my $nick (sort {(($a->{'op'}?'1':$a->{'halfop'}?'2':$a->{'voice'}?'3':$a->{'other'}>32?'0':'4').lc($a->{'nick'}))
-        cmp (($b->{'op'}?'1':$b->{'halfop'}?'2':$b->{'voice'}?'3':$b->{'other'}>32?'0':'4').lc($b->{'nick'}))} @nicks) {
+      my $gone_sort = Irssi::settings_get_bool('nicklist_gone_sort');
+      my $prefer_real;
+      if (exists $Irssi::Script::{'realnames::'}) {
+         my $code = "Irssi::Script::realnames"->can('use_realnames');
+         $prefer_real = $code && $code->($channel);
+      }
+      my $_real = sub {
+         my $nick = shift;
+         $prefer_real && length $nick->{'realname'} ? $nick->{'realname'} : $nick->{'nick'}
+      };
+      foreach my $nick (sort {($a->{'op'}?'1':$a->{'halfop'}?'2':$a->{'voice'}?'3':$a->{'other'}>32?'0':'4').($gone_sort?($a->{'gone'}?1:0):'').lc($_real->($a))
+        cmp ($b->{'op'}?'1':$b->{'halfop'}?'2':$b->{'voice'}?'3':$b->{'other'}>32?'0':'4').($gone_sort?($b->{'gone'}?1:0):'').lc($_real->($b))} @nicks) {
         my $colour = $colour{$nick->{nick}} || "\e[39m";
        $colour = "\e[37m" if $nick->{'gone'};
         print($fifo "NICK");
         if ($nick->{'op'}) {
-          print($fifo "\e[32m\@$colour$nick->{'nick'}\e[39m");
+          print($fifo "\e[32m\@$colour".$_real->($nick)."\e[39m");
         } elsif ($nick->{'halfop'}) {
-          print($fifo "\e[34m%$colour$nick->{'nick'}\e[39m");
+          print($fifo "\e[34m%$colour".$_real->($nick)."\e[39m");
         } elsif ($nick->{'voice'}) {
-          print($fifo "\e[33m+$colour$nick->{'nick'}\e[39m");
+          print($fifo "\e[33m+$colour".$_real->($nick)."\e[39m");
         } elsif ($nick->{'other'}>32) {
-          print($fifo "\e[31m".(chr $nick->{'other'})."$colour$nick->{'nick'}\e[39m");
+          print($fifo "\e[31m".(chr $nick->{'other'})."$colour".$_real->($nick)."\e[39m");
         } else {
-          print($fifo " $colour$nick->{'nick'}\e[39m");
+          print($fifo " $colour".$_real->($nick)."\e[39m");
         }
         print($fifo "\n");
       }
@@ -188,7 +201,7 @@ sub resized_timed {
 sub resized {
   $resize_timer = undef;
   return if defined $just_launched;
-  return unless $enabled > 0;
+  return unless $enabled >= 0;
   disable_nicklist;
   Irssi::timeout_add_once(200, \&reset_nicklist, '');
 }
@@ -201,6 +214,7 @@ Irssi::settings_add_int('tmux_nicklist', 'nicklist_max_users', 0);
 Irssi::settings_add_int('tmux_nicklist', 'nicklist_smallest_main', 0);
 Irssi::settings_add_int('tmux_nicklist', 'nicklist_pane_width', 13);
 Irssi::settings_add_bool('tmux_nicklist', 'nicklist_color', 1);
+Irssi::settings_add_bool('tmux_nicklist', 'nicklist_gone_sort', 0);
 Irssi::signal_add_last('window item changed', \&switch_channel);
 Irssi::signal_add_last('window changed', \&switch_channel);
 Irssi::signal_add_last('channel joined', \&switch_channel);
git clone https://git.99rst.org/PROJECT