1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# John Engelbrecht's original versions (<= 1.0.2) were released under the public
# domain. Ryan Kavanagh's changes are distributed under the ISC license:
#
# Copyright (C) 2017 Ryan Kavanagh <rak@ryanak.ca>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
use strict;
use vars qw($VERSION %IRSSI);
use Irssi;
use Irssi::Irc;
use Irssi::TextUI;
$VERSION = '2.0';
%IRSSI = (
authors => 'John Engelbrecht, Ryan Kavanagh',
contact => 'jengelbr@yahoo.com, rak@ryanak.ca',
name => 'twtopic.pl',
description => 'Animated Topic bar.',
sbitems => 'twtopic',
license => 'Public Domain, ISC',
changed => 'Wed Jan 03 16:20:17 EST 2017',
url => 'http://irssi.darktalker.net' . "\n",
);
my $instrut =
".--------------------------------------------------.\n"
. "| 1.) shell> mkdir ~/.irssi/scripts |\n"
. "| 2.) shell> cp twtopic.pl ~/.irssi/scripts/ |\n"
. "| 3.) shell> mkdir ~/.irssi/scripts/autorun |\n"
. "| 4.) shell> ln -s ~/.irssi/scripts/twtopic.pl \\ |\n"
. "| ~/.irssi/scripts/autorun/twtopic.pl |\n"
. "| 5.) /sbar topic remove topic |\n"
. "| 6.) /sbar topic remove topic_empty |\n"
. "| 7.) /sbar topic add -after topicbarstart |\n"
. "| -priority 100 -alignment left twtopic |\n"
. "| 9.) /toggle twtopic_instruct and last /save |\n"
. "|--------------------------------------------------|\n"
. "| Options: Default: |\n"
. "| /set twtopic_refresh <speed> 150 |\n"
. "| /set twtopic_size <size> 20 |\n"
. "| /set twtopic_padding <size> 20 |\n"
. "| /set twtopic_auto_resize <ON|OFF> OFF |\n"
. "| /set twtopic_ar_padding <size> 0 |\n"
. "| /set twtopic_min_scroll <ON|OFF> OFF |\n"
. "| /set twtopic_init_pause <length> 10 |\n"
. "| /toggle twtopic_instruct |Startup instructions |\n"
. "\`--------------------------------------------------'";
my $timeout;
my $start_pos = 0;
my $size;
my $min_scroll;
my $padding;
my $topic = "";
my @mirc_color_arr = (
"\0031", "\0035", "\0033", "\0037", "\0032", "\0036",
"\00310", "\0030", "\00314", "\0034", "\0039", "\0038",
"\00312", "\00313", "\00311", "\00315", "\017"
);
sub setup {
my $window = Irssi::active_win;
if ( Irssi::settings_get_bool('twtopic_auto_resize') ) {
$size =
$window->{'width'} - Irssi::settings_get_int('twtopic_ar_padding');
}
else {
$size = Irssi::settings_get_int('twtopic_size');
}
# Subtract 4 because we wrap the topic in '[ ' / ' ]'.
$size = $size - 4;
$min_scroll = Irssi::settings_get_bool('twtopic_min_scroll');
$padding = Irssi::settings_get_int('twtopic_padding');
update_topic();
}
sub regular_timer {
my $time = Irssi::settings_get_int('twtopic_refresh');
Irssi::timeout_remove($timeout);
$timeout = Irssi::timeout_add( $time, 'reload', undef );
}
sub init_timer {
my $time = Irssi::settings_get_int('twtopic_init_pause');
Irssi::timeout_remove($timeout);
$timeout = Irssi::timeout_add( $time, 'regular_timer', undef );
}
sub show {
my ( $item, $get_size_only ) = @_;
my $text = get();
$text = "[ " . $text . " ]";
$item->default_handler( $get_size_only, $text, undef, 1 );
}
sub update_topic {
$topic = "";
my $name = Irssi::active_win()->{active}->{name};
my $type = Irssi::active_win()->{active}->{type};
if ( $name eq "" ) {
# We're in the status window
$topic =
"Irssi website: http://www.irssi.org, "
. "Irssi IRC channel: #irssi @ irc://irc.freenode:6667, "
. "twtopic has been written by Tech Wizard and ryanakca";
}
elsif ( $type eq "QUERY" ) {
$topic = "You are now talking to...... " . $name;
}
else {
my $channel = Irssi::Irc::Server->channel_find($name);
$topic = $channel->{topic};
foreach (@mirc_color_arr) { $topic =~ s/$_//g; }
}
if ( $topic eq "" ) {
$topic = "=-=-=-=-= No Topic =-=-=-=-=-=-=-";
}
$topic =~ s/(\00313)+//;
$topic =~ s/(\002)+//;
$topic =~ s/(\001)+//;
# Reset the topic and pause
init_timer();
# The length of the topic may have changed. We should reset our $start_pos
# to avoid going off the end in case the topic got shorter.
$start_pos = -1;
reload ();
}
sub get {
my $topiclen = length($topic);
if ( $topiclen <= $size && $min_scroll ) {
return $topic . ( ' ' x ( $size - $topiclen ) );
}
my $padded = $topic . ( ' ' x $padding );
my $str = "";
my $needed = $size - length($str);
while ( $needed > 0 ) {
if ( $needed < length($padded) - $start_pos ) {
$str = $str . substr( $padded, $start_pos, $needed );
}
elsif ( $needed < length($padded) ) {
$str =
$str
. substr( $padded, $start_pos )
. substr( $padded, 0, $needed - length($padded) );
}
else {
$str =
$str
. substr( $padded, $start_pos )
. substr( $padded, 0, $start_pos );
}
$needed = $size - length($str);
}
$start_pos = $start_pos + 1 < length($padded) ? $start_pos + 1 : 0;
return $str;
}
Irssi::signal_add( 'channel topic changed', 'update_topic' );
Irssi::signal_add( 'setup changed', 'setup' );
Irssi::signal_add( 'terminal resized', 'setup' );
Irssi::signal_add( 'window changed', 'update_topic' );
Irssi::settings_add_bool( 'tech_addon', 'twtopic_auto_resize', 0 );
Irssi::settings_add_bool( 'tech_addon', 'twtopic_instruct', 1 );
Irssi::settings_add_bool( 'tech_addon', 'twtopic_min_scroll', 0 );
Irssi::settings_add_int( 'tech_addon', 'twtopic_ar_padding', 10 );
Irssi::settings_add_int( 'tech_addon', 'twtopic_init_pause', 10 );
Irssi::settings_add_int( 'tech_addon', 'twtopic_padding', 20 );
Irssi::settings_add_int( 'tech_addon', 'twtopic_refresh', 150 );
Irssi::settings_add_int( 'tech_addon', 'twtopic_size', 20 );
sub reload { Irssi::statusbar_items_redraw('twtopic'); }
if ( Irssi::settings_get_bool('twtopic_instruct') ) {
print $instrut;
}
setup();
Irssi::statusbar_item_register( 'twtopic', '$0', 'show' );
|