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.
1 # BitchX TAB complete style
2 # for irssi 0.7.99 by bd@bc-bd.org
4 # <tab> signal handling learned from dictcomplete by Timo Sirainen
6 # thx go out to fuchs, darix, dg, peder and all on #irssi who helped
12 # In a channel window type "ab<tab>" to see a list of nicks starting
14 # If you now press <tab> again, irssi will default to its own nick
16 # If you enter more characters you can use <tab> again to see a list
17 # of the matching nicks, or to complete the nick if there is only
20 # The last completion is saved so if you press "<tab>" with an empty
21 # input line, you get the last completed nick.
23 # Now there is a statusbar item where you can see the completing
24 # nicks instead of in the channel window. There are two ways to
27 # 1) Inside another statusbar
29 # /set niq_show_in_statusbar ON
30 # /statusbar window add -before more niq
32 # 2) In an own statusbar
34 # /set niq_show_in_statusbar ON
35 # /set niq_own_statusbar ON
37 # WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
39 # THIS IS CURRENTLY BROKEN IN IRSSI 0.8.4 AND ONLY WORKS WITH
40 # THE ACTUAL CVS VERSION. USEING THIS ON AN VERSION 0.8.4 OR
41 # OLDER WILL ERASE YOUR INPUT LINE
43 # With 2) you can also set
45 # /set niq_hide_on_inactive ON
47 # which will only show the bar if you complete nicks.
49 # WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
55 # /set niq_show_in_statusbar <ON|OFF>
56 # * ON : show the completing nicks in a statusbar item
57 # * OFF : show the nicks in the channel window
59 # /set niq_own_statusbar <ON|OFF>
60 # * ON : use an own statusbar for the nicks
61 # * OFF : just use an item
63 # /set niq_hide_on_inactive <ON|OFF>
64 # * ON : hide the own statusbar on inactivity
65 # * OFF : dont hide it
67 # /set niq_color_char <ON|OFF>
68 # * ON : colors the next unlikely character
69 # * OFF : boring no colors
77 # - work around an use problem
80 # - fixed completion for nicks starting with special chars
83 # - removed unneeded sort() of colored nicks
84 # - moved colored nick generation to where it is needed
85 # - the statusbar only worked with colorized nicks (duh!)
88 # - stop nickcompleting if last char is the completion_char
89 # which is in most cases ':'
92 # - fixed vanishing statusbar. it wrongly was reset on any
96 # - changed statusbar to be off by default since most people
97 # dont use the latest fixed version.
100 # - added own statusbar option
101 # - added color char option
104 # - added an niq statusbar
107 # - added default to irssi method on <tab><tab>
110 # - added lastcomp support
121 use vars qw($VERSION %IRSSI);
126 contact=> 'bd@bc-bd.org',
128 description=> 'BitchX like Nickcompletion at line start plus statusbar',
130 url=> 'https://bc-bd.org/svn/repos/irssi/niq',
133 my($lastword,$lastcomp,$niqString);
138 # build our nick with completion_char, add to complist and stop the signal
139 sub buildNickAndStop {
140 my ($complist,$nick) = @_;
141 my $push = $nick.Irssi::settings_get_str('completion_char');
145 push (@{$complist}, $push);
147 if (Irssi::settings_get_bool('niq_show_in_statusbar') == 1) {
151 Irssi::signal_stop();
156 my ($complist, $window, $word, $linestart, $want_space) = @_;
158 # still allow channel- #<tab>, /set n<tab>, etc completion.
159 if ($linestart ne "") {
163 # also back out if nothing has been entered and lastcomp is ""
165 if ($lastcomp ne "") {
166 buildNickAndStop($complist,$lastcomp);
172 if (rindex($word,Irssi::settings_get_str('completion_char')) == length($word) -1) {
174 buildNickAndStop($complist,$word,0);
178 my $channel = $window->{active};
180 # the completion is ok if this is a channel
181 if ($channel->{type} ne "CHANNEL")
188 # get the matching nicks but quote this l33t special chars like ^
189 my $shortestNick = 999;
190 my $quoted = quotemeta $word;
191 foreach my $n ($channel->nicks()) {
192 if ($n->{nick} =~ /^$quoted/i && $window->{active_server}->{nick} ne $n->{nick}) {
193 push(@nicks,$n->{nick});
194 if (length($n->{nick}) < $shortestNick) {
195 $shortestNick = length($n->{nick});
200 @nicks = sort(@nicks);
202 # if theres only one nick return it.
203 if (scalar @nicks eq 1)
205 buildNickAndStop($complist,$nicks[0]);
206 } elsif (scalar @nicks gt 1) {
207 # check if this is <tab> or <tab><tab>
208 if ($lastword eq $word) {
209 # <tab><tab> so default to the irssi method
211 for (@nicks) { $_ .= ':'; }
212 push (@{$complist}, @nicks);
214 # but delete lastword to be ready for the next <tab>
217 if (Irssi::settings_get_bool('niq_show_in_statusbar') == 1) {
223 # <tab> only so just print
226 # TODO way too slow, need some ideas first!
228 # find the longest matching subword
229 # Irssi::print(join(" ",@nicks));
230 # Irssi::print($shortestNick);
233 # for ($i = length($word); $exit == 0 && $i <$shortestNick; $i++) {
234 # my $char = substr($nicks[0],$i,1);
235 # Irssi::print($i." ".$char);
236 # foreach $n (@nicks) {
238 # if (substr($n,$i,1) ne $char) {
241 # Irssi::print("exit: ".$i);
246 # $word = substr($nicks[0],0,$i);
247 # Irssi::print($word);
250 # $$complist[0] = $word;
253 # build string w/o colored nicks
254 if (Irssi::settings_get_bool('niq_color_char') == 1) {
256 foreach my $n (@nicks) {
257 my $coloredNick = $n;
258 $coloredNick =~ s/($quoted)(.)(.*)/$1%_$2%_$3/i;
259 $niqString .= "$coloredNick ";
262 $niqString = join(" ",@nicks);
265 if (Irssi::settings_get_bool('niq_show_in_statusbar') == 1) {
266 drawStatusbar($niqString);
268 $window->print($niqString);
271 Irssi::signal_stop();
280 # we have not found a nick, so someone used <tab> within another conttext
281 # and thus $lastword is no longer of interest
291 sub drawStatusbar() {
294 if (Irssi::settings_get_bool('niq_own_statusbar') == 1) {
295 if (Irssi::settings_get_bool('niq_hide_on_inactive') == 1) {
297 Irssi::command("statusbar niq disable");
299 Irssi::command("statusbar niq enable");
304 $niqString = "{sb $word}";
305 Irssi::statusbar_items_redraw('niq');
309 my ($item, $get_size_only) = @_;
311 $item->default_handler($get_size_only, $niqString, undef, 1);
314 Irssi::signal_add_first('complete word', 'sig_complete');
315 Irssi::signal_add_last('window changed', 'emptyBar');
316 #Irssi::signal_add('event privmsg', 'emptyBar');
317 Irssi::signal_add('message own_public', 'emptyBar');
319 Irssi::statusbar_item_register('niq', '$0', 'niqStatusbar');
320 Irssi::statusbars_recreate_items();
322 Irssi::settings_add_bool('misc', 'niq_show_in_statusbar', 0);
323 Irssi::settings_add_bool('misc', 'niq_own_statusbar', 0);
324 Irssi::settings_add_bool('misc', 'niq_hide_on_inactive', 1);
325 Irssi::settings_add_bool('misc', 'niq_color_char', 1);