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.
24 # v5.0: fix cropping non-latin buffer names
25 # 2014-08-29, Patrick Steinhardt <ps@pks.im>:
26 # v4.9: add support for specifying custom buffer names
27 # 2014-07-19, Sebastien Helleu <flashcode@flashtux.org>:
28 # v4.8: add support of ctrl + mouse wheel to jump to previous/next buffer,
29 # new option "mouse_wheel"
30 # 2014-06-22, Sebastien Helleu <flashcode@flashtux.org>:
31 # v4.7: fix typos in options
32 # 2014-04-05, Sebastien Helleu <flashcode@flashtux.org>:
33 # v4.6: add support of hidden buffers (WeeChat >= 0.4.4)
34 # 2014-01-01, Sebastien Helleu <flashcode@flashtux.org>:
35 # v4.5: add option "mouse_move_buffer"
36 # 2013-12-11, Sebastien Helleu <flashcode@flashtux.org>:
37 # v4.4: fix buffer number on drag to the end of list when option
38 # weechat.look.buffer_auto_renumber is off
39 # 2013-12-10, nils_2@freenode.#weechat:
40 # v4.3: add options "prefix_bufname" and "suffix_bufname (idea by silverd)
41 # : fix hook_timer() for show_lag wasn't disabled
42 # : improved signal handling (less updating of buffers list)
43 # 2013-11-07, Sebastien Helleu <flashcode@flashtux.org>:
44 # v4.2: use default filling "columns_vertical" when bar position is top/bottom
45 # 2013-10-31, nils_2@freenode.#weechat:
46 # v4.1: add option "detach_buffer_immediately" (idea by farn)
47 # 2013-10-20, nils_2@freenode.#weechat:
48 # v4.0: add options "detach_displayed_buffers", "detach_display_window_number"
49 # 2013-09-27, nils_2@freenode.#weechat:
50 # v3.9: add option "toggle_bar" and option "show_prefix_query" (idea by IvarB)
51 # : fix problem with linefeed at end of list of buffers (reported by grawity)
52 # 2012-10-18, nils_2@freenode.#weechat:
53 # v3.8: add option "mark_inactive", to mark buffers you are not in (idea by xrdodrx)
54 # : add wildcard "*" for immune_detach_buffers (idea by StarWeaver)
55 # : add new options "detach_query" and "detach_free_content" (idea by StarWeaver)
56 # 2012-10-06, Nei <anti.teamidiot.de>:
57 # v3.7: call menu on right mouse if menu script is loaded.
58 # 2012-10-06, nils_2 <weechatter@arcor.de>:
59 # v3.6: add new option "hotlist_counter" (idea by torque).
60 # 2012-06-02, nils_2 <weechatter@arcor.de>:
61 # v3.5: add values "server|channel|private|all|keepserver|none" to option "hide_merged_buffers" (suggested by dominikh).
62 # 2012-05-25, nils_2 <weechatter@arcor.de>:
63 # v3.4: add new option "show_lag".
64 # 2012-04-07, Sebastien Helleu <flashcode@flashtux.org>:
65 # v3.3: fix truncation of wide chars in buffer name (option name_size_max) (bug #36034)
66 # 2012-03-15, nils_2 <weechatter@arcor.de>:
67 # v3.2: add new option "detach"(weechat >= 0.3.8)
68 # add new option "immune_detach_buffers" (requested by Mkaysi)
69 # add new function buffers_whitelist add|del|reset (suggested by FiXato)
70 # add new function buffers_detach add|del|reset
71 # 2012-03-09, Sebastien Helleu <flashcode@flashtux.org>:
72 # v3.1: fix reload of config file
73 # 2012-01-29, nils_2 <weechatter@arcor.de>:
74 # v3.0: fix: buffers did not update directly during window_switch (reported by FiXato)
75 # 2012-01-29, nils_2 <weechatter@arcor.de>:
76 # v2.9: add options "name_size_max" and "name_crop_suffix"
77 # 2012-01-08, nils_2 <weechatter@arcor.de>:
78 # v2.8: fix indenting for option "show_number off"
79 # fix unset of buffer activity in hotlist when buffer was moved with mouse
80 # add buffer with free content and core buffer sorted first (suggested by nyuszika7h)
81 # add options queries_default_fg/bg and queries_message_fg/bg (suggested by FiXato)
82 # add clicking with left button on current buffer will do a jump_previously_visited_buffer (suggested by FiXato)
83 # add clicking with right button on current buffer will do a jump_next_visited_buffer
84 # add additional informations in help texts
85 # add default_fg and default_bg for whitelist channels
86 # internal changes (script is now 3Kb smaller)
87 # 2012-01-04, Sebastien Helleu <flashcode@flashtux.org>:
88 # v2.7: fix regex lookup in whitelist buffers list
89 # 2011-12-04, nils_2 <weechatter@arcor.de>:
90 # v2.6: add own config file (buffers.conf)
91 # add new behavior for indenting (under_name)
92 # add new option to set different color for server buffers and buffers with free content
93 # 2011-10-30, nils_2 <weechatter@arcor.de>:
94 # v2.5: add new options "show_number_char" and "color_number_char",
95 # add help-description for options
96 # 2011-08-24, Sebastien Helleu <flashcode@flashtux.org>:
97 # v2.4: add mouse support
98 # 2011-06-06, nils_2 <weechatter@arcor.de>:
99 # v2.3: added: missed option "color_whitelist_default"
100 # 2011-03-23, Sebastien Helleu <flashcode@flashtux.org>:
101 # v2.2: fix color of nick prefix with WeeChat >= 0.3.5
102 # 2011-02-13, nils_2 <weechatter@arcor.de>:
103 # v2.1: add options "color_whitelist_*"
104 # 2010-10-05, Sebastien Helleu <flashcode@flashtux.org>:
105 # v2.0: add options "sort" and "show_number"
106 # 2010-04-12, Sebastien Helleu <flashcode@flashtux.org>:
107 # v1.9: replace call to log() by length() to align buffer numbers
108 # 2010-04-02, Sebastien Helleu <flashcode@flashtux.org>:
109 # v1.8: fix bug with background color and option indenting_number
110 # 2010-04-02, Helios <helios@efemes.de>:
111 # v1.7: add indenting_number option
112 # 2010-02-25, m4v <lambdae2@gmail.com>:
113 # v1.6: add option to hide empty prefixes
114 # 2010-02-12, Sebastien Helleu <flashcode@flashtux.org>:
115 # v1.5: add optional nick prefix for buffers like IRC channels
116 # 2009-09-30, Sebastien Helleu <flashcode@flashtux.org>:
117 # v1.4: remove spaces for indenting when bar position is top/bottom
118 # 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
119 # v1.3: add option "hide_merged_buffers"
120 # 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
121 # v1.2: improve display with merged buffers
122 # 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
123 # v1.1: sync with last API changes
124 # 2009-02-21, Sebastien Helleu <flashcode@flashtux.org>:
125 # v1.0: remove timer used to update bar item first time (not needed any more)
126 # 2009-02-17, Sebastien Helleu <flashcode@flashtux.org>:
127 # v0.9: fix bug with indenting of private buffers
128 # 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
129 # v0.8: update syntax for command /set (comments)
130 # 2008-10-20, Jiri Golembiovsky <golemj@gmail.com>:
131 # v0.7: add indenting option
132 # 2008-10-01, Sebastien Helleu <flashcode@flashtux.org>:
133 # v0.6: add default color for buffers, and color for current active buffer
134 # 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
135 # v0.5: fix color for "low" level entry in hotlist
136 # 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
137 # v0.4: rename option "show_category" to "short_names",
138 # remove option "color_slash"
139 # 2008-09-15, Sebastien Helleu <flashcode@flashtux.org>:
140 # v0.3: fix bug with priority in hotlist (var not defined)
141 # 2008-09-02, Sebastien Helleu <flashcode@flashtux.org>:
142 # v0.2: add color for buffers with activity and config options for
143 # colors, add config option to display/hide categories
144 # 2008-03-15, Sebastien Helleu <flashcode@flashtux.org>:
145 # v0.1: script creation
147 # Help about settings:
148 # display all settings for script (or use iset.pl script to change settings):
150 # show help text for option buffers.look.whitelist_buffers:
151 # /help buffers.look.whitelist_buffers
153 # Mouse-support (standard key bindings):
155 # - click on a buffer to switch to selected buffer
156 # - click on current buffer will do action jump_previously_visited_buffer
157 # - drag a buffer and drop it on another position will move the buffer to position
158 # right mouse-button:
159 # - click on current buffer will do action jump_next_visited_buffer
160 # - moving buffer to the left/right will close buffer.
164 use Encode
qw( decode encode );
165 # -----------------------------[ internal ]-------------------------------------
166 my $SCRIPT_NAME = "buffers";
167 my $SCRIPT_VERSION = "5.0";
169 my $BUFFERS_CONFIG_FILE_NAME = "buffers";
170 my $buffers_config_file;
171 my $cmd_buffers_whitelist= "buffers_whitelist";
172 my $cmd_buffers_detach = "buffers_detach";
174 my %mouse_keys = ("\@item(buffers):button1*" => "hsignal:buffers_mouse",
175 "\@item(buffers):button2*" => "hsignal:buffers_mouse",
176 "\@bar(buffers):ctrl-wheelup" => "hsignal:buffers_mouse",
177 "\@bar(buffers):ctrl-wheeldown" => "hsignal:buffers_mouse");
179 my %hotlist_level = (0 => "low", 1 => "message", 2 => "private", 3 => "highlight");
180 my @whitelist_buffers = ();
181 my @immune_detach_buffers= ();
182 my @detach_buffer_immediately= ();
183 my @buffers_focus = ();
184 my %buffers_timer = ();
187 # --------------------------------[ init ]--------------------------------------
188 weechat
::register
($SCRIPT_NAME, "Sebastien Helleu <flashcode\@flashtux.org>",
189 $SCRIPT_VERSION, "GPL3",
190 "Sidebar with list of buffers", "shutdown_cb", "");
191 my $weechat_version = weechat
::info_get
("version_number", "") || 0;
193 buffers_config_init
();
194 buffers_config_read
();
196 weechat
::bar_item_new
($SCRIPT_NAME, "build_buffers", "");
197 weechat
::bar_new
($SCRIPT_NAME, "0", "0", "root", "", "left", "columns_vertical",
198 "vertical", "0", "0", "default", "default", "default", "1",
201 if ( check_bar_item
() == 0 )
203 weechat
::command
("", "/bar show " . $SCRIPT_NAME) if ( weechat
::config_boolean
($options{"toggle_bar"}) eq 1 );
206 weechat
::hook_signal
("buffer_opened", "buffers_signal_buffer", "");
207 weechat
::hook_signal
("buffer_closed", "buffers_signal_buffer", "");
208 weechat
::hook_signal
("buffer_merged", "buffers_signal_buffer", "");
209 weechat
::hook_signal
("buffer_unmerged", "buffers_signal_buffer", "");
210 weechat
::hook_signal
("buffer_moved", "buffers_signal_buffer", "");
211 weechat
::hook_signal
("buffer_renamed", "buffers_signal_buffer", "");
212 weechat
::hook_signal
("buffer_switch", "buffers_signal_buffer", "");
213 weechat
::hook_signal
("buffer_hidden", "buffers_signal_buffer", ""); # WeeChat >= 0.4.4
214 weechat
::hook_signal
("buffer_unhidden", "buffers_signal_buffer", ""); # WeeChat >= 0.4.4
215 weechat
::hook_signal
("buffer_localvar_added", "buffers_signal_buffer", "");
216 weechat
::hook_signal
("buffer_localvar_changed", "buffers_signal_buffer", "");
218 weechat
::hook_signal
("window_switch", "buffers_signal_buffer", "");
219 weechat
::hook_signal
("hotlist_changed", "buffers_signal_hotlist", "");
220 #weechat::hook_command_run("/input switch_active_*", "buffers_signal_buffer", "");
221 weechat
::bar_item_update
($SCRIPT_NAME);
224 if ($weechat_version >= 0x00030600)
226 weechat
::hook_focus
($SCRIPT_NAME, "buffers_focus_buffers", "");
227 weechat
::hook_hsignal
("buffers_mouse", "buffers_hsignal_mouse", "");
228 weechat
::key_bind
("mouse", \
%mouse_keys);
231 weechat
::hook_command
($cmd_buffers_whitelist,
232 "add/del current buffer to/from buffers whitelist",
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_whitelist add\n",
243 "buffers_cmd_whitelist", "");
244 weechat
::hook_command
($cmd_buffers_detach,
245 "add/del current buffer to/from buffers detach",
246 "[add] || [del] || [reset]",
247 " add: add current buffer in configuration file\n".
248 " del: delete current buffer from configuration file\n".
249 "reset: reset all buffers from configuration file ".
250 "(no confirmation!)\n\n".
252 "/$cmd_buffers_detach add\n",
256 "buffers_cmd_detach", "");
258 if ($weechat_version >= 0x00030800)
260 weechat
::hook_config
("buffers.look.detach", "hook_timer_detach", "");
261 if (weechat
::config_integer
($options{"detach"}) > 0)
263 $Hooks{timer_detach
} = weechat
::hook_timer
(weechat
::config_integer
($options{"detach"}) * 1000,
264 60, 0, "buffers_signal_hotlist", "");
268 weechat
::hook_config
("buffers.look.show_lag", "hook_timer_lag", "");
270 if (weechat
::config_boolean
($options{"show_lag"}))
272 $Hooks{timer_lag
} = weechat
::hook_timer
(
273 weechat
::config_integer
(weechat
::config_get
("irc.network.lag_refresh_interval")) * 1000,
274 0, 0, "buffers_signal_hotlist", "");
277 # -------------------------------- [ command ] --------------------------------
278 sub buffers_cmd_whitelist
280 my ( $data, $buffer, $args ) = @_;
282 my $buffers_whitelist = weechat
::config_string
( weechat
::config_get
("buffers.look.whitelist_buffers") );
283 return weechat
::WEECHAT_RC_OK
if ( $buffers_whitelist eq "" and $args eq "del" or $buffers_whitelist eq "" and $args eq "reset" );
284 my @buffers_list = split( /,/, $buffers_whitelist );
286 my $infolist = weechat
::infolist_get
("buffer", weechat
::current_buffer
(), "");
287 weechat
::infolist_next
($infolist);
288 my $buffers_name = weechat
::infolist_string
($infolist, "name");
289 weechat
::infolist_free
($infolist);
290 return weechat
::WEECHAT_RC_OK
if ( $buffers_name eq "" ); # should never happen
292 if ( $args eq "add" )
294 return weechat
::WEECHAT_RC_OK
if ( grep /^$buffers_name$/, @buffers_list ); # check if buffer already in list
295 push @buffers_list, ( $buffers_name );
296 my $buffers_list = &create_whitelist
(\
@buffers_list);
297 weechat
::config_option_set
( weechat
::config_get
("buffers.look.whitelist_buffers"), $buffers_list, 1);
298 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" added to buffers whitelist");
300 elsif ( $args eq "del" )
302 return weechat
::WEECHAT_RC_OK
unless ( grep /^$buffers_name$/, @buffers_list ); # check if buffer is in list
303 @buffers_list = grep {$_ ne $buffers_name} @buffers_list; # delete entry
304 my $buffers_list = &create_whitelist
(\
@buffers_list);
305 weechat
::config_option_set
( weechat
::config_get
("buffers.look.whitelist_buffers"), $buffers_list, 1);
306 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" deleted from buffers whitelist");
308 elsif ( $args eq "reset" )
310 return weechat
::WEECHAT_RC_OK
if ( $buffers_whitelist eq "" );
311 weechat
::config_option_set
( weechat
::config_get
("buffers.look.whitelist_buffers"), "", 1);
312 weechat
::print(weechat
::current_buffer
(), "buffers whitelist is empty, now...");
314 return weechat
::WEECHAT_RC_OK
;
316 sub buffers_cmd_detach
318 my ( $data, $buffer, $args ) = @_;
320 my $immune_detach_buffers = weechat
::config_string
( weechat
::config_get
("buffers.look.immune_detach_buffers") );
321 return weechat
::WEECHAT_RC_OK
if ( $immune_detach_buffers eq "" and $args eq "del" or $immune_detach_buffers eq "" and $args eq "reset" );
323 my @buffers_list = split( /,/, $immune_detach_buffers );
325 my $infolist = weechat
::infolist_get
("buffer", weechat
::current_buffer
(), "");
326 weechat
::infolist_next
($infolist);
327 my $buffers_name = weechat
::infolist_string
($infolist, "name");
328 weechat
::infolist_free
($infolist);
329 return weechat
::WEECHAT_RC_OK
if ( $buffers_name eq "" ); # should never happen
331 if ( $args eq "add" )
333 return weechat
::WEECHAT_RC_OK
if ( grep /^$buffers_name$/, @buffers_list ); # check if buffer already in list
334 push @buffers_list, ( $buffers_name );
335 my $buffers_list = &create_whitelist
(\
@buffers_list);
336 weechat
::config_option_set
( weechat
::config_get
("buffers.look.immune_detach_buffers"), $buffers_list, 1);
337 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" added to immune detach buffers");
339 elsif ( $args eq "del" )
341 return weechat
::WEECHAT_RC_OK
unless ( grep /^$buffers_name$/, @buffers_list ); # check if buffer is in list
342 @buffers_list = grep {$_ ne $buffers_name} @buffers_list; # delete entry
343 my $buffers_list = &create_whitelist
(\
@buffers_list);
344 weechat
::config_option_set
( weechat
::config_get
("buffers.look.immune_detach_buffers"), $buffers_list, 1);
345 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" deleted from immune detach buffers");
347 elsif ( $args eq "reset" )
349 return weechat
::WEECHAT_RC_OK
if ( $immune_detach_buffers eq "" );
350 weechat
::config_option_set
( weechat
::config_get
("buffers.look.immune_detach_buffers"), "", 1);
351 weechat
::print(weechat
::current_buffer
(), "immune detach buffers is empty, now...");
353 return weechat
::WEECHAT_RC_OK
;
358 my @buffers_list = @{$_[0]};
359 my $buffers_list = "";
360 foreach (@buffers_list)
362 $buffers_list .= $_ .",";
366 return $buffers_list;
369 # -------------------------------- [ config ] --------------------------------
370 sub hook_timer_detach
375 weechat
::unhook
($Hooks{timer_detach
}) if $Hooks{timer_detach
};
376 $Hooks{timer_detach
} = "";
380 weechat
::unhook
($Hooks{timer_detach
}) if $Hooks{timer_detach
};
381 $Hooks{timer_detach
} = weechat
::hook_timer
( weechat
::config_integer
( $options{"detach"}) * 1000, 60, 0, "buffers_signal_hotlist", "");
383 weechat
::bar_item_update
($SCRIPT_NAME);
384 return weechat
::WEECHAT_RC_OK
;
392 weechat
::unhook
($Hooks{timer_lag
}) if $Hooks{timer_lag
};
393 $Hooks{timer_lag
} = "";
397 weechat
::unhook
($Hooks{timer_lag
}) if $Hooks{timer_lag
};
398 $Hooks{timer_lag
} = weechat
::hook_timer
( weechat
::config_integer
(weechat
::config_get
("irc.network.lag_refresh_interval")) * 1000, 0, 0, "buffers_signal_hotlist", "");
400 weechat
::bar_item_update
($SCRIPT_NAME);
401 return weechat
::WEECHAT_RC_OK
;
404 sub buffers_config_read
406 return weechat
::config_read
($buffers_config_file) if ($buffers_config_file ne "");
408 sub buffers_config_write
410 return weechat
::config_write
($buffers_config_file) if ($buffers_config_file ne "");
412 sub buffers_config_reload_cb
414 my ($data, $config_file) = ($_[0], $_[1]);
415 return weechat
::config_reload
($config_file)
417 sub buffers_config_init
419 $buffers_config_file = weechat
::config_new
($BUFFERS_CONFIG_FILE_NAME,
420 "buffers_config_reload_cb", "");
421 return if ($buffers_config_file eq "");
423 my %default_options_color =
424 ("color_current_fg" => [
425 "current_fg", "color",
426 "foreground color for current buffer",
427 "", 0, 0, "lightcyan", "lightcyan", 0,
428 "", "", "buffers_signal_config", "", "", ""
430 "color_current_bg" => [
431 "current_bg", "color",
432 "background color for current buffer",
433 "", 0, 0, "red", "red", 0,
434 "", "", "buffers_signal_config", "", "", ""
436 "color_default_fg" => [
437 "default_fg", "color",
438 "default foreground color for buffer name",
439 "", 0, 0, "default", "default", 0,
440 "", "", "buffers_signal_config", "", "", ""
442 "color_default_bg" => [
443 "default_bg", "color",
444 "default background color for buffer name",
445 "", 0, 0, "default", "default", 0,
446 "", "", "buffers_signal_config", "", "", ""
448 "color_hotlist_highlight_fg" => [
449 "hotlist_highlight_fg", "color",
450 "change foreground color of buffer name if a highlight messaged received",
451 "", 0, 0, "magenta", "magenta", 0,
452 "", "", "buffers_signal_config", "", "", ""
454 "color_hotlist_highlight_bg" => [
455 "hotlist_highlight_bg", "color",
456 "change background color of buffer name if a highlight messaged received",
457 "", 0, 0, "default", "default", 0,
458 "", "", "buffers_signal_config", "", "", ""
460 "color_hotlist_low_fg" => [
461 "hotlist_low_fg", "color",
462 "change foreground color of buffer name if a low message received",
463 "", 0, 0, "white", "white", 0,
464 "", "", "buffers_signal_config", "", "", ""
466 "color_hotlist_low_bg" => [
467 "hotlist_low_bg", "color",
468 "change background color of buffer name if a low message received",
469 "", 0, 0, "default", "default", 0,
470 "", "", "buffers_signal_config", "", "", ""
472 "color_hotlist_message_fg" => [
473 "hotlist_message_fg", "color",
474 "change foreground color of buffer name if a normal message received",
475 "", 0, 0, "yellow", "yellow", 0,
476 "", "", "buffers_signal_config", "", "", ""
478 "color_hotlist_message_bg" => [
479 "hotlist_message_bg", "color",
480 "change background color of buffer name if a normal message received",
481 "", 0, 0, "default", "default", 0,
482 "", "", "buffers_signal_config", "", "", ""
484 "color_hotlist_private_fg" => [
485 "hotlist_private_fg", "color",
486 "change foreground color of buffer name if a private message received",
487 "", 0, 0, "lightgreen", "lightgreen", 0,
488 "", "", "buffers_signal_config", "", "", ""
490 "color_hotlist_private_bg" => [
491 "hotlist_private_bg", "color",
492 "change background color of buffer name if a private message received",
493 "", 0, 0, "default", "default", 0,
494 "", "", "buffers_signal_config", "", "", ""
498 "color for buffer number",
499 "", 0, 0, "lightgreen", "lightgreen", 0,
500 "", "", "buffers_signal_config", "", "", ""
502 "color_number_char" => [
503 "number_char", "color",
504 "color for buffer number char",
505 "", 0, 0, "lightgreen", "lightgreen", 0,
506 "", "", "buffers_signal_config", "", "", ""
508 "color_whitelist_default_fg" => [
509 "whitelist_default_fg", "color",
510 "default foreground color for whitelist buffer name",
512 "", "", "buffers_signal_config", "", "", ""
514 "color_whitelist_default_bg" => [
515 "whitelist_default_bg", "color",
516 "default background color for whitelist buffer name",
518 "", "", "buffers_signal_config", "", "", ""
520 "color_whitelist_low_fg" => [
521 "whitelist_low_fg", "color",
522 "low color of whitelist buffer name",
524 "", "", "buffers_signal_config", "", "", ""
526 "color_whitelist_low_bg" => [
527 "whitelist_low_bg", "color",
528 "low color of whitelist buffer name",
530 "", "", "buffers_signal_config", "", "", ""
532 "color_whitelist_message_fg" => [
533 "whitelist_message_fg", "color",
534 "message color of whitelist buffer name",
536 "", "", "buffers_signal_config", "", "", ""
538 "color_whitelist_message_bg" => [
539 "whitelist_message_bg", "color",
540 "message color of whitelist buffer name",
542 "", "", "buffers_signal_config", "", "", ""
544 "color_whitelist_private_fg" => [
545 "whitelist_private_fg", "color",
546 "private color of whitelist buffer name",
548 "", "", "buffers_signal_config", "", "", ""
550 "color_whitelist_private_bg" => [
551 "whitelist_private_bg", "color",
552 "private color of whitelist buffer name",
554 "", "", "buffers_signal_config", "", "", ""
556 "color_whitelist_highlight_fg" => [
557 "whitelist_highlight_fg", "color",
558 "highlight color of whitelist buffer name",
560 "", "", "buffers_signal_config", "", "", ""
562 "color_whitelist_highlight_bg" => [
563 "whitelist_highlight_bg", "color",
564 "highlight color of whitelist buffer name",
566 "", "", "buffers_signal_config", "", "", ""
568 "color_none_channel_fg" => [
569 "none_channel_fg", "color",
570 "foreground color for none channel buffer (e.g.: core/server/plugin ".
572 "", 0, 0, "default", "default", 0,
573 "", "", "buffers_signal_config", "", "", ""
575 "color_none_channel_bg" => [
576 "none_channel_bg", "color",
577 "background color for none channel buffer (e.g.: core/server/plugin ".
579 "", 0, 0, "default", "default", 0,
580 "", "", "buffers_signal_config", "", "", ""
582 "queries_default_fg" => [
583 "queries_default_fg", "color",
584 "foreground color for query buffer without message",
585 "", 0, 0, "default", "default", 0,
586 "", "", "buffers_signal_config", "", "", ""
588 "queries_default_bg" => [
589 "queries_default_bg", "color",
590 "background color for query buffer without message",
591 "", 0, 0, "default", "default", 0,
592 "", "", "buffers_signal_config", "", "", ""
594 "queries_message_fg" => [
595 "queries_message_fg", "color",
596 "foreground color for query buffer with unread message",
597 "", 0, 0, "default", "default", 0,
598 "", "", "buffers_signal_config", "", "", ""
600 "queries_message_bg" => [
601 "queries_message_bg", "color",
602 "background color for query buffer with unread message",
603 "", 0, 0, "default", "default", 0,
604 "", "", "buffers_signal_config", "", "", ""
606 "queries_highlight_fg" => [
607 "queries_highlight_fg", "color",
608 "foreground color for query buffer with unread highlight",
609 "", 0, 0, "default", "default", 0,
610 "", "", "buffers_signal_config", "", "", ""
612 "queries_highlight_bg" => [
613 "queries_highlight_bg", "color",
614 "background color for query buffer with unread highlight",
615 "", 0, 0, "default", "default", 0,
616 "", "", "buffers_signal_config", "", "", ""
618 "color_prefix_bufname" => [
619 "prefix_bufname", "color",
620 "color for prefix of buffer name",
621 "", 0, 0, "default", "default", 0,
622 "", "", "buffers_signal_config", "", "", ""
624 "color_suffix_bufname" => [
625 "suffix_bufname", "color",
626 "color for suffix of buffer name",
627 "", 0, 0, "default", "default", 0,
628 "", "", "buffers_signal_config", "", "", ""
632 my %default_options_look =
634 "hotlist_counter" => [
635 "hotlist_counter", "boolean",
636 "show number of message for the buffer (this option needs WeeChat >= ".
637 "0.3.5). The relevant option for notification is \"weechat.look.".
638 "buffer_notify_default\"",
639 "", 0, 0, "off", "off", 0,
640 "", "", "buffers_signal_config", "", "", ""
643 "show_lag", "boolean",
644 "show lag behind server name. This option is using \"irc.color.".
645 "item_lag_finished\", ".
646 "\"irc.network.lag_min_show\" and \"irc.network.lag_refresh_interval\"",
647 "", 0, 0, "off", "off", 0,
648 "", "", "buffers_signal_config", "", "", ""
650 "look_whitelist_buffers" => [
651 "whitelist_buffers", "string",
652 "comma separated list of buffers for using a different color scheme ".
653 "(for example: freenode.#weechat,freenode.#weechat-fr)",
655 "", "", "buffers_signal_config_whitelist", "", "", ""
657 "hide_merged_buffers" => [
658 "hide_merged_buffers", "integer",
659 "hide merged buffers. The value determines which merged buffers should ".
660 "be hidden, keepserver meaning 'all except server buffers'. Other values ".
661 "correspondent to the buffer type.",
662 "server|channel|private|keepserver|all|none", 0, 0, "none", "none", 0,
663 "", "", "buffers_signal_config", "", "", ""
666 "indenting", "integer", "use indenting for channel and query buffers. ".
667 "This option only takes effect if bar is left/right positioned",
668 "off|on|under_name", 0, 0, "off", "off", 0,
669 "", "", "buffers_signal_config", "", "", ""
671 "indenting_number" => [
672 "indenting_number", "boolean",
673 "use indenting for numbers. This option only takes effect if bar is ".
674 "left/right positioned",
675 "", 0, 0, "on", "on", 0,
676 "", "", "buffers_signal_config", "", "", ""
679 "short_names", "boolean",
680 "display short names (remove text before first \".\" in buffer name)",
681 "", 0, 0, "on", "on", 0,
682 "", "", "buffers_signal_config", "", "", ""
685 "show_number", "boolean",
686 "display buffer number in front of buffer name",
687 "", 0, 0, "on", "on", 0,
688 "", "", "buffers_signal_config", "", "", ""
690 "show_number_char" => [
691 "number_char", "string",
692 "display a char behind buffer number",
693 "", 0, 0, ".", ".", 0,
694 "", "", "buffers_signal_config", "", "", ""
696 "show_prefix_bufname" => [
697 "prefix_bufname", "string",
698 "prefix displayed in front of buffer name",
700 "", "", "buffers_signal_config", "", "", ""
702 "show_suffix_bufname" => [
703 "suffix_bufname", "string",
704 "suffix displayed at end of buffer name",
706 "", "", "buffers_signal_config", "", "", ""
710 "displays your prefix for channel in front of buffer name",
711 "", 0, 0, "off", "off", 0,
712 "", "", "buffers_signal_config", "", "", ""
714 "show_prefix_empty" => [
715 "prefix_empty", "boolean",
716 "use a placeholder for channels without prefix",
717 "", 0, 0, "on", "on", 0,
718 "", "", "buffers_signal_config", "", "", ""
720 "show_prefix_query" => [
721 "prefix_for_query", "string",
722 "prefix displayed in front of query buffer",
724 "", "", "buffers_signal_config", "", "", ""
728 "sort buffer-list by \"number\" or \"name\"",
729 "number|name", 0, 0, "number", "number", 0,
730 "", "", "buffers_signal_config", "", "", ""
733 "core_to_front", "boolean",
734 "core buffer and buffers with free content will be listed first. ".
735 "Take only effect if buffer sort is by name",
736 "", 0, 0, "off", "off", 0,
737 "", "", "buffers_signal_config", "", "", ""
739 "jump_prev_next_visited_buffer" => [
740 "jump_prev_next_visited_buffer", "boolean",
741 "jump to previously or next visited buffer if you click with ".
742 "left/right mouse button on currently visiting buffer",
743 "", 0, 0, "off", "off", 0,
744 "", "", "buffers_signal_config", "", "", ""
747 "name_size_max", "integer",
748 "maximum size of buffer name. 0 means no limitation",
750 "", "", "buffers_signal_config", "", "", ""
752 "name_crop_suffix" => [
753 "name_crop_suffix", "string",
754 "contains an optional char(s) that is appended when buffer name is ".
756 "", 0, 0, "+", "+", 0,
757 "", "", "buffers_signal_config", "", "", ""
761 "detach buffer from buffers list after a specific period of time ".
762 "(in seconds) without action (weechat ≥ 0.3.8 required) (0 means \"off\")",
763 "", 0, 31536000, 0, "number", 0,
764 "", "", "buffers_signal_config", "", "", ""
766 "immune_detach_buffers" => [
767 "immune_detach_buffers", "string",
768 "comma separated list of buffers to NOT automatically detach. ".
769 "Allows \"*\" wildcard. Ex: \"BitlBee,freenode.*\"",
771 "", "", "buffers_signal_config_immune_detach_buffers", "", "", ""
774 "detach_query", "boolean",
775 "query buffer will be detached",
776 "", 0, 0, "off", "off", 0,
777 "", "", "buffers_signal_config", "", "", ""
779 "detach_buffer_immediately" => [
780 "detach_buffer_immediately", "string",
781 "comma separated list of buffers to detach immediately. A query and ".
782 "highlight message will attach buffer again. Allows \"*\" wildcard. ".
783 "Ex: \"BitlBee,freenode.*\"",
785 "", "", "buffers_signal_config_detach_buffer_immediately", "", "", ""
787 "detach_free_content" => [
788 "detach_free_content", "boolean",
789 "buffers with free content will be detached (Ex: iset, chanmon)",
790 "", 0, 0, "off", "off", 0,
791 "", "", "buffers_signal_config", "", "", ""
793 "detach_displayed_buffers" => [
794 "detach_displayed_buffers", "boolean",
795 "buffers displayed in a (split) window will be detached",
796 "", 0, 0, "on", "on", 0,
797 "", "", "buffers_signal_config", "", "", ""
799 "detach_display_window_number" => [
800 "detach_display_window_number", "boolean",
801 "window number will be add, behind buffer name (this option takes only ".
802 "effect with \"detach_displayed_buffers\" option)",
803 "", 0, 0, "off", "off", 0,
804 "", "", "buffers_signal_config", "", "", ""
807 "mark_inactive", "boolean",
808 "if option is \"on\", inactive buffers (those you are not in) will have ".
809 "parentheses around them. An inactive buffer will not be detached.",
810 "", 0, 0, "off", "off", 0,
811 "", "", "buffers_signal_config", "", "", ""
814 "toggle_bar", "boolean",
815 "if option is \"on\", buffers bar will hide/show when script is ".
817 "", 0, 0, "on", "on", 0,
818 "", "", "buffers_signal_config", "", "", ""
820 "mouse_move_buffer" => [
821 "mouse_move_buffer", "boolean",
822 "if option is \"on\", mouse gestures (drag & drop) can move buffers in list.",
823 "", 0, 0, "on", "on", 0,
824 "", "", "buffers_signal_config", "", "", ""
827 "mouse_wheel", "boolean",
828 "if option is \"on\", mouse wheel jumps to previous/next buffer in list.",
829 "", 0, 0, "on", "on", 0,
830 "", "", "buffers_signal_config", "", "", ""
834 my $section_color = weechat
::config_new_section
(
835 $buffers_config_file,
836 "color", 0, 0, "", "", "", "", "", "", "", "", "", "");
837 if ($section_color eq "")
839 weechat
::config_free
($buffers_config_file);
842 foreach my $option (keys %default_options_color)
844 $options{$option} = weechat
::config_new_option
(
845 $buffers_config_file,
847 $default_options_color{$option}[0],
848 $default_options_color{$option}[1],
849 $default_options_color{$option}[2],
850 $default_options_color{$option}[3],
851 $default_options_color{$option}[4],
852 $default_options_color{$option}[5],
853 $default_options_color{$option}[6],
854 $default_options_color{$option}[7],
855 $default_options_color{$option}[8],
856 $default_options_color{$option}[9],
857 $default_options_color{$option}[10],
858 $default_options_color{$option}[11],
859 $default_options_color{$option}[12],
860 $default_options_color{$option}[13],
861 $default_options_color{$option}[14]);
865 my $section_look = weechat
::config_new_section
(
866 $buffers_config_file,
867 "look", 0, 0, "", "", "", "", "", "", "", "", "", "");
868 if ($section_look eq "")
870 weechat
::config_free
($buffers_config_file);
873 foreach my $option (keys %default_options_look)
875 $options{$option} = weechat
::config_new_option
(
876 $buffers_config_file,
878 $default_options_look{$option}[0],
879 $default_options_look{$option}[1],
880 $default_options_look{$option}[2],
881 $default_options_look{$option}[3],
882 $default_options_look{$option}[4],
883 $default_options_look{$option}[5],
884 $default_options_look{$option}[6],
885 $default_options_look{$option}[7],
886 $default_options_look{$option}[8],
887 $default_options_look{$option}[9],
888 $default_options_look{$option}[10],
889 $default_options_look{$option}[11],
890 $default_options_look{$option}[12],
891 $default_options_look{$option}[13],
892 $default_options_look{$option}[14],
893 $default_options_look{$option}[15]);
901 # get bar position (left/right/top/bottom)
902 my $position = "left";
903 my $option_position = weechat
::config_get
("weechat.bar.buffers.position");
904 if ($option_position ne "")
906 $position = weechat
::config_string
($option_position);
911 my $infolist = weechat
::infolist_get
("hotlist", "", "");
912 while (weechat
::infolist_next
($infolist))
914 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")} =
915 weechat
::infolist_integer
($infolist, "priority");
916 if ( weechat
::config_boolean
( $options{"hotlist_counter"} ) eq 1 and $weechat_version >= 0x00030500)
918 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")."_count_00"} =
919 weechat
::infolist_integer
($infolist, "count_00"); # low message
920 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")."_count_01"} =
921 weechat
::infolist_integer
($infolist, "count_01"); # channel message
922 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")."_count_02"} =
923 weechat
::infolist_integer
($infolist, "count_02"); # private message
924 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")."_count_03"} =
925 weechat
::infolist_integer
($infolist, "count_03"); # highlight message
928 weechat
::infolist_free
($infolist);
937 my $max_number_digits = 0;
939 $infolist = weechat
::infolist_get
("buffer", "", "");
940 while (weechat
::infolist_next
($infolist))
942 # ignore hidden buffers (WeeChat >= 0.4.4)
943 if ($weechat_version >= 0x00040400)
945 next if (weechat
::infolist_integer
($infolist, "hidden"));
948 my $number = weechat
::infolist_integer
($infolist, "number");
949 if ($number ne $old_number)
951 @buffers = (@buffers, @current2, @current1);
956 if ($number > $max_number)
958 $max_number = $number;
960 $old_number = $number;
961 my $active = weechat
::infolist_integer
($infolist, "active");
966 $buffer->{"pointer"} = weechat
::infolist_pointer
($infolist, "pointer");
967 $buffer->{"number"} = $number;
968 $buffer->{"active"} = $active;
969 $buffer->{"current_buffer"} = weechat
::infolist_integer
($infolist, "current_buffer");
970 $buffer->{"num_displayed"} = weechat
::infolist_integer
($infolist, "num_displayed");
971 $buffer->{"plugin_name"} = weechat
::infolist_string
($infolist, "plugin_name");
972 $buffer->{"name"} = weechat
::infolist_string
($infolist, "name");
973 $buffer->{"short_name"} = weechat
::infolist_string
($infolist, "short_name");
974 $buffer->{"full_name"} = $buffer->{"plugin_name"}.".".$buffer->{"name"};
975 $buffer->{"type"} = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type");
976 #weechat::print("", $buffer->{"type"});
978 # check if buffer is active (or maybe a /part, /kick channel)
979 if ($buffer->{"type"} eq "channel" and weechat
::config_boolean
( $options{"mark_inactive"} ) eq 1)
981 my $server = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_server");
982 my $channel = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_channel");
983 my $infolist_channel = weechat
::infolist_get
("irc_channel", "", $server.",".$channel);
984 if ($infolist_channel)
986 weechat
::infolist_next
($infolist_channel);
987 $buffer->{"nicks_count"} = weechat
::infolist_integer
($infolist_channel, "nicks_count");
990 $buffer->{"nicks_count"} = 0;
992 weechat
::infolist_free
($infolist_channel);
995 my $result = check_immune_detached_buffers
($buffer->{"name"}); # checking for wildcard
997 next if ( check_detach_buffer_immediately
($buffer->{"name"}) eq 1
998 and $buffer->{"current_buffer"} eq 0
999 and ( not exists $hotlist{$buffer->{"pointer"}} or $hotlist{$buffer->{"pointer"}} < 2) ); # checking for buffer to immediately detach
1003 my $detach_time = weechat
::config_integer
( $options{"detach"});
1004 my $current_time = time();
1005 # set timer for buffers with no hotlist action
1006 $buffers_timer{$buffer->{"pointer"}} = $current_time
1007 if ( not exists $hotlist{$buffer->{"pointer"}}
1008 and $buffer->{"type"} eq "channel"
1009 and not exists $buffers_timer{$buffer->{"pointer"}}
1010 and $detach_time > 0);
1012 $buffers_timer{$buffer->{"pointer"}} = $current_time
1013 if (weechat
::config_boolean
($options{"detach_query"}) eq 1
1014 and not exists $hotlist{$buffer->{"pointer"}}
1015 and $buffer->{"type"} eq "private"
1016 and not exists $buffers_timer{$buffer->{"pointer"}}
1017 and $detach_time > 0);
1020 if (weechat
::config_boolean
($options{"detach_query"}) eq 0
1021 and $buffer->{"type"} eq "private");
1023 # free content buffer
1024 $buffers_timer{$buffer->{"pointer"}} = $current_time
1025 if (weechat
::config_boolean
($options{"detach_free_content"}) eq 1
1026 and not exists $hotlist{$buffer->{"pointer"}}
1027 and $buffer->{"type"} eq ""
1028 and not exists $buffers_timer{$buffer->{"pointer"}}
1029 and $detach_time > 0);
1031 if (weechat
::config_boolean
($options{"detach_free_content"}) eq 0
1032 and $buffer->{"type"} eq "");
1034 $detach_time = 0 if (weechat
::config_boolean
($options{"mark_inactive"}) eq 1 and defined $buffer->{"nicks_count"} and $buffer->{"nicks_count"} == 0);
1037 unless ( $buffer->{"current_buffer"} eq 0
1038 and not exists $hotlist{$buffer->{"pointer"}}
1039 # and $buffer->{"type"} eq "channel"
1040 and exists $buffers_timer{$buffer->{"pointer"}}
1041 and $detach_time > 0
1042 and $weechat_version >= 0x00030800
1043 and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
1047 push(@current2, $buffer);
1051 push(@current1, $buffer);
1054 elsif ( $buffer->{"current_buffer"} eq 0
1055 and not exists $hotlist{$buffer->{"pointer"}}
1056 # and $buffer->{"type"} eq "channel"
1057 and exists $buffers_timer{$buffer->{"pointer"}}
1058 and $detach_time > 0
1059 and $weechat_version >= 0x00030800
1060 and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
1061 { # check for option detach_displayed_buffers and if buffer is displayed in a split window
1062 if ( $buffer->{"num_displayed"} eq 1
1063 and weechat
::config_boolean
($options{"detach_displayed_buffers"}) eq 0 )
1065 my $infolist_window = weechat
::infolist_get
("window", "", "");
1066 while (weechat
::infolist_next
($infolist_window))
1068 my $buffer_ptr = weechat
::infolist_pointer
($infolist_window, "buffer");
1069 if ($buffer_ptr eq $buffer->{"pointer"})
1071 $buffer->{"window"} = weechat
::infolist_integer
($infolist_window, "number");
1074 weechat
::infolist_free
($infolist_window);
1076 push(@current2, $buffer);
1080 else # buffer in "immune_detach_buffers"
1084 push(@current2, $buffer);
1088 push(@current1, $buffer);
1094 if ($max_number >= 1)
1096 $max_number_digits = length(int($max_number));
1098 @buffers = (@buffers, @current2, @current1);
1099 weechat
::infolist_free
($infolist);
1101 # sort buffers by number, name or shortname
1106 for my $buffer (@buffers)
1109 if (weechat
::config_integer
( $options{"sort"} ) eq 1) # number = 0; name = 1
1111 my $name = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_custom_name");
1112 if (not defined $name or $name eq "") {
1113 if (weechat
::config_boolean
( $options{"short_names"} ) eq 1) {
1114 $name = $buffer->{"short_name"};
1116 $name = $buffer->{"name"};
1119 if (weechat
::config_integer
($options{"name_size_max"}) >= 1){
1120 $name = encode
("UTF-8", substr(decode
("UTF-8", $name), 0, weechat
::config_integer
($options{"name_size_max"})));
1122 if ( weechat
::config_boolean
($options{"core_to_front"}) eq 1)
1124 if ( (weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "private") )
1126 my $type = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type");
1127 if ( $type eq "" and $name ne "weechat")
1132 $name = " " . $name;
1136 $key = sprintf("%s%08d", lc($name), $buffer->{"number"});
1140 $key = sprintf("%08d", $number);
1142 $sorted_buffers{$key} = $buffer;
1147 # build string with buffers
1149 foreach my $key (sort keys %sorted_buffers)
1151 my $buffer = $sorted_buffers{$key};
1153 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "server" )
1155 # buffer type "server" or merged with core?
1156 if ( ($buffer->{"type"} eq "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1161 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "channel" )
1163 # buffer type "channel" or merged with core?
1164 if ( ($buffer->{"type"} eq "channel" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1169 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "private" )
1171 # buffer type "private" or merged with core?
1172 if ( ($buffer->{"type"} eq "private" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1177 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "keepserver" )
1179 if ( ($buffer->{"type"} ne "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1184 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "all" )
1186 if ( ! $buffer->{"active"} )
1192 push(@buffers_focus, $buffer); # buffer > buffers_focus, for mouse support
1196 $color = weechat
::config_color
( $options{"color_default_fg"} );
1197 $bg = weechat
::config_color
( $options{"color_default_bg"} );
1199 if ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") eq "private" )
1201 if ( (weechat
::config_color
($options{"queries_default_bg"})) ne "default" || (weechat
::config_color
($options{"queries_default_fg"})) ne "default" )
1203 $bg = weechat
::config_color
( $options{"queries_default_bg"} );
1204 $color = weechat
::config_color
( $options{"queries_default_fg"} );
1207 # check for core and buffer with free content
1208 if ( (weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "private") )
1210 $color = weechat
::config_color
( $options{"color_none_channel_fg"} );
1211 $bg = weechat
::config_color
( $options{"color_none_channel_bg"} );
1213 # default whitelist buffer?
1214 if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
1216 $color = weechat
::config_color
( $options{"color_whitelist_default_fg"} );
1217 $bg = weechat
::config_color
( $options{"color_whitelist_default_bg"} );
1220 $color = "default" if ($color eq "");
1222 # color for channel and query buffer
1223 if (exists $hotlist{$buffer->{"pointer"}})
1225 delete $buffers_timer{$buffer->{"pointer"}};
1226 # check if buffer is in whitelist buffer
1227 if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
1229 $bg = weechat
::config_color
( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
1230 $color = weechat
::config_color
( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
1232 elsif ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") eq "private" )
1234 # queries_default_fg/bg and buffers.color.queries_message_fg/bg
1235 if ( (weechat
::config_color
($options{"queries_highlight_fg"})) ne "default" ||
1236 (weechat
::config_color
($options{"queries_highlight_bg"})) ne "default" ||
1237 (weechat
::config_color
($options{"queries_message_fg"})) ne "default" ||
1238 (weechat
::config_color
($options{"queries_message_bg"})) ne "default" )
1240 if ( ($hotlist{$buffer->{"pointer"}}) == 2 )
1242 $bg = weechat
::config_color
( $options{"queries_message_bg"} );
1243 $color = weechat
::config_color
( $options{"queries_message_fg"} );
1246 elsif ( ($hotlist{$buffer->{"pointer"}}) == 3 )
1248 $bg = weechat
::config_color
( $options{"queries_highlight_bg"} );
1249 $color = weechat
::config_color
( $options{"queries_highlight_fg"} );
1253 $bg = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
1254 $color = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
1258 $bg = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
1259 $color = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
1263 if ($buffer->{"current_buffer"})
1265 $color = weechat
::config_color
( $options{"color_current_fg"} );
1266 $bg = weechat
::config_color
( $options{"color_current_bg"} );
1269 $color_bg = weechat
::color
(",".$bg) if ($bg ne "");
1271 # create channel number for output
1272 if ( weechat
::config_string
( $options{"show_prefix_bufname"} ) ne "" )
1275 weechat
::color
( weechat
::config_color
( $options{"color_prefix_bufname"} ) ).
1276 weechat
::config_string
( $options{"show_prefix_bufname"} ).
1277 weechat
::color
("default");
1280 if ( weechat
::config_boolean
( $options{"show_number"} ) eq 1 ) # on
1282 if (( weechat
::config_boolean
( $options{"indenting_number"} ) eq 1)
1283 && (($position eq "left") || ($position eq "right")))
1285 $str .= weechat
::color
("default").$color_bg
1286 .(" " x
($max_number_digits - length(int($buffer->{"number"}))));
1288 if ($old_number ne $buffer->{"number"})
1290 $str .= weechat
::color
( weechat
::config_color
( $options{"color_number"} ) )
1292 .$buffer->{"number"}
1293 .weechat
::color
("default")
1295 .weechat
::color
( weechat
::config_color
( $options{"color_number_char"} ) )
1296 .weechat
::config_string
( $options{"show_number_char"} )
1302 $indent = ((" " x
length($buffer->{"number"}))." ") if (($position eq "left") || ($position eq "right"));
1303 $str .= weechat
::color
("default")
1309 if (( weechat
::config_integer
( $options{"indenting"} ) ne 0 ) # indenting NOT off
1310 && (($position eq "left") || ($position eq "right")))
1312 my $type = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type");
1313 if (($type eq "channel") || ($type eq "private"))
1315 if ( weechat
::config_integer
( $options{"indenting"} ) eq 1 )
1319 elsif ( (weechat
::config_integer
($options{"indenting"}) eq 2) and (weechat
::config_integer
($options{"indenting_number"}) eq 0) ) #under_name
1321 if ( weechat
::config_boolean
( $options{"show_number"} ) eq 0 )
1326 $str .= ( (" " x
( $max_number_digits - length($buffer->{"number"}) ))." " );
1332 $str .= weechat
::config_string
( $options{"show_prefix_query"}) if (weechat
::config_string
( $options{"show_prefix_query"} ) ne "" and $buffer->{"type"} eq "private");
1334 if (weechat
::config_boolean
( $options{"show_prefix"} ) eq 1)
1336 my $nickname = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_nick");
1337 if ($nickname ne "")
1339 # with version >= 0.3.2, this infolist will return only nick
1340 # with older versions, whole nicklist is returned for buffer, and this can be very slow
1341 my $infolist_nick = weechat
::infolist_get
("nicklist", $buffer->{"pointer"}, "nick_".$nickname);
1342 if ($infolist_nick ne "")
1344 while (weechat
::infolist_next
($infolist_nick))
1346 if ((weechat
::infolist_string
($infolist_nick, "type") eq "nick")
1347 && (weechat
::infolist_string
($infolist_nick, "name") eq $nickname))
1349 my $prefix = weechat
::infolist_string
($infolist_nick, "prefix");
1350 if (($prefix ne " ") or (weechat
::config_boolean
( $options{"show_prefix_empty"} ) eq 1))
1352 # with version >= 0.3.5, it is now a color name (for older versions: option name with color)
1353 if (int($weechat_version) >= 0x00030500)
1355 $str .= weechat
::color
(weechat
::infolist_string
($infolist_nick, "prefix_color"));
1359 $str .= weechat
::color
(weechat
::config_color
(
1360 weechat
::config_get
(
1361 weechat
::infolist_string
($infolist_nick, "prefix_color"))));
1368 weechat
::infolist_free
($infolist_nick);
1372 if ($buffer->{"type"} eq "channel" and weechat
::config_boolean
( $options{"mark_inactive"} ) eq 1 and $buffer->{"nicks_count"} == 0)
1377 $str .= weechat
::color
($color) . weechat
::color
(",".$bg);
1379 my $name = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_custom_name");
1380 if (not defined $name or $name eq "")
1382 if (weechat
::config_boolean
( $options{"short_names"} ) eq 1) {
1383 $name = $buffer->{"short_name"};
1385 $name = $buffer->{"name"};
1389 if (weechat
::config_integer
($options{"name_size_max"}) >= 1) # check max_size of buffer name
1391 $name = decode
("UTF-8", $name);
1392 $str .= encode
("UTF-8", substr($name, 0, weechat
::config_integer
($options{"name_size_max"})));
1393 $str .= weechat
::color
(weechat
::config_color
( $options{"color_number_char"})).weechat
::config_string
($options{"name_crop_suffix"}) if (length($name) > weechat
::config_integer
($options{"name_size_max"}));
1394 $str .= add_inactive_parentless
($buffer->{"type"}, $buffer->{"nicks_count"});
1395 $str .= add_hotlist_count
($buffer->{"pointer"}, %hotlist);
1400 $str .= add_inactive_parentless
($buffer->{"type"}, $buffer->{"nicks_count"});
1401 $str .= add_hotlist_count
($buffer->{"pointer"}, %hotlist);
1404 if ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") eq "server" and weechat
::config_boolean
($options{"show_lag"}) eq 1)
1406 my $color_lag = weechat
::config_color
(weechat
::config_get
("irc.color.item_lag_finished"));
1407 my $min_lag = weechat
::config_integer
(weechat
::config_get
("irc.network.lag_min_show"));
1408 my $infolist_server = weechat
::infolist_get
("irc_server", "", $buffer->{"short_name"});
1409 weechat
::infolist_next
($infolist_server);
1410 my $lag = (weechat
::infolist_integer
($infolist_server, "lag"));
1411 weechat
::infolist_free
($infolist_server);
1412 if ( int($lag) > int($min_lag) )
1415 $str .= weechat
::color
("default") . " (" . weechat
::color
($color_lag) . $lag . weechat
::color
("default") . ")";
1418 if (weechat
::config_boolean
($options{"detach_displayed_buffers"}) eq 0
1419 and weechat
::config_boolean
($options{"detach_display_window_number"}) eq 1)
1421 if ($buffer->{"window"})
1423 $str .= weechat
::color
("default") . " (" . weechat
::color
(weechat
::config_color
( $options{"color_number"})) . $buffer->{"window"} . weechat
::color
("default") . ")";
1426 $str .= weechat
::color
("default");
1428 if ( weechat
::config_string
( $options{"show_suffix_bufname"} ) ne "" )
1430 $str .= weechat
::color
( weechat
::config_color
( $options{"color_suffix_bufname"} ) ).
1431 weechat
::config_string
( $options{"show_suffix_bufname"} ).
1432 weechat
::color
("default");
1436 $old_number = $buffer->{"number"};
1439 # remove spaces and/or linefeed at the end
1445 sub add_inactive_parentless
1447 my ($buf_type, $buf_nicks_count) = @_;
1449 if ($buf_type eq "channel" and weechat
::config_boolean
( $options{"mark_inactive"} ) eq 1 and $buf_nicks_count == 0)
1451 $str .= weechat
::color
(weechat
::config_color
( $options{"color_number_char"}));
1457 sub add_hotlist_count
1459 my ($bufpointer, %hotlist) = @_;
1461 return "" if ( weechat
::config_boolean
( $options{"hotlist_counter"} ) eq 0 or ($weechat_version < 0x00030500)); # off
1462 my $col_number_char = weechat
::color
(weechat
::config_color
( $options{"color_number_char"}) );
1463 my $str = " ".$col_number_char."(";
1466 if (defined $hotlist{$bufpointer."_count_00"})
1468 my $bg = weechat
::config_color
( $options{"color_hotlist_low_bg"} );
1469 my $color = weechat
::config_color
( $options{"color_hotlist_low_fg"} );
1470 $str .= weechat
::color
($bg).
1471 weechat
::color
($color).
1472 $hotlist{$bufpointer."_count_00"} if ($hotlist{$bufpointer."_count_00"} ne "0");
1476 if (defined $hotlist{$bufpointer."_count_01"})
1478 my $bg = weechat
::config_color
( $options{"color_hotlist_message_bg"} );
1479 my $color = weechat
::config_color
( $options{"color_hotlist_message_fg"} );
1480 if ($str =~ /[0-9]$/)
1483 weechat
::color
($bg).
1484 weechat
::color
($color).
1485 $hotlist{$bufpointer."_count_01"} if ($hotlist{$bufpointer."_count_01"} ne "0");
1488 $str .= weechat
::color
($bg).
1489 weechat
::color
($color).
1490 $hotlist{$bufpointer."_count_01"} if ($hotlist{$bufpointer."_count_01"} ne "0");
1494 if (defined $hotlist{$bufpointer."_count_02"})
1496 my $bg = weechat
::config_color
( $options{"color_hotlist_private_bg"} );
1497 my $color = weechat
::config_color
( $options{"color_hotlist_private_fg"} );
1498 if ($str =~ /[0-9]$/)
1501 weechat
::color
($bg).
1502 weechat
::color
($color).
1503 $hotlist{$bufpointer."_count_02"} if ($hotlist{$bufpointer."_count_02"} ne "0");
1506 $str .= weechat
::color
($bg).
1507 weechat
::color
($color).
1508 $hotlist{$bufpointer."_count_02"} if ($hotlist{$bufpointer."_count_02"} ne "0");
1512 if (defined $hotlist{$bufpointer."_count_03"})
1514 my $bg = weechat
::config_color
( $options{"color_hotlist_highlight_bg"} );
1515 my $color = weechat
::config_color
( $options{"color_hotlist_highlight_fg"} );
1516 if ($str =~ /[0-9]$/)
1519 weechat
::color
($bg).
1520 weechat
::color
($color).
1521 $hotlist{$bufpointer."_count_03"} if ($hotlist{$bufpointer."_count_03"} ne "0");
1524 $str .= weechat
::color
($bg).
1525 weechat
::color
($color).
1526 $hotlist{$bufpointer."_count_03"} if ($hotlist{$bufpointer."_count_03"} ne "0");
1529 $str .= $col_number_char. ")";
1531 $str = "" if (weechat
::string_remove_color
($str, "") eq " ()"); # remove color and check for buffer with no messages
1535 sub buffers_signal_buffer
1537 my ($data, $signal, $signal_data) = @_;
1539 # check for buffer_switch and set or remove detach time
1540 if ($weechat_version >= 0x00030800)
1542 if ($signal eq "buffer_switch")
1544 my $pointer = weechat
::hdata_get_list
(weechat
::hdata_get
("buffer"), "gui_buffer_last_displayed"); # get switched buffer
1545 my $current_time = time();
1546 if ( weechat
::buffer_get_string
($pointer, "localvar_type") eq "channel")
1548 $buffers_timer{$pointer} = $current_time;
1552 delete $buffers_timer{$pointer};
1555 if ($signal eq "buffer_opened")
1557 my $current_time = time();
1558 $buffers_timer{$signal_data} = $current_time;
1560 if ($signal eq "buffer_closing")
1562 delete $buffers_timer{$signal_data};
1565 weechat
::bar_item_update
($SCRIPT_NAME);
1566 return weechat
::WEECHAT_RC_OK
;
1569 sub buffers_signal_hotlist
1571 weechat
::bar_item_update
($SCRIPT_NAME);
1572 return weechat
::WEECHAT_RC_OK
;
1576 sub buffers_signal_config_whitelist
1578 @whitelist_buffers = ();
1579 @whitelist_buffers = split( /,/, weechat
::config_string
( $options{"look_whitelist_buffers"} ) );
1580 weechat
::bar_item_update
($SCRIPT_NAME);
1581 return weechat
::WEECHAT_RC_OK
;
1584 sub buffers_signal_config_immune_detach_buffers
1586 @immune_detach_buffers = ();
1587 @immune_detach_buffers = split( /,/, weechat
::config_string
( $options{"immune_detach_buffers"} ) );
1588 weechat
::bar_item_update
($SCRIPT_NAME);
1589 return weechat
::WEECHAT_RC_OK
;
1592 sub buffers_signal_config_detach_buffer_immediately
1594 @detach_buffer_immediately = ();
1595 @detach_buffer_immediately = split( /,/, weechat
::config_string
( $options{"detach_buffer_immediately"} ) );
1596 weechat
::bar_item_update
($SCRIPT_NAME);
1597 return weechat
::WEECHAT_RC_OK
;
1600 sub buffers_signal_config
1602 weechat
::bar_item_update
($SCRIPT_NAME);
1603 return weechat
::WEECHAT_RC_OK
;
1606 # called when mouse click occured in buffers item: this callback returns buffer
1607 # hash according to line of item where click occured
1608 sub buffers_focus_buffers
1610 my %info = %{$_[1]};
1611 my $item_line = int($info{"_bar_item_line"});
1613 if (($info{"_bar_item_name"} eq $SCRIPT_NAME) && ($item_line >= 0) && ($item_line <= $#buffers_focus))
1615 $hash = $buffers_focus[$item_line];
1620 my $hash_focus = $buffers_focus[0];
1621 foreach my $key (keys %$hash_focus)
1623 $hash->{$key} = "?";
1629 # called when a mouse action is done on buffers item, to execute action
1630 # possible actions: jump to a buffer or move buffer in list (drag & drop of buffer)
1631 sub buffers_hsignal_mouse
1633 my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
1634 my $current_buffer = weechat
::buffer_get_integer
(weechat
::current_buffer
(), "number"); # get current buffer number
1636 if ( $hash{"_key"} eq "button1" )
1639 if ($hash{"number"} eq $hash{"number2"})
1641 if ( weechat
::config_boolean
($options{"jump_prev_next_visited_buffer"}) )
1643 if ( $current_buffer eq $hash{"number"} )
1645 weechat
::command
("", "/input jump_previously_visited_buffer");
1649 weechat
::command
("", "/buffer ".$hash{"full_name"});
1654 weechat
::command
("", "/buffer ".$hash{"full_name"});
1659 move_buffer
(%hash) if (weechat
::config_boolean
($options{"mouse_move_buffer"}));
1662 elsif ( ($hash{"_key"} eq "button2") && (weechat
::config_boolean
($options{"jump_prev_next_visited_buffer"})) )
1664 # right mouse button
1665 if ( $current_buffer eq $hash{"number2"} )
1667 weechat
::command
("", "/input jump_next_visited_buffer");
1670 elsif ( $hash{"_key"} =~ /wheelup$/ )
1673 if (weechat
::config_boolean
($options{"mouse_wheel"}))
1675 weechat
::command
("", "/buffer -1");
1678 elsif ( $hash{"_key"} =~ /wheeldown$/ )
1681 if (weechat
::config_boolean
($options{"mouse_wheel"}))
1683 weechat
::command
("", "/buffer +1");
1688 my $infolist = weechat
::infolist_get
("hook", "", "command,menu");
1689 my $has_menu_command = weechat
::infolist_next
($infolist);
1690 weechat
::infolist_free
($infolist);
1692 if ( $has_menu_command && $hash{"_key"} =~ /button2/ )
1694 if ($hash{"number"} eq $hash{"number2"})
1696 weechat
::command
($hash{"pointer"}, "/menu buffer1 $hash{short_name} $hash{number}");
1700 weechat
::command
($hash{"pointer"}, "/menu buffer2 $hash{short_name}/$hash{short_name2} $hash{number} $hash{number2}")
1705 move_buffer
(%hash) if (weechat
::config_boolean
($options{"mouse_move_buffer"}));
1713 my $number2 = $hash{"number2"};
1714 if ($number2 eq "?")
1716 # if number 2 is not known (end of gesture outside buffers list), then set it
1717 # according to mouse gesture
1719 if (($hash{"_key"} =~ /gesture-right/) || ($hash{"_key"} =~ /gesture-down/))
1721 $number2 = "999999";
1722 if ($weechat_version >= 0x00030600)
1724 my $hdata_buffer = weechat
::hdata_get
("buffer");
1725 my $last_gui_buffer = weechat
::hdata_get_list
($hdata_buffer, "last_gui_buffer");
1726 if ($last_gui_buffer)
1728 $number2 = weechat
::hdata_integer
($hdata_buffer, $last_gui_buffer, "number") + 1;
1733 my $ptrbuf = weechat
::current_buffer
();
1734 weechat
::command
($hash{"pointer"}, "/buffer move ".$number2);
1737 sub check_immune_detached_buffers
1739 my ($buffername) = @_;
1740 foreach ( @immune_detach_buffers ){
1741 my $immune_buffer = weechat
::string_mask_to_regex
($_);
1742 if ($buffername =~ /^$immune_buffer$/i)
1750 sub check_detach_buffer_immediately
1752 my ($buffername) = @_;
1753 foreach ( @detach_buffer_immediately ){
1754 my $detach_buffer = weechat
::string_mask_to_regex
($_);
1755 if ($buffername =~ /^$detach_buffer$/i)
1765 weechat
::command
("", "/bar hide " . $SCRIPT_NAME) if ( weechat
::config_boolean
($options{"toggle_bar"}) eq 1 );
1766 return weechat
::WEECHAT_RC_OK
1772 my $infolist = weechat
::infolist_get
("bar", "", "");
1773 while (weechat
::infolist_next
($infolist))
1775 my $bar_items = weechat
::infolist_string
($infolist, "items");
1776 if (index($bar_items, $SCRIPT_NAME) != -1)
1778 my $name = weechat
::infolist_string
($infolist, "name");
1779 if ($name ne $SCRIPT_NAME)
1786 weechat
::infolist_free
($infolist);