]> git.madduck.net Git - code/irssi/scripts-bc-bd.git/blob - rotator.pl

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

allow per-window level specifications
[code/irssi/scripts-bc-bd.git] / rotator.pl
1 use Irssi;
2 use Irssi::TextUI;
3 use strict;
4
5 use vars qw($VERSION %IRSSI);
6
7 $VERSION="0.2.1";
8 %IRSSI = (
9         authors=> 'BC-bd',
10         contact=> 'bd@bc-bd.org',
11         name=> 'rotator',
12         description=> 'Displaye a small, changeing statusbar item to show irssi is still running',
13         license=> 'GPL v2',
14         url=> 'https://bc-bd.org/svn/repos/irssi/rotator',
15 );
16
17 # rotator Displaye a small, changeing statusbar item to show irssi is still running
18 # for irssi 0.8.4 by bd@bc-bd.org
19 #
20 #########
21 # USAGE
22 ###
23
24 # To use this script type f.e.:
25 #
26 #               /statusbar window add -after more -alignment right rotator
27 #
28 # For more info on statusbars read the docs for /statusbar
29 #
30 #########
31 # OPTIONS
32 #########
33 #
34 # /set rotator_seperator <char>
35 #       The character that is used to split the string in elements.
36 #
37 # /set rotator_chars <string>
38 #       The string to display. Examples are:
39 #
40 #               /set rotator_chars . o 0 O
41 #               /set rotator_chars _ ­ ¯
42 #               /set rotator_chars %r­ %Y- %g-
43 #
44 # /set rotator_speed <int>
45 #       The number of milliseconds to display every char.
46 #       1 second = 1000 milliseconds.
47 #
48 # /set rotator_bounce <ON|OFF>
49 #               * ON  : reverse direction at the end of rotator_chars
50 #               * OFF : start from the beginning
51 #
52 ###
53 ################
54 ###
55 # Changelog
56 #
57 # Version 0.2.1
58 #  - checking rotator_speed to be > 10
59 #
60 # Version 0.2
61 #  - added rotator_bounce
62 #  - added rotator_seperator
63 #  - added support for elements longer than one char
64 #  - fixed displaying of special chars (thx to peder for pointing this one out)
65 #
66 # Version 0.1
67 #  - initial release
68 #
69 ###
70 ################
71
72 my ($pos,$char,$timeout,$boundary,$direction);
73
74 $char = '';
75
76 sub rotatorTimeout {
77         my @rot = split(Irssi::settings_get_str('rotator_seperator'), Irssi::settings_get_str('rotator_chars'));
78         my $len = scalar @rot;
79
80         $char = quotemeta($rot[$pos]);
81
82         if ($pos == $boundary) {
83                 if (Irssi::settings_get_bool('rotator_bounce')) {
84                         if ($direction < 0) {
85                                 $boundary = $len -1;
86                         } else {
87                                 $boundary = 0;
88                         }
89                         $direction *= -1;
90                 } else {
91                         $pos = -1;
92                 }
93         }
94
95         $pos += $direction;
96
97         Irssi::statusbar_items_redraw('rotator');
98 }
99
100 sub rotatorStatusbar() {
101         my ($item, $get_size_only) = @_;
102
103         $item->default_handler($get_size_only, "{sb ".$char."}", undef, 1);
104 }
105
106 sub rotatorSetup() {
107         my $time = Irssi::settings_get_int('rotator_speed');
108
109         Irssi::timeout_remove($timeout);
110
111         $boundary = scalar split(Irssi::settings_get_str('rotator_seperator'), Irssi::settings_get_str('rotator_chars')) -1;
112         $direction = +1;
113         $pos = 0;
114
115         if ($time < 10) {
116                 Irssi::print("rotator: rotator_speed must be > 10");
117         } else {
118                 $timeout = Irssi::timeout_add($time, 'rotatorTimeout' , undef);
119         }
120 }
121
122 Irssi::signal_add('setup changed', 'rotatorSetup');
123
124 Irssi::statusbar_item_register('rotator', '$0', 'rotatorStatusbar');
125
126 Irssi::settings_add_str('misc', 'rotator_chars', '. o 0 O 0 o');
127 Irssi::settings_add_str('misc', 'rotator_seperator', ' ');
128 Irssi::settings_add_int('misc', 'rotator_speed', 2000);
129 Irssi::settings_add_bool('misc', 'rotator_bounce', 1);
130
131 if (Irssi::settings_get_int('rotator_speed') < 10) {
132         Irssi::print("rotator: rotator_speed must be > 10");
133 } else {
134         $timeout = Irssi::timeout_add(Irssi::settings_get_int('rotator_speed'), 'rotatorTimeout' , undef);
135 }
136
137 rotatorSetup();