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
30use Irssi;
31use Irssi::TextUI;
32use strict;
33
34use vars qw($VERSION %IRSSI);
35
36$VERSION="0.02";
37%IRSSI = (
38	authors=> 'Demonen',
39	contact=> 'demmydemon@gmail.com',
40	name=> 'scroller',
41	description=> 'Scrolls specified text on the status bar',
42	sbitems=> 'scroller',
43	license=> 'Public Domain',
44);
45
46
47my ($scalarSize, $subset, $start, $end, $timeout, $count, $time, $scalar);
48
49
50sub scrollerStatusbar() {
51    my ($item, $get_size_only) = @_;
52        $item->default_handler($get_size_only, "{sb ".$subset."}", undef, 1);
53}
54
55
56sub scrollerTimeout() {
57    if ($count > $scalarSize){
58        $count = 0;
59    }else{
60        $count++;
61    }
62    $start = $count;
63    $end   = 10;
64    $subset = (substr $scalar, $start, $end);
65    Irssi::statusbar_items_redraw('scroller');
66}
67
68
69sub scrollerUpdate() {
70    $scalar = Irssi::settings_get_str('scrollerText');
71    $scalar = "- - - ->".$scalar."- - - ->";
72    print "Scrolling: \" $scalar \"";
73    $scalarSize = length($scalar) -11;
74    $count = 0;
75    Irssi::timeout_remove($timeout);
76    if (Irssi::settings_get_int('scrollerSpeed') < 10){
77        Irssi::settings_set_int('scrollerSpeed', 10);
78        print "Sorry, minimum delay for timeouts in irssi is 10 ms.  Delay set to 10 ms.";
79    }
80    $timeout = Irssi::timeout_add(Irssi::settings_get_int('scrollerSpeed'), 'scrollerTimeout' , undef);
81}
82
83
84sub scrollerStart() {
85    Irssi::settings_add_str('misc', 'scrollerText', 'Scrolling text not defined.  Use "/set scrollerText <something>" to define it');
86    Irssi::settings_add_int('misc', 'scrollerSpeed', 200);
87    $timeout = Irssi::timeout_add(Irssi::settings_get_int('scrollerSpeed'), 'scrollerTimeout' , undef);
88    Irssi::statusbar_item_register('scroller', '$0', 'scrollerStatusbar');
89	#Irssi::command_bind scrollthis => \&scrollthis;
90    Irssi::signal_add('setup changed', 'scrollerUpdate');
91    &scrollerUpdate();
92}
93
94
95&scrollerStart();
96print "Use \"/set scrollerText <something>\" to scroll <something>";
97print "Use \"/set scrollerSpeed <int>\" to set the delay in milliseconds";
98