2 # Copyright (C) 2008-2014 Sebastien Helleu <flashcode@flashtux.org>
3 # Copyright (C) 2011-2013 Nils G <weechatter@arcor.de>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Display sidebar with list of buffers.
23 # 2014-04-05, Sebastien Helleu <flashcode@flashtux.org>:
24 # v4.6: add support of hidden buffers (WeeChat >= 0.4.4)
25 # 2014-01-01, Sebastien Helleu <flashcode@flashtux.org>:
26 # v4.5: add option "mouse_move_buffer"
27 # 2013-12-11, Sebastien Helleu <flashcode@flashtux.org>:
28 # v4.4: fix buffer number on drag to the end of list when option
29 # weechat.look.buffer_auto_renumber is off
30 # 2013-12-10, nils_2@freenode.#weechat:
31 # v4.3: add options "prefix_bufname" and "suffix_bufname (idea by silverd)
32 # : fix hook_timer() for show_lag wasn't disabled
33 # : improved signal handling (less updating of buffers list)
34 # 2013-11-07, Sebastien Helleu <flashcode@flashtux.org>:
35 # v4.2: use default filling "columns_vertical" when bar position is top/bottom
36 # 2013-10-31, nils_2@freenode.#weechat:
37 # v4.1: add option "detach_buffer_immediately" (idea by farn)
38 # 2013-10-20, nils_2@freenode.#weechat:
39 # v4.0: add options "detach_displayed_buffers", "detach_display_window_number"
40 # 2013-09-27, nils_2@freenode.#weechat:
41 # v3.9: add option "toggle_bar" and option "show_prefix_query" (idea by IvarB)
42 # : fix problem with linefeed at end of list of buffers (reported by grawity)
43 # 2012-10-18, nils_2@freenode.#weechat:
44 # v3.8: add option "mark_inactive", to mark buffers you are not in (idea by xrdodrx)
45 # : add wildcard "*" for immune_detach_buffers (idea by StarWeaver)
46 # : add new options "detach_query" and "detach_free_content" (idea by StarWeaver)
47 # 2012-10-06, Nei <anti.teamidiot.de>:
48 # v3.7: call menu on right mouse if menu script is loaded.
49 # 2012-10-06, nils_2 <weechatter@arcor.de>:
50 # v3.6: add new option "hotlist_counter" (idea by torque).
51 # 2012-06-02, nils_2 <weechatter@arcor.de>:
52 # v3.5: add values "server|channel|private|all|keepserver|none" to option "hide_merged_buffers" (suggested by dominikh).
53 # 2012-05-25, nils_2 <weechatter@arcor.de>:
54 # v3.4: add new option "show_lag".
55 # 2012-04-07, Sebastien Helleu <flashcode@flashtux.org>:
56 # v3.3: fix truncation of wide chars in buffer name (option name_size_max) (bug #36034)
57 # 2012-03-15, nils_2 <weechatter@arcor.de>:
58 # v3.2: add new option "detach"(weechat >= 0.3.8)
59 # add new option "immune_detach_buffers" (requested by Mkaysi)
60 # add new function buffers_whitelist add|del|reset (suggested by FiXato)
61 # add new function buffers_detach add|del|reset
62 # 2012-03-09, Sebastien Helleu <flashcode@flashtux.org>:
63 # v3.1: fix reload of config file
64 # 2012-01-29, nils_2 <weechatter@arcor.de>:
65 # v3.0: fix: buffers did not update directly during window_switch (reported by FiXato)
66 # 2012-01-29, nils_2 <weechatter@arcor.de>:
67 # v2.9: add options "name_size_max" and "name_crop_suffix"
68 # 2012-01-08, nils_2 <weechatter@arcor.de>:
69 # v2.8: fix indenting for option "show_number off"
70 # fix unset of buffer activity in hotlist when buffer was moved with mouse
71 # add buffer with free content and core buffer sorted first (suggested by nyuszika7h)
72 # add options queries_default_fg/bg and queries_message_fg/bg (suggested by FiXato)
73 # add clicking with left button on current buffer will do a jump_previously_visited_buffer (suggested by FiXato)
74 # add clicking with right button on current buffer will do a jump_next_visited_buffer
75 # add additional informations in help texts
76 # add default_fg and default_bg for whitelist channels
77 # internal changes (script is now 3Kb smaller)
78 # 2012-01-04, Sebastien Helleu <flashcode@flashtux.org>:
79 # v2.7: fix regex lookup in whitelist buffers list
80 # 2011-12-04, nils_2 <weechatter@arcor.de>:
81 # v2.6: add own config file (buffers.conf)
82 # add new behavior for indenting (under_name)
83 # add new option to set different color for server buffers and buffers with free content
84 # 2011-10-30, nils_2 <weechatter@arcor.de>:
85 # v2.5: add new options "show_number_char" and "color_number_char",
86 # add help-description for options
87 # 2011-08-24, Sebastien Helleu <flashcode@flashtux.org>:
88 # v2.4: add mouse support
89 # 2011-06-06, nils_2 <weechatter@arcor.de>:
90 # v2.3: added: missed option "color_whitelist_default"
91 # 2011-03-23, Sebastien Helleu <flashcode@flashtux.org>:
92 # v2.2: fix color of nick prefix with WeeChat >= 0.3.5
93 # 2011-02-13, nils_2 <weechatter@arcor.de>:
94 # v2.1: add options "color_whitelist_*"
95 # 2010-10-05, Sebastien Helleu <flashcode@flashtux.org>:
96 # v2.0: add options "sort" and "show_number"
97 # 2010-04-12, Sebastien Helleu <flashcode@flashtux.org>:
98 # v1.9: replace call to log() by length() to align buffer numbers
99 # 2010-04-02, Sebastien Helleu <flashcode@flashtux.org>:
100 # v1.8: fix bug with background color and option indenting_number
101 # 2010-04-02, Helios <helios@efemes.de>:
102 # v1.7: add indenting_number option
103 # 2010-02-25, m4v <lambdae2@gmail.com>:
104 # v1.6: add option to hide empty prefixes
105 # 2010-02-12, Sebastien Helleu <flashcode@flashtux.org>:
106 # v1.5: add optional nick prefix for buffers like IRC channels
107 # 2009-09-30, Sebastien Helleu <flashcode@flashtux.org>:
108 # v1.4: remove spaces for indenting when bar position is top/bottom
109 # 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
110 # v1.3: add option "hide_merged_buffers"
111 # 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
112 # v1.2: improve display with merged buffers
113 # 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
114 # v1.1: sync with last API changes
115 # 2009-02-21, Sebastien Helleu <flashcode@flashtux.org>:
116 # v1.0: remove timer used to update bar item first time (not needed any more)
117 # 2009-02-17, Sebastien Helleu <flashcode@flashtux.org>:
118 # v0.9: fix bug with indenting of private buffers
119 # 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
120 # v0.8: update syntax for command /set (comments)
121 # 2008-10-20, Jiri Golembiovsky <golemj@gmail.com>:
122 # v0.7: add indenting option
123 # 2008-10-01, Sebastien Helleu <flashcode@flashtux.org>:
124 # v0.6: add default color for buffers, and color for current active buffer
125 # 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
126 # v0.5: fix color for "low" level entry in hotlist
127 # 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
128 # v0.4: rename option "show_category" to "short_names",
129 # remove option "color_slash"
130 # 2008-09-15, Sebastien Helleu <flashcode@flashtux.org>:
131 # v0.3: fix bug with priority in hotlist (var not defined)
132 # 2008-09-02, Sebastien Helleu <flashcode@flashtux.org>:
133 # v0.2: add color for buffers with activity and config options for
134 # colors, add config option to display/hide categories
135 # 2008-03-15, Sebastien Helleu <flashcode@flashtux.org>:
136 # v0.1: script creation
138 # Help about settings:
139 # display all settings for script (or use iset.pl script to change settings):
141 # show help text for option buffers.look.whitelist_buffers:
142 # /help buffers.look.whitelist_buffers
144 # Mouse-support (standard key bindings):
146 # - click on a buffer to switch to selected buffer
147 # - click on current buffer will do action jump_previously_visited_buffer
148 # - drag a buffer and drop it on another position will move the buffer to position
149 # right mouse-button:
150 # - click on current buffer will do action jump_next_visited_buffer
151 # - moving buffer to the left/right will close buffer.
155 use Encode
qw( decode encode );
156 # -----------------------------[ internal ]-------------------------------------
157 my $SCRIPT_NAME = "buffers";
158 my $SCRIPT_VERSION = "4.6";
160 my $BUFFERS_CONFIG_FILE_NAME = "buffers";
161 my $buffers_config_file;
162 my $cmd_buffers_whitelist= "buffers_whitelist";
163 my $cmd_buffers_detach = "buffers_detach";
165 my %mouse_keys = ("\@item(buffers):button1*" => "hsignal:buffers_mouse",
166 "\@item(buffers):button2*" => "hsignal:buffers_mouse");
168 my %hotlist_level = (0 => "low", 1 => "message", 2 => "private", 3 => "highlight");
169 my @whitelist_buffers = ();
170 my @immune_detach_buffers= ();
171 my @detach_buffer_immediately= ();
172 my @buffers_focus = ();
173 my %buffers_timer = ();
176 # --------------------------------[ init ]--------------------------------------
177 weechat
::register
($SCRIPT_NAME, "Sebastien Helleu <flashcode\@flashtux.org>",
178 $SCRIPT_VERSION, "GPL3",
179 "Sidebar with list of buffers", "shutdown_cb", "");
180 my $weechat_version = weechat
::info_get
("version_number", "") || 0;
182 buffers_config_init
();
183 buffers_config_read
();
185 weechat
::bar_item_new
($SCRIPT_NAME, "build_buffers", "");
186 weechat
::bar_new
($SCRIPT_NAME, "0", "0", "root", "", "left", "columns_vertical",
187 "vertical", "0", "0", "default", "default", "default", "1",
190 if ( check_bar_item
() == 0 )
192 weechat
::command
("", "/bar show " . $SCRIPT_NAME) if ( weechat
::config_boolean
($options{"toggle_bar"}) eq 1 );
195 weechat
::hook_signal
("buffer_opened", "buffers_signal_buffer", "");
196 weechat
::hook_signal
("buffer_closed", "buffers_signal_buffer", "");
197 weechat
::hook_signal
("buffer_merged", "buffers_signal_buffer", "");
198 weechat
::hook_signal
("buffer_unmerged", "buffers_signal_buffer", "");
199 weechat
::hook_signal
("buffer_moved", "buffers_signal_buffer", "");
200 weechat
::hook_signal
("buffer_renamed", "buffers_signal_buffer", "");
201 weechat
::hook_signal
("buffer_switch", "buffers_signal_buffer", "");
202 weechat
::hook_signal
("buffer_hidden", "buffers_signal_buffer", ""); # WeeChat >= 0.4.4
203 weechat
::hook_signal
("buffer_unhidden", "buffers_signal_buffer", ""); # WeeChat >= 0.4.4
205 weechat
::hook_signal
("window_switch", "buffers_signal_buffer", "");
206 weechat
::hook_signal
("hotlist_changed", "buffers_signal_hotlist", "");
207 #weechat::hook_command_run("/input switch_active_*", "buffers_signal_buffer", "");
208 weechat
::bar_item_update
($SCRIPT_NAME);
211 if ($weechat_version >= 0x00030600)
213 weechat
::hook_focus
($SCRIPT_NAME, "buffers_focus_buffers", "");
214 weechat
::hook_hsignal
("buffers_mouse", "buffers_hsignal_mouse", "");
215 weechat
::key_bind
("mouse", \
%mouse_keys);
218 weechat
::hook_command
($cmd_buffers_whitelist,
219 "add/del current buffer to/from buffers whitelist",
220 "[add] || [del] || [reset]",
221 " add: add current buffer in configuration file\n".
222 " del: delete current buffer from configuration file\n".
223 "reset: reset all buffers from configuration file ".
224 "(no confirmation!)\n\n".
226 "/$cmd_buffers_whitelist add\n",
230 "buffers_cmd_whitelist", "");
231 weechat
::hook_command
($cmd_buffers_detach,
232 "add/del current buffer to/from buffers detach",
233 "[add] || [del] || [reset]",
234 " add: add current buffer in configuration file\n".
235 " del: delete current buffer from configuration file\n".
236 "reset: reset all buffers from configuration file ".
237 "(no confirmation!)\n\n".
239 "/$cmd_buffers_detach add\n",
243 "buffers_cmd_detach", "");
245 if ($weechat_version >= 0x00030800)
247 weechat
::hook_config
("buffers.look.detach", "hook_timer_detach", "");
248 if (weechat
::config_integer
($options{"detach"}) > 0)
250 $Hooks{timer_detach
} = weechat
::hook_timer
(weechat
::config_integer
($options{"detach"}) * 1000,
251 60, 0, "buffers_signal_hotlist", "");
255 weechat
::hook_config
("buffers.look.show_lag", "hook_timer_lag", "");
257 if (weechat
::config_boolean
($options{"show_lag"}))
259 $Hooks{timer_lag
} = weechat
::hook_timer
(
260 weechat
::config_integer
(weechat
::config_get
("irc.network.lag_refresh_interval")) * 1000,
261 0, 0, "buffers_signal_hotlist", "");
264 # -------------------------------- [ command ] --------------------------------
265 sub buffers_cmd_whitelist
267 my ( $data, $buffer, $args ) = @_;
269 my $buffers_whitelist = weechat
::config_string
( weechat
::config_get
("buffers.look.whitelist_buffers") );
270 return weechat
::WEECHAT_RC_OK
if ( $buffers_whitelist eq "" and $args eq "del" or $buffers_whitelist eq "" and $args eq "reset" );
271 my @buffers_list = split( /,/, $buffers_whitelist );
273 my $infolist = weechat
::infolist_get
("buffer", weechat
::current_buffer
(), "");
274 weechat
::infolist_next
($infolist);
275 my $buffers_name = weechat
::infolist_string
($infolist, "name");
276 weechat
::infolist_free
($infolist);
277 return weechat
::WEECHAT_RC_OK
if ( $buffers_name eq "" ); # should never happen
279 if ( $args eq "add" )
281 return weechat
::WEECHAT_RC_OK
if ( grep /^$buffers_name$/, @buffers_list ); # check if buffer already in list
282 push @buffers_list, ( $buffers_name );
283 my $buffers_list = &create_whitelist
(\
@buffers_list);
284 weechat
::config_option_set
( weechat
::config_get
("buffers.look.whitelist_buffers"), $buffers_list, 1);
285 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" added to buffers whitelist");
287 elsif ( $args eq "del" )
289 return weechat
::WEECHAT_RC_OK
unless ( grep /^$buffers_name$/, @buffers_list ); # check if buffer is in list
290 @buffers_list = grep {$_ ne $buffers_name} @buffers_list; # delete entry
291 my $buffers_list = &create_whitelist
(\
@buffers_list);
292 weechat
::config_option_set
( weechat
::config_get
("buffers.look.whitelist_buffers"), $buffers_list, 1);
293 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" deleted from buffers whitelist");
295 elsif ( $args eq "reset" )
297 return weechat
::WEECHAT_RC_OK
if ( $buffers_whitelist eq "" );
298 weechat
::config_option_set
( weechat
::config_get
("buffers.look.whitelist_buffers"), "", 1);
299 weechat
::print(weechat
::current_buffer
(), "buffers whitelist is empty, now...");
301 return weechat
::WEECHAT_RC_OK
;
303 sub buffers_cmd_detach
305 my ( $data, $buffer, $args ) = @_;
307 my $immune_detach_buffers = weechat
::config_string
( weechat
::config_get
("buffers.look.immune_detach_buffers") );
308 return weechat
::WEECHAT_RC_OK
if ( $immune_detach_buffers eq "" and $args eq "del" or $immune_detach_buffers eq "" and $args eq "reset" );
310 my @buffers_list = split( /,/, $immune_detach_buffers );
312 my $infolist = weechat
::infolist_get
("buffer", weechat
::current_buffer
(), "");
313 weechat
::infolist_next
($infolist);
314 my $buffers_name = weechat
::infolist_string
($infolist, "name");
315 weechat
::infolist_free
($infolist);
316 return weechat
::WEECHAT_RC_OK
if ( $buffers_name eq "" ); # should never happen
318 if ( $args eq "add" )
320 return weechat
::WEECHAT_RC_OK
if ( grep /^$buffers_name$/, @buffers_list ); # check if buffer already in list
321 push @buffers_list, ( $buffers_name );
322 my $buffers_list = &create_whitelist
(\
@buffers_list);
323 weechat
::config_option_set
( weechat
::config_get
("buffers.look.immune_detach_buffers"), $buffers_list, 1);
324 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" added to immune detach buffers");
326 elsif ( $args eq "del" )
328 return weechat
::WEECHAT_RC_OK
unless ( grep /^$buffers_name$/, @buffers_list ); # check if buffer is in list
329 @buffers_list = grep {$_ ne $buffers_name} @buffers_list; # delete entry
330 my $buffers_list = &create_whitelist
(\
@buffers_list);
331 weechat
::config_option_set
( weechat
::config_get
("buffers.look.immune_detach_buffers"), $buffers_list, 1);
332 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" deleted from immune detach buffers");
334 elsif ( $args eq "reset" )
336 return weechat
::WEECHAT_RC_OK
if ( $immune_detach_buffers eq "" );
337 weechat
::config_option_set
( weechat
::config_get
("buffers.look.immune_detach_buffers"), "", 1);
338 weechat
::print(weechat
::current_buffer
(), "immune detach buffers is empty, now...");
340 return weechat
::WEECHAT_RC_OK
;
345 my @buffers_list = @{$_[0]};
346 my $buffers_list = "";
347 foreach (@buffers_list)
349 $buffers_list .= $_ .",";
353 return $buffers_list;
356 # -------------------------------- [ config ] --------------------------------
357 sub hook_timer_detach
362 weechat
::unhook
($Hooks{timer_detach
}) if $Hooks{timer_detach
};
363 $Hooks{timer_detach
} = "";
367 weechat
::unhook
($Hooks{timer_detach
}) if $Hooks{timer_detach
};
368 $Hooks{timer_detach
} = weechat
::hook_timer
( weechat
::config_integer
( $options{"detach"}) * 1000, 60, 0, "buffers_signal_hotlist", "");
370 weechat
::bar_item_update
($SCRIPT_NAME);
371 return weechat
::WEECHAT_RC_OK
;
379 weechat
::unhook
($Hooks{timer_lag
}) if $Hooks{timer_lag
};
380 $Hooks{timer_lag
} = "";
384 weechat
::unhook
($Hooks{timer_lag
}) if $Hooks{timer_lag
};
385 $Hooks{timer_lag
} = weechat
::hook_timer
( weechat
::config_integer
(weechat
::config_get
("irc.network.lag_refresh_interval")) * 1000, 0, 0, "buffers_signal_hotlist", "");
387 weechat
::bar_item_update
($SCRIPT_NAME);
388 return weechat
::WEECHAT_RC_OK
;
391 sub buffers_config_read
393 return weechat
::config_read
($buffers_config_file) if ($buffers_config_file ne "");
395 sub buffers_config_write
397 return weechat
::config_write
($buffers_config_file) if ($buffers_config_file ne "");
399 sub buffers_config_reload_cb
401 my ($data, $config_file) = ($_[0], $_[1]);
402 return weechat
::config_reload
($config_file)
404 sub buffers_config_init
406 $buffers_config_file = weechat
::config_new
($BUFFERS_CONFIG_FILE_NAME,
407 "buffers_config_reload_cb", "");
408 return if ($buffers_config_file eq "");
410 my %default_options_color =
411 ("color_current_fg" => [
412 "current_fg", "color",
413 "foreground color for current buffer",
414 "", 0, 0, "lightcyan", "lightcyan", 0,
415 "", "", "buffers_signal_config", "", "", ""
417 "color_current_bg" => [
418 "current_bg", "color",
419 "background color for current buffer",
420 "", 0, 0, "red", "red", 0,
421 "", "", "buffers_signal_config", "", "", ""
423 "color_default_fg" => [
424 "default_fg", "color",
425 "default foreground color for buffer name",
426 "", 0, 0, "default", "default", 0,
427 "", "", "buffers_signal_config", "", "", ""
429 "color_default_bg" => [
430 "default_bg", "color",
431 "default background color for buffer name",
432 "", 0, 0, "default", "default", 0,
433 "", "", "buffers_signal_config", "", "", ""
435 "color_hotlist_highlight_fg" => [
436 "hotlist_highlight_fg", "color",
437 "change foreground color of buffer name if a highlight messaged received",
438 "", 0, 0, "magenta", "magenta", 0,
439 "", "", "buffers_signal_config", "", "", ""
441 "color_hotlist_highlight_bg" => [
442 "hotlist_highlight_bg", "color",
443 "change background color of buffer name if a highlight messaged received",
444 "", 0, 0, "default", "default", 0,
445 "", "", "buffers_signal_config", "", "", ""
447 "color_hotlist_low_fg" => [
448 "hotlist_low_fg", "color",
449 "change foreground color of buffer name if a low message received",
450 "", 0, 0, "white", "white", 0,
451 "", "", "buffers_signal_config", "", "", ""
453 "color_hotlist_low_bg" => [
454 "hotlist_low_bg", "color",
455 "change background color of buffer name if a low message received",
456 "", 0, 0, "default", "default", 0,
457 "", "", "buffers_signal_config", "", "", ""
459 "color_hotlist_message_fg" => [
460 "hotlist_message_fg", "color",
461 "change foreground color of buffer name if a normal message received",
462 "", 0, 0, "yellow", "yellow", 0,
463 "", "", "buffers_signal_config", "", "", ""
465 "color_hotlist_message_bg" => [
466 "hotlist_message_bg", "color",
467 "change background color of buffer name if a normal message received",
468 "", 0, 0, "default", "default", 0,
469 "", "", "buffers_signal_config", "", "", ""
471 "color_hotlist_private_fg" => [
472 "hotlist_private_fg", "color",
473 "change foreground color of buffer name if a private message received",
474 "", 0, 0, "lightgreen", "lightgreen", 0,
475 "", "", "buffers_signal_config", "", "", ""
477 "color_hotlist_private_bg" => [
478 "hotlist_private_bg", "color",
479 "change background color of buffer name if a private message received",
480 "", 0, 0, "default", "default", 0,
481 "", "", "buffers_signal_config", "", "", ""
485 "color for buffer number",
486 "", 0, 0, "lightgreen", "lightgreen", 0,
487 "", "", "buffers_signal_config", "", "", ""
489 "color_number_char" => [
490 "number_char", "color",
491 "color for buffer number char",
492 "", 0, 0, "lightgreen", "lightgreen", 0,
493 "", "", "buffers_signal_config", "", "", ""
495 "color_whitelist_default_fg" => [
496 "whitelist_default_fg", "color",
497 "default foreground color for whitelist buffer name",
499 "", "", "buffers_signal_config", "", "", ""
501 "color_whitelist_default_bg" => [
502 "whitelist_default_bg", "color",
503 "default background color for whitelist buffer name",
505 "", "", "buffers_signal_config", "", "", ""
507 "color_whitelist_low_fg" => [
508 "whitelist_low_fg", "color",
509 "low color of whitelist buffer name",
511 "", "", "buffers_signal_config", "", "", ""
513 "color_whitelist_low_bg" => [
514 "whitelist_low_bg", "color",
515 "low color of whitelist buffer name",
517 "", "", "buffers_signal_config", "", "", ""
519 "color_whitelist_message_fg" => [
520 "whitelist_message_fg", "color",
521 "message color of whitelist buffer name",
523 "", "", "buffers_signal_config", "", "", ""
525 "color_whitelist_message_bg" => [
526 "whitelist_message_bg", "color",
527 "message color of whitelist buffer name",
529 "", "", "buffers_signal_config", "", "", ""
531 "color_whitelist_private_fg" => [
532 "whitelist_private_fg", "color",
533 "private color of whitelist buffer name",
535 "", "", "buffers_signal_config", "", "", ""
537 "color_whitelist_private_bg" => [
538 "whitelist_private_bg", "color",
539 "private color of whitelist buffer name",
541 "", "", "buffers_signal_config", "", "", ""
543 "color_whitelist_highlight_fg" => [
544 "whitelist_highlight_fg", "color",
545 "highlight color of whitelist buffer name",
547 "", "", "buffers_signal_config", "", "", ""
549 "color_whitelist_highlight_bg" => [
550 "whitelist_highlight_bg", "color",
551 "highlight color of whitelist buffer name",
553 "", "", "buffers_signal_config", "", "", ""
555 "color_none_channel_fg" => [
556 "none_channel_fg", "color",
557 "foreground color for none channel buffer (e.g.: core/server/plugin ".
559 "", 0, 0, "default", "default", 0,
560 "", "", "buffers_signal_config", "", "", ""
562 "color_none_channel_bg" => [
563 "none_channel_bg", "color",
564 "background color for none channel buffer (e.g.: core/server/plugin ".
566 "", 0, 0, "default", "default", 0,
567 "", "", "buffers_signal_config", "", "", ""
569 "queries_default_fg" => [
570 "queries_default_fg", "color",
571 "foreground color for query buffer without message",
572 "", 0, 0, "default", "default", 0,
573 "", "", "buffers_signal_config", "", "", ""
575 "queries_default_bg" => [
576 "queries_default_bg", "color",
577 "background color for query buffer without message",
578 "", 0, 0, "default", "default", 0,
579 "", "", "buffers_signal_config", "", "", ""
581 "queries_message_fg" => [
582 "queries_message_fg", "color",
583 "foreground color for query buffer with unread message",
584 "", 0, 0, "default", "default", 0,
585 "", "", "buffers_signal_config", "", "", ""
587 "queries_message_bg" => [
588 "queries_message_bg", "color",
589 "background color for query buffer with unread message",
590 "", 0, 0, "default", "default", 0,
591 "", "", "buffers_signal_config", "", "", ""
593 "queries_highlight_fg" => [
594 "queries_highlight_fg", "color",
595 "foreground color for query buffer with unread highlight",
596 "", 0, 0, "default", "default", 0,
597 "", "", "buffers_signal_config", "", "", ""
599 "queries_highlight_bg" => [
600 "queries_highlight_bg", "color",
601 "background color for query buffer with unread highlight",
602 "", 0, 0, "default", "default", 0,
603 "", "", "buffers_signal_config", "", "", ""
605 "color_prefix_bufname" => [
606 "prefix_bufname", "color",
607 "color for prefix of buffer name",
608 "", 0, 0, "default", "default", 0,
609 "", "", "buffers_signal_config", "", "", ""
611 "color_suffix_bufname" => [
612 "suffix_bufname", "color",
613 "color for suffix of buffer name",
614 "", 0, 0, "default", "default", 0,
615 "", "", "buffers_signal_config", "", "", ""
619 my %default_options_look =
621 "hotlist_counter" => [
622 "hotlist_counter", "boolean",
623 "show number of message for the buffer (this option needs WeeChat >= ".
624 "0.3.5). The relevant option for notification is \"weechat.look.".
625 "buffer_notify_default\"",
626 "", 0, 0, "off", "off", 0,
627 "", "", "buffers_signal_config", "", "", ""
630 "show_lag", "boolean",
631 "show lag behind servername. This option is using \"irc.color.".
632 "item_lag_finished\", ".
633 "\"irc.network.lag_min_show\" and \"irc.network.lag_refresh_interval\"",
634 "", 0, 0, "off", "off", 0,
635 "", "", "buffers_signal_config", "", "", ""
637 "look_whitelist_buffers" => [
638 "whitelist_buffers", "string",
639 "comma separated list of buffers for using a different color scheme ".
640 "(for example: freenode.#weechat,freenode.#weechat-fr)",
642 "", "", "buffers_signal_config_whitelist", "", "", ""
644 "hide_merged_buffers" => [
645 "hide_merged_buffers", "integer",
646 "hide merged buffers. The value determines which merged buffers should ".
647 "be hidden, keepserver meaning 'all except server buffers'. Other values ".
648 "correspondent to the buffer type.",
649 "server|channel|private|keepserver|all|none", 0, 0, "none", "none", 0,
650 "", "", "buffers_signal_config", "", "", ""
653 "indenting", "integer", "use indenting for channel and query buffers. ".
654 "This option only takes effect if bar is left/right positioned",
655 "off|on|under_name", 0, 0, "off", "off", 0,
656 "", "", "buffers_signal_config", "", "", ""
658 "indenting_number" => [
659 "indenting_number", "boolean",
660 "use indenting for numbers. This option only takes effect if bar is ".
661 "left/right positioned",
662 "", 0, 0, "on", "on", 0,
663 "", "", "buffers_signal_config", "", "", ""
666 "short_names", "boolean",
667 "display short names (remove text before first \".\" in buffer name)",
668 "", 0, 0, "on", "on", 0,
669 "", "", "buffers_signal_config", "", "", ""
672 "show_number", "boolean",
673 "display channel number in front of buffername",
674 "", 0, 0, "on", "on", 0,
675 "", "", "buffers_signal_config", "", "", ""
677 "show_number_char" => [
678 "number_char", "string",
679 "display a char behind channel number",
680 "", 0, 0, ".", ".", 0,
681 "", "", "buffers_signal_config", "", "", ""
683 "show_prefix_bufname" => [
684 "prefix_bufname", "string",
685 "prefix displayed in front of buffername",
687 "", "", "buffers_signal_config", "", "", ""
689 "show_suffix_bufname" => [
690 "suffix_bufname", "string",
691 "suffix displayed at end of buffername",
693 "", "", "buffers_signal_config", "", "", ""
697 "displays your prefix for channel in front of buffername",
698 "", 0, 0, "off", "off", 0,
699 "", "", "buffers_signal_config", "", "", ""
701 "show_prefix_empty" => [
702 "prefix_empty", "boolean",
703 "use a placeholder for channels without prefix",
704 "", 0, 0, "on", "on", 0,
705 "", "", "buffers_signal_config", "", "", ""
707 "show_prefix_query" => [
708 "prefix_for_query", "string",
709 "prefix displayed in front of query buffer",
711 "", "", "buffers_signal_config", "", "", ""
715 "sort buffer-list by \"number\" or \"name\"",
716 "number|name", 0, 0, "number", "number", 0,
717 "", "", "buffers_signal_config", "", "", ""
720 "core_to_front", "boolean",
721 "core buffer and buffers with free content will be listed first. ".
722 "Take only effect if buffer sort is by name",
723 "", 0, 0, "off", "off", 0,
724 "", "", "buffers_signal_config", "", "", ""
726 "jump_prev_next_visited_buffer" => [
727 "jump_prev_next_visited_buffer", "boolean",
728 "jump to previously or next visited buffer if you click with ".
729 "left/right mouse button on currently visiting buffer",
730 "", 0, 0, "off", "off", 0,
731 "", "", "buffers_signal_config", "", "", ""
734 "name_size_max", "integer",
735 "maximum size of buffer name. 0 means no limitation",
737 "", "", "buffers_signal_config", "", "", ""
739 "name_crop_suffix" => [
740 "name_crop_suffix", "string",
741 "contains an optional char(s) that is appended when buffer name is ".
743 "", 0, 0, "+", "+", 0,
744 "", "", "buffers_signal_config", "", "", ""
748 "detach channel from buffers list after a specific period of time ".
749 "(in seconds) without action (weechat ≥ 0.3.8 required) (0 means \"off\")",
750 "", 0, 31536000, 0, "number", 0,
751 "", "", "buffers_signal_config", "", "", ""
753 "immune_detach_buffers" => [
754 "immune_detach_buffers", "string",
755 "comma separated list of buffers to NOT automatically detatch. ".
756 "Allows \"*\" wildcard. Ex: \"BitlBee,freenode.*\"",
758 "", "", "buffers_signal_config_immune_detach_buffers", "", "", ""
761 "detach_query", "boolean",
762 "query buffer will be detachted",
763 "", 0, 0, "off", "off", 0,
764 "", "", "buffers_signal_config", "", "", ""
766 "detach_buffer_immediately" => [
767 "detach_buffer_immediately", "string",
768 "comma separated list of buffers to detach immediately. A query and ".
769 "highlight message will attach buffer again. Allows \"*\" wildcard. ".
770 "Ex: \"BitlBee,freenode.*\"",
772 "", "", "buffers_signal_config_detach_buffer_immediately", "", "", ""
774 "detach_free_content" => [
775 "detach_free_content", "boolean",
776 "buffers with free content will be detached (Ex: iset, chanmon)",
777 "", 0, 0, "off", "off", 0,
778 "", "", "buffers_signal_config", "", "", ""
780 "detach_displayed_buffers" => [
781 "detach_displayed_buffers", "boolean",
782 "buffers displayed in a (split) window will be detached",
783 "", 0, 0, "on", "on", 0,
784 "", "", "buffers_signal_config", "", "", ""
786 "detach_display_window_number" => [
787 "detach_display_window_number", "boolean",
788 "window number will be add, behind buffer name (this option takes only ".
789 "effect with \"detach_displayed_buffers\" option)",
790 "", 0, 0, "off", "off", 0,
791 "", "", "buffers_signal_config", "", "", ""
794 "mark_inactive", "boolean",
795 "if option is \"on\", inactive buffers (those you are not in) will have ".
796 "parentheses around them. An inactive buffer will not be detached.",
797 "", 0, 0, "off", "off", 0,
798 "", "", "buffers_signal_config", "", "", ""
801 "toogle_bar", "boolean",
802 "if option is \"on\", buffers bar will hide/show when script is ".
804 "", 0, 0, "on", "on", 0,
805 "", "", "buffers_signal_config", "", "", ""
807 "mouse_move_buffer" => [
808 "mouse_move_buffer", "boolean",
809 "if option is \"on\", mouse gestures (drag & drop) can move buffers in list.",
810 "", 0, 0, "on", "on", 0,
811 "", "", "buffers_signal_config", "", "", ""
815 my $section_color = weechat
::config_new_section
(
816 $buffers_config_file,
817 "color", 0, 0, "", "", "", "", "", "", "", "", "", "");
818 if ($section_color eq "")
820 weechat
::config_free
($buffers_config_file);
823 foreach my $option (keys %default_options_color)
825 $options{$option} = weechat
::config_new_option
(
826 $buffers_config_file,
828 $default_options_color{$option}[0],
829 $default_options_color{$option}[1],
830 $default_options_color{$option}[2],
831 $default_options_color{$option}[3],
832 $default_options_color{$option}[4],
833 $default_options_color{$option}[5],
834 $default_options_color{$option}[6],
835 $default_options_color{$option}[7],
836 $default_options_color{$option}[8],
837 $default_options_color{$option}[9],
838 $default_options_color{$option}[10],
839 $default_options_color{$option}[11],
840 $default_options_color{$option}[12],
841 $default_options_color{$option}[13],
842 $default_options_color{$option}[14]);
846 my $section_look = weechat
::config_new_section
(
847 $buffers_config_file,
848 "look", 0, 0, "", "", "", "", "", "", "", "", "", "");
849 if ($section_look eq "")
851 weechat
::config_free
($buffers_config_file);
854 foreach my $option (keys %default_options_look)
856 $options{$option} = weechat
::config_new_option
(
857 $buffers_config_file,
859 $default_options_look{$option}[0],
860 $default_options_look{$option}[1],
861 $default_options_look{$option}[2],
862 $default_options_look{$option}[3],
863 $default_options_look{$option}[4],
864 $default_options_look{$option}[5],
865 $default_options_look{$option}[6],
866 $default_options_look{$option}[7],
867 $default_options_look{$option}[8],
868 $default_options_look{$option}[9],
869 $default_options_look{$option}[10],
870 $default_options_look{$option}[11],
871 $default_options_look{$option}[12],
872 $default_options_look{$option}[13],
873 $default_options_look{$option}[14],
874 $default_options_look{$option}[15]);
882 # get bar position (left/right/top/bottom)
883 my $position = "left";
884 my $option_position = weechat
::config_get
("weechat.bar.buffers.position");
885 if ($option_position ne "")
887 $position = weechat
::config_string
($option_position);
892 my $infolist = weechat
::infolist_get
("hotlist", "", "");
893 while (weechat
::infolist_next
($infolist))
895 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")} =
896 weechat
::infolist_integer
($infolist, "priority");
897 if ( weechat
::config_boolean
( $options{"hotlist_counter"} ) eq 1 and $weechat_version >= 0x00030500)
899 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")."_count_00"} =
900 weechat
::infolist_integer
($infolist, "count_00"); # low message
901 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")."_count_01"} =
902 weechat
::infolist_integer
($infolist, "count_01"); # channel message
903 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")."_count_02"} =
904 weechat
::infolist_integer
($infolist, "count_02"); # private message
905 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")."_count_03"} =
906 weechat
::infolist_integer
($infolist, "count_03"); # highlight message
909 weechat
::infolist_free
($infolist);
918 my $max_number_digits = 0;
920 $infolist = weechat
::infolist_get
("buffer", "", "");
921 while (weechat
::infolist_next
($infolist))
923 # ignore hidden buffers (WeeChat >= 0.4.4)
924 if ($weechat_version >= 0x00040400)
926 next if (weechat
::infolist_integer
($infolist, "hidden"));
929 my $number = weechat
::infolist_integer
($infolist, "number");
930 if ($number ne $old_number)
932 @buffers = (@buffers, @current2, @current1);
937 if ($number > $max_number)
939 $max_number = $number;
941 $old_number = $number;
942 my $active = weechat
::infolist_integer
($infolist, "active");
947 $buffer->{"pointer"} = weechat
::infolist_pointer
($infolist, "pointer");
948 $buffer->{"number"} = $number;
949 $buffer->{"active"} = $active;
950 $buffer->{"current_buffer"} = weechat
::infolist_integer
($infolist, "current_buffer");
951 $buffer->{"num_displayed"} = weechat
::infolist_integer
($infolist, "num_displayed");
952 $buffer->{"plugin_name"} = weechat
::infolist_string
($infolist, "plugin_name");
953 $buffer->{"name"} = weechat
::infolist_string
($infolist, "name");
954 $buffer->{"short_name"} = weechat
::infolist_string
($infolist, "short_name");
955 $buffer->{"full_name"} = $buffer->{"plugin_name"}.".".$buffer->{"name"};
956 $buffer->{"type"} = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type");
957 #weechat::print("", $buffer->{"type"});
959 # check if buffer is active (or maybe a /part, /kick channel)
960 if ($buffer->{"type"} eq "channel" and weechat
::config_boolean
( $options{"mark_inactive"} ) eq 1)
962 my $server = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_server");
963 my $channel = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_channel");
964 my $infolist_channel = weechat
::infolist_get
("irc_channel", "", $server.",".$channel);
965 if ($infolist_channel)
967 weechat
::infolist_next
($infolist_channel);
968 $buffer->{"nicks_count"} = weechat
::infolist_integer
($infolist_channel, "nicks_count");
971 $buffer->{"nicks_count"} = 0;
973 weechat
::infolist_free
($infolist_channel);
976 my $result = check_immune_detached_buffers
($buffer->{"name"}); # checking for wildcard
978 next if ( check_detach_buffer_immediately
($buffer->{"name"}) eq 1
979 and $buffer->{"current_buffer"} eq 0
980 and ( not exists $hotlist{$buffer->{"pointer"}} or $hotlist{$buffer->{"pointer"}} < 2) ); # checking for buffer to immediately detach
984 my $detach_time = weechat
::config_integer
( $options{"detach"});
985 my $current_time = time();
986 # set timer for buffers with no hotlist action
987 $buffers_timer{$buffer->{"pointer"}} = $current_time
988 if ( not exists $hotlist{$buffer->{"pointer"}}
989 and $buffer->{"type"} eq "channel"
990 and not exists $buffers_timer{$buffer->{"pointer"}}
991 and $detach_time > 0);
993 $buffers_timer{$buffer->{"pointer"}} = $current_time
994 if (weechat
::config_boolean
($options{"detach_query"}) eq 1
995 and not exists $hotlist{$buffer->{"pointer"}}
996 and $buffer->{"type"} eq "private"
997 and not exists $buffers_timer{$buffer->{"pointer"}}
998 and $detach_time > 0);
1001 if (weechat
::config_boolean
($options{"detach_query"}) eq 0
1002 and $buffer->{"type"} eq "private");
1004 # free content buffer
1005 $buffers_timer{$buffer->{"pointer"}} = $current_time
1006 if (weechat
::config_boolean
($options{"detach_free_content"}) eq 1
1007 and not exists $hotlist{$buffer->{"pointer"}}
1008 and $buffer->{"type"} eq ""
1009 and not exists $buffers_timer{$buffer->{"pointer"}}
1010 and $detach_time > 0);
1012 if (weechat
::config_boolean
($options{"detach_free_content"}) eq 0
1013 and $buffer->{"type"} eq "");
1015 $detach_time = 0 if (weechat
::config_boolean
($options{"mark_inactive"}) eq 1 and defined $buffer->{"nicks_count"} and $buffer->{"nicks_count"} == 0);
1018 unless ( $buffer->{"current_buffer"} eq 0
1019 and not exists $hotlist{$buffer->{"pointer"}}
1020 # and $buffer->{"type"} eq "channel"
1021 and exists $buffers_timer{$buffer->{"pointer"}}
1022 and $detach_time > 0
1023 and $weechat_version >= 0x00030800
1024 and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
1028 push(@current2, $buffer);
1032 push(@current1, $buffer);
1035 elsif ( $buffer->{"current_buffer"} eq 0
1036 and not exists $hotlist{$buffer->{"pointer"}}
1037 # and $buffer->{"type"} eq "channel"
1038 and exists $buffers_timer{$buffer->{"pointer"}}
1039 and $detach_time > 0
1040 and $weechat_version >= 0x00030800
1041 and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
1042 { # check for option detach_displayed_buffers and if buffer is displayed in a split window
1043 if ( $buffer->{"num_displayed"} eq 1
1044 and weechat
::config_boolean
($options{"detach_displayed_buffers"}) eq 0 )
1046 my $infolist_window = weechat
::infolist_get
("window", "", "");
1047 while (weechat
::infolist_next
($infolist_window))
1049 my $buffer_ptr = weechat
::infolist_pointer
($infolist_window, "buffer");
1050 if ($buffer_ptr eq $buffer->{"pointer"})
1052 $buffer->{"window"} = weechat
::infolist_integer
($infolist_window, "number");
1055 weechat
::infolist_free
($infolist_window);
1057 push(@current2, $buffer);
1061 else # buffer in "immune_detach_buffers"
1065 push(@current2, $buffer);
1069 push(@current1, $buffer);
1075 if ($max_number >= 1)
1077 $max_number_digits = length(int($max_number));
1079 @buffers = (@buffers, @current2, @current1);
1080 weechat
::infolist_free
($infolist);
1082 # sort buffers by number, name or shortname
1087 for my $buffer (@buffers)
1090 if (weechat
::config_integer
( $options{"sort"} ) eq 1) # number = 0; name = 1
1092 my $name = $buffer->{"name"};
1093 $name = $buffer->{"short_name"} if (weechat
::config_boolean
( $options{"short_names"} ) eq 1);
1094 if (weechat
::config_integer
($options{"name_size_max"}) >= 1){
1095 $name = encode
("UTF-8", substr(decode
("UTF-8", $name), 0, weechat
::config_integer
($options{"name_size_max"})));
1097 if ( weechat
::config_boolean
($options{"core_to_front"}) eq 1)
1099 if ( (weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "private") )
1101 my $type = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type");
1102 if ( $type eq "" and $name ne "weechat")
1107 $name = " " . $name;
1111 $key = sprintf("%s%08d", lc($name), $buffer->{"number"});
1115 $key = sprintf("%08d", $number);
1117 $sorted_buffers{$key} = $buffer;
1122 # build string with buffers
1124 foreach my $key (sort keys %sorted_buffers)
1126 my $buffer = $sorted_buffers{$key};
1128 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "server" )
1130 # buffer type "server" or merged with core?
1131 if ( ($buffer->{"type"} eq "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1136 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "channel" )
1138 # buffer type "channel" or merged with core?
1139 if ( ($buffer->{"type"} eq "channel" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1144 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "private" )
1146 # buffer type "private" or merged with core?
1147 if ( ($buffer->{"type"} eq "private" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1152 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "keepserver" )
1154 if ( ($buffer->{"type"} ne "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1159 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "all" )
1161 if ( ! $buffer->{"active"} )
1167 push(@buffers_focus, $buffer); # buffer > buffers_focus, for mouse support
1171 $color = weechat
::config_color
( $options{"color_default_fg"} );
1172 $bg = weechat
::config_color
( $options{"color_default_bg"} );
1174 if ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") eq "private" )
1176 if ( (weechat
::config_color
($options{"queries_default_bg"})) ne "default" || (weechat
::config_color
($options{"queries_default_fg"})) ne "default" )
1178 $bg = weechat
::config_color
( $options{"queries_default_bg"} );
1179 $color = weechat
::config_color
( $options{"queries_default_fg"} );
1182 # check for core and buffer with free content
1183 if ( (weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "private") )
1185 $color = weechat
::config_color
( $options{"color_none_channel_fg"} );
1186 $bg = weechat
::config_color
( $options{"color_none_channel_bg"} );
1188 # default whitelist buffer?
1189 if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
1191 $color = weechat
::config_color
( $options{"color_whitelist_default_fg"} );
1192 $bg = weechat
::config_color
( $options{"color_whitelist_default_bg"} );
1195 $color = "default" if ($color eq "");
1197 # color for channel and query buffer
1198 if (exists $hotlist{$buffer->{"pointer"}})
1200 delete $buffers_timer{$buffer->{"pointer"}};
1201 # check if buffer is in whitelist buffer
1202 if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
1204 $bg = weechat
::config_color
( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
1205 $color = weechat
::config_color
( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
1207 elsif ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") eq "private" )
1209 # queries_default_fg/bg and buffers.color.queries_message_fg/bg
1210 if ( (weechat
::config_color
($options{"queries_highlight_fg"})) ne "default" ||
1211 (weechat
::config_color
($options{"queries_highlight_bg"})) ne "default" ||
1212 (weechat
::config_color
($options{"queries_message_fg"})) ne "default" ||
1213 (weechat
::config_color
($options{"queries_message_bg"})) ne "default" )
1215 if ( ($hotlist{$buffer->{"pointer"}}) == 2 )
1217 $bg = weechat
::config_color
( $options{"queries_message_bg"} );
1218 $color = weechat
::config_color
( $options{"queries_message_fg"} );
1221 elsif ( ($hotlist{$buffer->{"pointer"}}) == 3 )
1223 $bg = weechat
::config_color
( $options{"queries_highlight_bg"} );
1224 $color = weechat
::config_color
( $options{"queries_highlight_fg"} );
1228 $bg = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
1229 $color = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
1233 $bg = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
1234 $color = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
1238 if ($buffer->{"current_buffer"})
1240 $color = weechat
::config_color
( $options{"color_current_fg"} );
1241 $bg = weechat
::config_color
( $options{"color_current_bg"} );
1244 $color_bg = weechat
::color
(",".$bg) if ($bg ne "");
1246 # create channel number for output
1247 if ( weechat
::config_string
( $options{"show_prefix_bufname"} ) ne "" )
1250 weechat
::color
( weechat
::config_color
( $options{"color_prefix_bufname"} ) ).
1251 weechat
::config_string
( $options{"show_prefix_bufname"} ).
1252 weechat
::color
("default");
1255 if ( weechat
::config_boolean
( $options{"show_number"} ) eq 1 ) # on
1257 if (( weechat
::config_boolean
( $options{"indenting_number"} ) eq 1)
1258 && (($position eq "left") || ($position eq "right")))
1260 $str .= weechat
::color
("default").$color_bg
1261 .(" " x
($max_number_digits - length(int($buffer->{"number"}))));
1263 if ($old_number ne $buffer->{"number"})
1265 $str .= weechat
::color
( weechat
::config_color
( $options{"color_number"} ) )
1267 .$buffer->{"number"}
1268 .weechat
::color
("default")
1270 .weechat
::color
( weechat
::config_color
( $options{"color_number_char"} ) )
1271 .weechat
::config_string
( $options{"show_number_char"} )
1277 $indent = ((" " x
length($buffer->{"number"}))." ") if (($position eq "left") || ($position eq "right"));
1278 $str .= weechat
::color
("default")
1284 if (( weechat
::config_integer
( $options{"indenting"} ) ne 0 ) # indenting NOT off
1285 && (($position eq "left") || ($position eq "right")))
1287 my $type = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type");
1288 if (($type eq "channel") || ($type eq "private"))
1290 if ( weechat
::config_integer
( $options{"indenting"} ) eq 1 )
1294 elsif ( (weechat
::config_integer
($options{"indenting"}) eq 2) and (weechat
::config_integer
($options{"indenting_number"}) eq 0) ) #under_name
1296 if ( weechat
::config_boolean
( $options{"show_number"} ) eq 0 )
1301 $str .= ( (" " x
( $max_number_digits - length($buffer->{"number"}) ))." " );
1307 $str .= weechat
::config_string
( $options{"show_prefix_query"}) if (weechat
::config_string
( $options{"show_prefix_query"} ) ne "" and $buffer->{"type"} eq "private");
1309 if (weechat
::config_boolean
( $options{"show_prefix"} ) eq 1)
1311 my $nickname = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_nick");
1312 if ($nickname ne "")
1314 # with version >= 0.3.2, this infolist will return only nick
1315 # with older versions, whole nicklist is returned for buffer, and this can be very slow
1316 my $infolist_nick = weechat
::infolist_get
("nicklist", $buffer->{"pointer"}, "nick_".$nickname);
1317 if ($infolist_nick ne "")
1319 while (weechat
::infolist_next
($infolist_nick))
1321 if ((weechat
::infolist_string
($infolist_nick, "type") eq "nick")
1322 && (weechat
::infolist_string
($infolist_nick, "name") eq $nickname))
1324 my $prefix = weechat
::infolist_string
($infolist_nick, "prefix");
1325 if (($prefix ne " ") or (weechat
::config_boolean
( $options{"show_prefix_empty"} ) eq 1))
1327 # with version >= 0.3.5, it is now a color name (for older versions: option name with color)
1328 if (int($weechat_version) >= 0x00030500)
1330 $str .= weechat
::color
(weechat
::infolist_string
($infolist_nick, "prefix_color"));
1334 $str .= weechat
::color
(weechat
::config_color
(
1335 weechat
::config_get
(
1336 weechat
::infolist_string
($infolist_nick, "prefix_color"))));
1343 weechat
::infolist_free
($infolist_nick);
1347 if ($buffer->{"type"} eq "channel" and weechat
::config_boolean
( $options{"mark_inactive"} ) eq 1 and $buffer->{"nicks_count"} == 0)
1352 $str .= weechat
::color
($color) . weechat
::color
(",".$bg);
1354 if (weechat
::config_boolean
( $options{"short_names"} ) eq 1)
1356 if (weechat
::config_integer
($options{"name_size_max"}) >= 1) # check max_size of buffer name
1358 $str .= encode
("UTF-8", substr(decode
("UTF-8", $buffer->{"short_name"}), 0, weechat
::config_integer
($options{"name_size_max"})));
1359 $str .= weechat
::color
(weechat
::config_color
( $options{"color_number_char"})).weechat
::config_string
($options{"name_crop_suffix"}) if (length($buffer->{"short_name"}) > weechat
::config_integer
($options{"name_size_max"}));
1360 $str .= add_inactive_parentless
($buffer->{"type"}, $buffer->{"nicks_count"});
1361 $str .= add_hotlist_count
($buffer->{"pointer"}, %hotlist);
1365 $str .= $buffer->{"short_name"};
1366 $str .= add_inactive_parentless
($buffer->{"type"}, $buffer->{"nicks_count"});
1367 $str .= add_hotlist_count
($buffer->{"pointer"}, %hotlist);
1372 if (weechat
::config_integer
($options{"name_size_max"}) >= 1) # check max_size of buffer name
1374 $str .= encode
("UTF-8", substr(decode
("UTF-8", $buffer->{"name"},), 0, weechat
::config_integer
($options{"name_size_max"})));
1375 $str .= weechat
::color
(weechat
::config_color
( $options{"color_number_char"})).weechat
::config_string
($options{"name_crop_suffix"}) if (length($buffer->{"name"}) > weechat
::config_integer
($options{"name_size_max"}));
1376 $str .= add_inactive_parentless
($buffer->{"type"}, $buffer->{"nicks_count"});
1377 $str .= add_hotlist_count
($buffer->{"pointer"}, %hotlist);
1381 $str .= $buffer->{"name"};
1382 $str .= add_inactive_parentless
($buffer->{"type"}, $buffer->{"nicks_count"});
1383 $str .= add_hotlist_count
($buffer->{"pointer"}, %hotlist);
1386 if ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") eq "server" and weechat
::config_boolean
($options{"show_lag"}) eq 1)
1388 my $color_lag = weechat
::config_color
(weechat
::config_get
("irc.color.item_lag_finished"));
1389 my $min_lag = weechat
::config_integer
(weechat
::config_get
("irc.network.lag_min_show"));
1390 my $infolist_server = weechat
::infolist_get
("irc_server", "", $buffer->{"short_name"});
1391 weechat
::infolist_next
($infolist_server);
1392 my $lag = (weechat
::infolist_integer
($infolist_server, "lag"));
1393 weechat
::infolist_free
($infolist_server);
1394 if ( int($lag) > int($min_lag) )
1397 $str .= weechat
::color
("default") . " (" . weechat
::color
($color_lag) . $lag . weechat
::color
("default") . ")";
1400 if (weechat
::config_boolean
($options{"detach_displayed_buffers"}) eq 0
1401 and weechat
::config_boolean
($options{"detach_display_window_number"}) eq 1)
1403 if ($buffer->{"window"})
1405 $str .= weechat
::color
("default") . " (" . weechat
::color
(weechat
::config_color
( $options{"color_number"})) . $buffer->{"window"} . weechat
::color
("default") . ")";
1408 $str .= weechat
::color
("default");
1410 if ( weechat
::config_string
( $options{"show_suffix_bufname"} ) ne "" )
1412 $str .= weechat
::color
( weechat
::config_color
( $options{"color_suffix_bufname"} ) ).
1413 weechat
::config_string
( $options{"show_suffix_bufname"} ).
1414 weechat
::color
("default");
1418 $old_number = $buffer->{"number"};
1421 # remove spaces and/or linefeed at the end
1427 sub add_inactive_parentless
1429 my ($buf_type, $buf_nicks_count) = @_;
1431 if ($buf_type eq "channel" and weechat
::config_boolean
( $options{"mark_inactive"} ) eq 1 and $buf_nicks_count == 0)
1433 $str .= weechat
::color
(weechat
::config_color
( $options{"color_number_char"}));
1439 sub add_hotlist_count
1441 my ($bufpointer, %hotlist) = @_;
1443 return "" if ( weechat
::config_boolean
( $options{"hotlist_counter"} ) eq 0 or ($weechat_version < 0x00030500)); # off
1444 my $col_number_char = weechat
::color
(weechat
::config_color
( $options{"color_number_char"}) );
1445 my $str = " ".$col_number_char."(";
1448 if (defined $hotlist{$bufpointer."_count_00"})
1450 my $bg = weechat
::config_color
( $options{"color_hotlist_low_bg"} );
1451 my $color = weechat
::config_color
( $options{"color_hotlist_low_fg"} );
1452 $str .= weechat
::color
($bg).
1453 weechat
::color
($color).
1454 $hotlist{$bufpointer."_count_00"} if ($hotlist{$bufpointer."_count_00"} ne "0");
1458 if (defined $hotlist{$bufpointer."_count_01"})
1460 my $bg = weechat
::config_color
( $options{"color_hotlist_message_bg"} );
1461 my $color = weechat
::config_color
( $options{"color_hotlist_message_fg"} );
1462 if ($str =~ /[0-9]$/)
1465 weechat
::color
($bg).
1466 weechat
::color
($color).
1467 $hotlist{$bufpointer."_count_01"} if ($hotlist{$bufpointer."_count_01"} ne "0");
1470 $str .= weechat
::color
($bg).
1471 weechat
::color
($color).
1472 $hotlist{$bufpointer."_count_01"} if ($hotlist{$bufpointer."_count_01"} ne "0");
1476 if (defined $hotlist{$bufpointer."_count_02"})
1478 my $bg = weechat
::config_color
( $options{"color_hotlist_private_bg"} );
1479 my $color = weechat
::config_color
( $options{"color_hotlist_private_fg"} );
1480 if ($str =~ /[0-9]$/)
1483 weechat
::color
($bg).
1484 weechat
::color
($color).
1485 $hotlist{$bufpointer."_count_02"} if ($hotlist{$bufpointer."_count_02"} ne "0");
1488 $str .= weechat
::color
($bg).
1489 weechat
::color
($color).
1490 $hotlist{$bufpointer."_count_02"} if ($hotlist{$bufpointer."_count_02"} ne "0");
1494 if (defined $hotlist{$bufpointer."_count_03"})
1496 my $bg = weechat
::config_color
( $options{"color_hotlist_highlight_bg"} );
1497 my $color = weechat
::config_color
( $options{"color_hotlist_highlight_fg"} );
1498 if ($str =~ /[0-9]$/)
1501 weechat
::color
($bg).
1502 weechat
::color
($color).
1503 $hotlist{$bufpointer."_count_03"} if ($hotlist{$bufpointer."_count_03"} ne "0");
1506 $str .= weechat
::color
($bg).
1507 weechat
::color
($color).
1508 $hotlist{$bufpointer."_count_03"} if ($hotlist{$bufpointer."_count_03"} ne "0");
1511 $str .= $col_number_char. ")";
1513 $str = "" if (weechat
::string_remove_color
($str, "") eq " ()"); # remove color and check for buffer with no messages
1517 sub buffers_signal_buffer
1519 my ($data, $signal, $signal_data) = @_;
1521 # check for buffer_switch and set or remove detach time
1522 if ($weechat_version >= 0x00030800)
1524 if ($signal eq "buffer_switch")
1526 my $pointer = weechat
::hdata_get_list
(weechat
::hdata_get
("buffer"), "gui_buffer_last_displayed"); # get switched buffer
1527 my $current_time = time();
1528 if ( weechat
::buffer_get_string
($pointer, "localvar_type") eq "channel")
1530 $buffers_timer{$pointer} = $current_time;
1534 delete $buffers_timer{$pointer};
1537 if ($signal eq "buffer_opened")
1539 my $current_time = time();
1540 $buffers_timer{$signal_data} = $current_time;
1542 if ($signal eq "buffer_closing")
1544 delete $buffers_timer{$signal_data};
1547 weechat
::bar_item_update
($SCRIPT_NAME);
1548 return weechat
::WEECHAT_RC_OK
;
1551 sub buffers_signal_hotlist
1553 weechat
::bar_item_update
($SCRIPT_NAME);
1554 return weechat
::WEECHAT_RC_OK
;
1558 sub buffers_signal_config_whitelist
1560 @whitelist_buffers = ();
1561 @whitelist_buffers = split( /,/, weechat
::config_string
( $options{"look_whitelist_buffers"} ) );
1562 weechat
::bar_item_update
($SCRIPT_NAME);
1563 return weechat
::WEECHAT_RC_OK
;
1566 sub buffers_signal_config_immune_detach_buffers
1568 @immune_detach_buffers = ();
1569 @immune_detach_buffers = split( /,/, weechat
::config_string
( $options{"immune_detach_buffers"} ) );
1570 weechat
::bar_item_update
($SCRIPT_NAME);
1571 return weechat
::WEECHAT_RC_OK
;
1574 sub buffers_signal_config_detach_buffer_immediately
1576 @detach_buffer_immediately = ();
1577 @detach_buffer_immediately = split( /,/, weechat
::config_string
( $options{"detach_buffer_immediately"} ) );
1578 weechat
::bar_item_update
($SCRIPT_NAME);
1579 return weechat
::WEECHAT_RC_OK
;
1582 sub buffers_signal_config
1584 weechat
::bar_item_update
($SCRIPT_NAME);
1585 return weechat
::WEECHAT_RC_OK
;
1588 # called when mouse click occured in buffers item: this callback returns buffer
1589 # hash according to line of item where click occured
1590 sub buffers_focus_buffers
1592 my %info = %{$_[1]};
1593 my $item_line = int($info{"_bar_item_line"});
1595 if (($info{"_bar_item_name"} eq $SCRIPT_NAME) && ($item_line >= 0) && ($item_line <= $#buffers_focus))
1597 $hash = $buffers_focus[$item_line];
1602 my $hash_focus = $buffers_focus[0];
1603 foreach my $key (keys %$hash_focus)
1605 $hash->{$key} = "?";
1611 # called when a mouse action is done on buffers item, to execute action
1612 # possible actions: jump to a buffer or move buffer in list (drag & drop of buffer)
1613 sub buffers_hsignal_mouse
1615 my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
1616 my $current_buffer = weechat
::buffer_get_integer
(weechat
::current_buffer
(), "number"); # get current buffer number
1618 if ( $hash{"_key"} eq "button1" ) # left mouse button
1620 if ($hash{"number"} eq $hash{"number2"})
1622 if ( weechat
::config_integer
($options{"jump_prev_next_visited_buffer"}) eq 1 )
1624 if ( $current_buffer eq $hash{"number"} )
1626 weechat
::command
("", "/input jump_previously_visited_buffer");
1630 weechat
::command
("", "/buffer ".$hash{"full_name"});
1635 weechat
::command
("", "/buffer ".$hash{"full_name"});
1640 move_buffer
(%hash) if (weechat
::config_boolean
($options{"mouse_move_buffer"}));
1643 elsif ( ($hash{"_key"} eq "button2") && (weechat
::config_integer
($options{"jump_prev_next_visited_buffer"}) eq 1) )# right mouse button
1645 if ( $current_buffer eq $hash{"number2"} )
1647 weechat
::command
("", "/input jump_next_visited_buffer");
1652 my $infolist = weechat
::infolist_get
("hook", "", "command,menu");
1653 my $has_menu_command = weechat
::infolist_next
($infolist);
1654 weechat
::infolist_free
($infolist);
1656 if ( $has_menu_command && $hash{"_key"} =~ /button2/ )
1658 if ($hash{"number"} eq $hash{"number2"})
1660 weechat
::command
($hash{"pointer"}, "/menu buffer1 $hash{short_name} $hash{number}");
1664 weechat
::command
($hash{"pointer"}, "/menu buffer2 $hash{short_name}/$hash{short_name2} $hash{number} $hash{number2}")
1669 move_buffer
(%hash) if (weechat
::config_boolean
($options{"mouse_move_buffer"}));
1677 my $number2 = $hash{"number2"};
1678 if ($number2 eq "?")
1680 # if number 2 is not known (end of gesture outside buffers list), then set it
1681 # according to mouse gesture
1683 if (($hash{"_key"} =~ /gesture-right/) || ($hash{"_key"} =~ /gesture-down/))
1685 $number2 = "999999";
1686 if ($weechat_version >= 0x00030600)
1688 my $hdata_buffer = weechat
::hdata_get
("buffer");
1689 my $last_gui_buffer = weechat
::hdata_get_list
($hdata_buffer, "last_gui_buffer");
1690 if ($last_gui_buffer)
1692 $number2 = weechat
::hdata_integer
($hdata_buffer, $last_gui_buffer, "number") + 1;
1697 my $ptrbuf = weechat
::current_buffer
();
1698 weechat
::command
($hash{"pointer"}, "/buffer move ".$number2);
1701 sub check_immune_detached_buffers
1703 my ($buffername) = @_;
1704 foreach ( @immune_detach_buffers ){
1705 my $immune_buffer = weechat
::string_mask_to_regex
($_);
1706 if ($buffername =~ /^$immune_buffer$/i)
1714 sub check_detach_buffer_immediately
1716 my ($buffername) = @_;
1717 foreach ( @detach_buffer_immediately ){
1718 my $detach_buffer = weechat
::string_mask_to_regex
($_);
1719 if ($buffername =~ /^$detach_buffer$/i)
1729 weechat
::command
("", "/bar hide " . $SCRIPT_NAME) if ( weechat
::config_boolean
($options{"toggle_bar"}) eq 1 );
1730 return weechat
::WEECHAT_RC_OK
1736 my $infolist = weechat
::infolist_get
("bar", "", "");
1737 while (weechat
::infolist_next
($infolist))
1739 my $bar_items = weechat
::infolist_string
($infolist, "items");
1740 if (index($bar_items, $SCRIPT_NAME) != -1)
1742 my $name = weechat
::infolist_string
($infolist, "name");
1743 if ($name ne $SCRIPT_NAME)
1750 weechat
::infolist_free
($infolist);