html/mirc_colour_popup.pl


   1 #!/usr/bin/perl
   2 # mirc_colour_popup irssi module
   3 #
   4 # Shows a mIRC-style colour popup when you hit ^C.
   5 #
   6 # usage:
   7 #
   8 # after loading the script, add the statusbar item somewhere convenient: 
   9 #   /statusbar window add -after barstart colours
  10 #
  11 
  12 use strict;
  13 use Irssi;
  14 use Irssi::TextUI;
  15 use vars qw($VERSION %IRSSI);
  16 
  17 $VERSION = "1.0";
  18 %IRSSI = (
  19     authors     => "Michael Kowalchuk",
  20     contact     => "michael.kowalchuk\@gmail.com",
  21     name        => "mirc_colour_popup",
  22     description => "Shows a mIRC-style colour popup when you hit ^C.",
  23     license     => "Public Domain",
  24     changed     => "9.26.2008",
  25 );
  26 
  27 
  28 my $vis;
  29 
  30 my @colours = ('W','k','b','g','R','r','m','y','Y','G','c','C','B','P','K','w');
  31 
  32 sub colours_sb {
  33 	my ($item, $get_size_only) = @_;
  34 
  35 	my $txt;
  36 	if( $vis ) {
  37 		$txt = join " ", map { "\%$colours[$_]$_" } 0 .. 15;
  38 	}
  39 	$item->default_handler($get_size_only, "{sb $txt}", undef, 1);
  40 }
  41 
  42 
  43 Irssi::signal_add_last 'gui key pressed' => sub {
  44 	my ($key) = @_;
  45 
  46 	if( not $vis and $key eq 3 ) {
  47 		$vis = 1;
  48 		Irssi::statusbar_items_redraw('colours');
  49 	}
  50 
  51 	elsif( $vis and $key ne 3 ) {
  52 		$vis = undef;
  53 		Irssi::statusbar_items_redraw('colours');
  54 	}
  55 
  56 };
  57 
  58 Irssi::statusbar_item_register('colours', undef, 'colours_sb');
  59 
  60