html/scroller.pl


   1 #DEMONENS SCROLLER SCRIPT!
   2 #scroller.pl
   3 
   4 #This script will create a small 10-character scroller on the irssi status bar.
   5 #It is pretty much useless.
   6 #I use it to remind myself about meetings, phonecalls I'm supposed to make etc
   7 #
   8 #Enjoy to the extent possible.
   9 #
  10 # -Demonen
  11 #
  12 #To make it show up in irrsi, do this:
  13 # 1) put scroller.pl in ~/.irssi/scripts
  14 #    This is where irssi expects to find scripts
  15 #
  16 # 2) in irssi, give the command /script load scroller
  17 #    Some stuff will appear in your status window.
  18 #
  19 # 3) in irssi, give the command /statusbar window add -after more -alignment right scroller
  20 #    This will enable the scroller element on the status bar.
  21 #
  22 # 4) in irssi, give the command /set scrollerText <something>
  23 #    This will scroll the text <something>
  24 #
  25 # 5) in irssi, give the command /set scrollerSpeed <something>
  26 #    This is the delay in milliseconds before it cycles to the next character.
  27 #    I use 200 here, but anything above 10 is just fine.
  28 
  29 
  30 use Irssi;
  31 use strict;
  32 
  33 use vars qw($VERSION %IRSSI);
  34 
  35 $VERSION="0.01";
  36 %IRSSI = (
  37 	authors=> 'Demonen',
  38 	contact=> 'demmydemon@gmail.com',
  39 	name=> 'scroller',
  40 	description=> 'Scrolls specified text on the status bar',
  41 	license=> 'Public Domain',
  42 );
  43 
  44 
  45 my ($scalarSize, $subset, $start, $end, $timeout, $count, $time, $scalar);
  46 
  47 
  48 sub scrollerStatusbar() {
  49     my ($item, $get_size_only) = @_;
  50         $item->default_handler($get_size_only, "{sb ".$subset."}", undef, 1);
  51 }
  52 
  53 
  54 sub scrollerTimeout() {
  55     if ($count > $scalarSize){
  56         $count = 0;
  57     }else{
  58         $count++;
  59     }
  60     $start = $count;
  61     $end   = 10;
  62     $subset = (substr $scalar, $start, $end);    
  63     Irssi::statusbar_items_redraw('scroller');
  64 }
  65 
  66 
  67 sub scrollerUpdate() {
  68     $scalar = Irssi::settings_get_str('scrollerText');
  69     $scalar = "- - - ->".$scalar."- - - ->";
  70     print "Scrolling: \" $scalar \"";
  71     $scalarSize = length($scalar) -11;
  72     $count = 0;
  73     Irssi::timeout_remove($timeout);
  74     if (Irssi::settings_get_int('scrollerSpeed') < 10){
  75         Irssi::settings_set_int('scrollerSpeed', 10);
  76         print "Sorry, minimum delay for timeouts in irssi is 10 ms.  Delay set to 10 ms.";
  77     }
  78     $timeout = Irssi::timeout_add(Irssi::settings_get_int('scrollerSpeed'), 'scrollerTimeout' , undef);
  79 }
  80 
  81 
  82 sub scrollerStart() {
  83     Irssi::settings_add_str('misc', 'scrollerText', 'Scrolling text not defined.  Use "/set scrollerText <something>" to define it');
  84     Irssi::settings_add_int('misc', 'scrollerSpeed', 200);
  85     $timeout = Irssi::timeout_add(Irssi::settings_get_int('scrollerSpeed'), 'scrollerTimeout' , undef);
  86     Irssi::statusbar_item_register('scroller', '$0', 'scrollerStatusbar');
  87     Irssi::command_bind scrollthis => \&scrollthis;
  88     Irssi::signal_add('setup changed', 'scrollerUpdate');
  89     &scrollerUpdate();
  90 }
  91 
  92 
  93 &scrollerStart();
  94 print "Use \"/set scrollerText <something>\" to scroll <something>";
  95 print "Use \"/set scrollerSpeed <int>\" to set the delay in milliseconds";