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 # 2016-05-01, mumixam <mumixam@gmail.com>:
24 # v5.4: added option "detach_buffer_immediately_level"
25 # 2015-08-21, Matthew Cox <matthewcpcox@gmail.com>
26 # v5.3: add option "indenting_amount", to adjust the indenting of channel buffers
27 # 2015-05-02, arza <arza@arza.us>:
28 # v5.2: truncate long names (name_size_max) more when mark_inactive adds parenthesis
29 # 2015-03-29, Ed Santiago <ed@edsantiago.com>:
30 # v5.1: merged buffers: always indent, except when filling is horizontal
32 # v5.0: fix cropping non-latin buffer names
33 # 2014-08-29, Patrick Steinhardt <ps@pks.im>:
34 # v4.9: add support for specifying custom buffer names
35 # 2014-07-19, Sebastien Helleu <flashcode@flashtux.org>:
36 # v4.8: add support of ctrl + mouse wheel to jump to previous/next buffer,
37 # new option "mouse_wheel"
38 # 2014-06-22, Sebastien Helleu <flashcode@flashtux.org>:
39 # v4.7: fix typos in options
40 # 2014-04-05, Sebastien Helleu <flashcode@flashtux.org>:
41 # v4.6: add support of hidden buffers (WeeChat >= 0.4.4)
42 # 2014-01-01, Sebastien Helleu <flashcode@flashtux.org>:
43 # v4.5: add option "mouse_move_buffer"
44 # 2013-12-11, Sebastien Helleu <flashcode@flashtux.org>:
45 # v4.4: fix buffer number on drag to the end of list when option
46 # weechat.look.buffer_auto_renumber is off
47 # 2013-12-10, nils_2@freenode.#weechat:
48 # v4.3: add options "prefix_bufname" and "suffix_bufname (idea by silverd)
49 # : fix hook_timer() for show_lag wasn't disabled
50 # : improved signal handling (less updating of buffers list)
51 # 2013-11-07, Sebastien Helleu <flashcode@flashtux.org>:
52 # v4.2: use default filling "columns_vertical" when bar position is top/bottom
53 # 2013-10-31, nils_2@freenode.#weechat:
54 # v4.1: add option "detach_buffer_immediately" (idea by farn)
55 # 2013-10-20, nils_2@freenode.#weechat:
56 # v4.0: add options "detach_displayed_buffers", "detach_display_window_number"
57 # 2013-09-27, nils_2@freenode.#weechat:
58 # v3.9: add option "toggle_bar" and option "show_prefix_query" (idea by IvarB)
59 # : fix problem with linefeed at end of list of buffers (reported by grawity)
60 # 2012-10-18, nils_2@freenode.#weechat:
61 # v3.8: add option "mark_inactive", to mark buffers you are not in (idea by xrdodrx)
62 # : add wildcard "*" for immune_detach_buffers (idea by StarWeaver)
63 # : add new options "detach_query" and "detach_free_content" (idea by StarWeaver)
64 # 2012-10-06, Nei <anti.teamidiot.de>:
65 # v3.7: call menu on right mouse if menu script is loaded.
66 # 2012-10-06, nils_2 <weechatter@arcor.de>:
67 # v3.6: add new option "hotlist_counter" (idea by torque).
68 # 2012-06-02, nils_2 <weechatter@arcor.de>:
69 # v3.5: add values "server|channel|private|all|keepserver|none" to option "hide_merged_buffers" (suggested by dominikh).
70 # 2012-05-25, nils_2 <weechatter@arcor.de>:
71 # v3.4: add new option "show_lag".
72 # 2012-04-07, Sebastien Helleu <flashcode@flashtux.org>:
73 # v3.3: fix truncation of wide chars in buffer name (option name_size_max) (bug #36034)
74 # 2012-03-15, nils_2 <weechatter@arcor.de>:
75 # v3.2: add new option "detach"(weechat >= 0.3.8)
76 # add new option "immune_detach_buffers" (requested by Mkaysi)
77 # add new function buffers_whitelist add|del|reset (suggested by FiXato)
78 # add new function buffers_detach add|del|reset
79 # 2012-03-09, Sebastien Helleu <flashcode@flashtux.org>:
80 # v3.1: fix reload of config file
81 # 2012-01-29, nils_2 <weechatter@arcor.de>:
82 # v3.0: fix: buffers did not update directly during window_switch (reported by FiXato)
83 # 2012-01-29, nils_2 <weechatter@arcor.de>:
84 # v2.9: add options "name_size_max" and "name_crop_suffix"
85 # 2012-01-08, nils_2 <weechatter@arcor.de>:
86 # v2.8: fix indenting for option "show_number off"
87 # fix unset of buffer activity in hotlist when buffer was moved with mouse
88 # add buffer with free content and core buffer sorted first (suggested by nyuszika7h)
89 # add options queries_default_fg/bg and queries_message_fg/bg (suggested by FiXato)
90 # add clicking with left button on current buffer will do a jump_previously_visited_buffer (suggested by FiXato)
91 # add clicking with right button on current buffer will do a jump_next_visited_buffer
92 # add additional informations in help texts
93 # add default_fg and default_bg for whitelist channels
94 # internal changes (script is now 3Kb smaller)
95 # 2012-01-04, Sebastien Helleu <flashcode@flashtux.org>:
96 # v2.7: fix regex lookup in whitelist buffers list
97 # 2011-12-04, nils_2 <weechatter@arcor.de>:
98 # v2.6: add own config file (buffers.conf)
99 # add new behavior for indenting (under_name)
100 # add new option to set different color for server buffers and buffers with free content
101 # 2011-10-30, nils_2 <weechatter@arcor.de>:
102 # v2.5: add new options "show_number_char" and "color_number_char",
103 # add help-description for options
104 # 2011-08-24, Sebastien Helleu <flashcode@flashtux.org>:
105 # v2.4: add mouse support
106 # 2011-06-06, nils_2 <weechatter@arcor.de>:
107 # v2.3: added: missed option "color_whitelist_default"
108 # 2011-03-23, Sebastien Helleu <flashcode@flashtux.org>:
109 # v2.2: fix color of nick prefix with WeeChat >= 0.3.5
110 # 2011-02-13, nils_2 <weechatter@arcor.de>:
111 # v2.1: add options "color_whitelist_*"
112 # 2010-10-05, Sebastien Helleu <flashcode@flashtux.org>:
113 # v2.0: add options "sort" and "show_number"
114 # 2010-04-12, Sebastien Helleu <flashcode@flashtux.org>:
115 # v1.9: replace call to log() by length() to align buffer numbers
116 # 2010-04-02, Sebastien Helleu <flashcode@flashtux.org>:
117 # v1.8: fix bug with background color and option indenting_number
118 # 2010-04-02, Helios <helios@efemes.de>:
119 # v1.7: add indenting_number option
120 # 2010-02-25, m4v <lambdae2@gmail.com>:
121 # v1.6: add option to hide empty prefixes
122 # 2010-02-12, Sebastien Helleu <flashcode@flashtux.org>:
123 # v1.5: add optional nick prefix for buffers like IRC channels
124 # 2009-09-30, Sebastien Helleu <flashcode@flashtux.org>:
125 # v1.4: remove spaces for indenting when bar position is top/bottom
126 # 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
127 # v1.3: add option "hide_merged_buffers"
128 # 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
129 # v1.2: improve display with merged buffers
130 # 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
131 # v1.1: sync with last API changes
132 # 2009-02-21, Sebastien Helleu <flashcode@flashtux.org>:
133 # v1.0: remove timer used to update bar item first time (not needed any more)
134 # 2009-02-17, Sebastien Helleu <flashcode@flashtux.org>:
135 # v0.9: fix bug with indenting of private buffers
136 # 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
137 # v0.8: update syntax for command /set (comments)
138 # 2008-10-20, Jiri Golembiovsky <golemj@gmail.com>:
139 # v0.7: add indenting option
140 # 2008-10-01, Sebastien Helleu <flashcode@flashtux.org>:
141 # v0.6: add default color for buffers, and color for current active buffer
142 # 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
143 # v0.5: fix color for "low" level entry in hotlist
144 # 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
145 # v0.4: rename option "show_category" to "short_names",
146 # remove option "color_slash"
147 # 2008-09-15, Sebastien Helleu <flashcode@flashtux.org>:
148 # v0.3: fix bug with priority in hotlist (var not defined)
149 # 2008-09-02, Sebastien Helleu <flashcode@flashtux.org>:
150 # v0.2: add color for buffers with activity and config options for
151 # colors, add config option to display/hide categories
152 # 2008-03-15, Sebastien Helleu <flashcode@flashtux.org>:
153 # v0.1: script creation
155 # Help about settings:
156 # display all settings for script (or use iset.pl script to change settings):
158 # show help text for option buffers.look.whitelist_buffers:
159 # /help buffers.look.whitelist_buffers
161 # Mouse-support (standard key bindings):
163 # - click on a buffer to switch to selected buffer
164 # - click on current buffer will do action jump_previously_visited_buffer
165 # - drag a buffer and drop it on another position will move the buffer to position
166 # right mouse-button:
167 # - click on current buffer will do action jump_next_visited_buffer
168 # - moving buffer to the left/right will close buffer.
172 use Encode
qw( decode encode );
173 # -----------------------------[ internal ]-------------------------------------
174 my $SCRIPT_NAME = "buffers";
175 my $SCRIPT_VERSION = "5.4";
177 my $BUFFERS_CONFIG_FILE_NAME = "buffers";
178 my $buffers_config_file;
179 my $cmd_buffers_whitelist= "buffers_whitelist";
180 my $cmd_buffers_detach = "buffers_detach";
184 my %mouse_keys = ("\@item(buffers):button1*" => "hsignal:buffers_mouse",
185 "\@item(buffers):button2*" => "hsignal:buffers_mouse",
186 "\@bar(buffers):ctrl-wheelup" => "hsignal:buffers_mouse",
187 "\@bar(buffers):ctrl-wheeldown" => "hsignal:buffers_mouse");
189 my %hotlist_level = (0 => "low", 1 => "message", 2 => "private", 3 => "highlight");
190 my @whitelist_buffers = ();
191 my @immune_detach_buffers= ();
192 my @detach_buffer_immediately= ();
193 my @buffers_focus = ();
194 my %buffers_timer = ();
197 # --------------------------------[ init ]--------------------------------------
198 weechat
::register
($SCRIPT_NAME, "Sebastien Helleu <flashcode\@flashtux.org>",
199 $SCRIPT_VERSION, "GPL3",
200 "Sidebar with list of buffers", "shutdown_cb", "");
201 my $weechat_version = weechat
::info_get
("version_number", "") || 0;
203 buffers_config_init
();
204 buffers_config_read
();
206 weechat
::bar_item_new
($SCRIPT_NAME, "build_buffers", "");
207 weechat
::bar_new
($SCRIPT_NAME, "0", "0", "root", "", "left", "columns_vertical",
208 "vertical", "0", "0", "default", "default", "default", "1",
211 if ( check_bar_item
() == 0 )
213 weechat
::command
("", "/bar show " . $SCRIPT_NAME) if ( weechat
::config_boolean
($options{"toggle_bar"}) eq 1 );
216 weechat
::hook_signal
("buffer_opened", "buffers_signal_buffer", "");
217 weechat
::hook_signal
("buffer_closed", "buffers_signal_buffer", "");
218 weechat
::hook_signal
("buffer_merged", "buffers_signal_buffer", "");
219 weechat
::hook_signal
("buffer_unmerged", "buffers_signal_buffer", "");
220 weechat
::hook_signal
("buffer_moved", "buffers_signal_buffer", "");
221 weechat
::hook_signal
("buffer_renamed", "buffers_signal_buffer", "");
222 weechat
::hook_signal
("buffer_switch", "buffers_signal_buffer", "");
223 weechat
::hook_signal
("buffer_hidden", "buffers_signal_buffer", ""); # WeeChat >= 0.4.4
224 weechat
::hook_signal
("buffer_unhidden", "buffers_signal_buffer", ""); # WeeChat >= 0.4.4
225 weechat
::hook_signal
("buffer_localvar_added", "buffers_signal_buffer", "");
226 weechat
::hook_signal
("buffer_localvar_changed", "buffers_signal_buffer", "");
228 weechat
::hook_signal
("window_switch", "buffers_signal_buffer", "");
229 weechat
::hook_signal
("hotlist_changed", "buffers_signal_hotlist", "");
230 #weechat::hook_command_run("/input switch_active_*", "buffers_signal_buffer", "");
231 weechat
::bar_item_update
($SCRIPT_NAME);
234 if ($weechat_version >= 0x00030600)
236 weechat
::hook_focus
($SCRIPT_NAME, "buffers_focus_buffers", "");
237 weechat
::hook_hsignal
("buffers_mouse", "buffers_hsignal_mouse", "");
238 weechat
::key_bind
("mouse", \
%mouse_keys);
241 weechat
::hook_command
($cmd_buffers_whitelist,
242 "add/del current buffer to/from buffers whitelist",
243 "[add] || [del] || [reset]",
244 " add: add current buffer in configuration file\n".
245 " del: delete current buffer from configuration file\n".
246 "reset: reset all buffers from configuration file ".
247 "(no confirmation!)\n\n".
249 "/$cmd_buffers_whitelist add\n",
253 "buffers_cmd_whitelist", "");
254 weechat
::hook_command
($cmd_buffers_detach,
255 "add/del current buffer to/from buffers detach",
256 "[add] || [del] || [reset]",
257 " add: add current buffer in configuration file\n".
258 " del: delete current buffer from configuration file\n".
259 "reset: reset all buffers from configuration file ".
260 "(no confirmation!)\n\n".
262 "/$cmd_buffers_detach add\n",
266 "buffers_cmd_detach", "");
268 if ($weechat_version >= 0x00030800)
270 weechat
::hook_config
("buffers.look.detach", "hook_timer_detach", "");
271 if (weechat
::config_integer
($options{"detach"}) > 0)
273 $Hooks{timer_detach
} = weechat
::hook_timer
(weechat
::config_integer
($options{"detach"}) * 1000,
274 60, 0, "buffers_signal_hotlist", "");
278 weechat
::hook_config
("buffers.look.show_lag", "hook_timer_lag", "");
280 if (weechat
::config_boolean
($options{"show_lag"}))
282 $Hooks{timer_lag
} = weechat
::hook_timer
(
283 weechat
::config_integer
(weechat
::config_get
("irc.network.lag_refresh_interval")) * 1000,
284 0, 0, "buffers_signal_hotlist", "");
287 # -------------------------------- [ command ] --------------------------------
288 sub buffers_cmd_whitelist
290 my ( $data, $buffer, $args ) = @_;
292 my $buffers_whitelist = weechat
::config_string
( weechat
::config_get
("buffers.look.whitelist_buffers") );
293 return weechat
::WEECHAT_RC_OK
if ( $buffers_whitelist eq "" and $args eq "del" or $buffers_whitelist eq "" and $args eq "reset" );
294 my @buffers_list = split( /,/, $buffers_whitelist );
296 my $infolist = weechat
::infolist_get
("buffer", weechat
::current_buffer
(), "");
297 weechat
::infolist_next
($infolist);
298 my $buffers_name = weechat
::infolist_string
($infolist, "name");
299 weechat
::infolist_free
($infolist);
300 return weechat
::WEECHAT_RC_OK
if ( $buffers_name eq "" ); # should never happen
302 if ( $args eq "add" )
304 return weechat
::WEECHAT_RC_OK
if ( grep /^$buffers_name$/, @buffers_list ); # check if buffer already in list
305 push @buffers_list, ( $buffers_name );
306 my $buffers_list = &create_whitelist
(\
@buffers_list);
307 weechat
::config_option_set
( weechat
::config_get
("buffers.look.whitelist_buffers"), $buffers_list, 1);
308 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" added to buffers whitelist");
310 elsif ( $args eq "del" )
312 return weechat
::WEECHAT_RC_OK
unless ( grep /^$buffers_name$/, @buffers_list ); # check if buffer is in list
313 @buffers_list = grep {$_ ne $buffers_name} @buffers_list; # delete entry
314 my $buffers_list = &create_whitelist
(\
@buffers_list);
315 weechat
::config_option_set
( weechat
::config_get
("buffers.look.whitelist_buffers"), $buffers_list, 1);
316 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" deleted from buffers whitelist");
318 elsif ( $args eq "reset" )
320 return weechat
::WEECHAT_RC_OK
if ( $buffers_whitelist eq "" );
321 weechat
::config_option_set
( weechat
::config_get
("buffers.look.whitelist_buffers"), "", 1);
322 weechat
::print(weechat
::current_buffer
(), "buffers whitelist is empty, now...");
324 return weechat
::WEECHAT_RC_OK
;
326 sub buffers_cmd_detach
328 my ( $data, $buffer, $args ) = @_;
330 my $immune_detach_buffers = weechat
::config_string
( weechat
::config_get
("buffers.look.immune_detach_buffers") );
331 return weechat
::WEECHAT_RC_OK
if ( $immune_detach_buffers eq "" and $args eq "del" or $immune_detach_buffers eq "" and $args eq "reset" );
333 my @buffers_list = split( /,/, $immune_detach_buffers );
335 my $infolist = weechat
::infolist_get
("buffer", weechat
::current_buffer
(), "");
336 weechat
::infolist_next
($infolist);
337 my $buffers_name = weechat
::infolist_string
($infolist, "name");
338 weechat
::infolist_free
($infolist);
339 return weechat
::WEECHAT_RC_OK
if ( $buffers_name eq "" ); # should never happen
341 if ( $args eq "add" )
343 return weechat
::WEECHAT_RC_OK
if ( grep /^$buffers_name$/, @buffers_list ); # check if buffer already in list
344 push @buffers_list, ( $buffers_name );
345 my $buffers_list = &create_whitelist
(\
@buffers_list);
346 weechat
::config_option_set
( weechat
::config_get
("buffers.look.immune_detach_buffers"), $buffers_list, 1);
347 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" added to immune detach buffers");
349 elsif ( $args eq "del" )
351 return weechat
::WEECHAT_RC_OK
unless ( grep /^$buffers_name$/, @buffers_list ); # check if buffer is in list
352 @buffers_list = grep {$_ ne $buffers_name} @buffers_list; # delete entry
353 my $buffers_list = &create_whitelist
(\
@buffers_list);
354 weechat
::config_option_set
( weechat
::config_get
("buffers.look.immune_detach_buffers"), $buffers_list, 1);
355 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" deleted from immune detach buffers");
357 elsif ( $args eq "reset" )
359 return weechat
::WEECHAT_RC_OK
if ( $immune_detach_buffers eq "" );
360 weechat
::config_option_set
( weechat
::config_get
("buffers.look.immune_detach_buffers"), "", 1);
361 weechat
::print(weechat
::current_buffer
(), "immune detach buffers is empty, now...");
363 return weechat
::WEECHAT_RC_OK
;
368 my @buffers_list = @{$_[0]};
369 my $buffers_list = "";
370 foreach (@buffers_list)
372 $buffers_list .= $_ .",";
376 return $buffers_list;
379 # -------------------------------- [ config ] --------------------------------
380 sub hook_timer_detach
385 weechat
::unhook
($Hooks{timer_detach
}) if $Hooks{timer_detach
};
386 $Hooks{timer_detach
} = "";
390 weechat
::unhook
($Hooks{timer_detach
}) if $Hooks{timer_detach
};
391 $Hooks{timer_detach
} = weechat
::hook_timer
( weechat
::config_integer
( $options{"detach"}) * 1000, 60, 0, "buffers_signal_hotlist", "");
393 weechat
::bar_item_update
($SCRIPT_NAME);
394 return weechat
::WEECHAT_RC_OK
;
402 weechat
::unhook
($Hooks{timer_lag
}) if $Hooks{timer_lag
};
403 $Hooks{timer_lag
} = "";
407 weechat
::unhook
($Hooks{timer_lag
}) if $Hooks{timer_lag
};
408 $Hooks{timer_lag
} = weechat
::hook_timer
( weechat
::config_integer
(weechat
::config_get
("irc.network.lag_refresh_interval")) * 1000, 0, 0, "buffers_signal_hotlist", "");
410 weechat
::bar_item_update
($SCRIPT_NAME);
411 return weechat
::WEECHAT_RC_OK
;
414 sub buffers_config_read
416 return weechat
::config_read
($buffers_config_file) if ($buffers_config_file ne "");
418 sub buffers_config_write
420 return weechat
::config_write
($buffers_config_file) if ($buffers_config_file ne "");
422 sub buffers_config_reload_cb
424 my ($data, $config_file) = ($_[0], $_[1]);
425 return weechat
::config_reload
($config_file)
427 sub buffers_config_init
429 $buffers_config_file = weechat
::config_new
($BUFFERS_CONFIG_FILE_NAME,
430 "buffers_config_reload_cb", "");
431 return if ($buffers_config_file eq "");
433 my %default_options_color =
434 ("color_current_fg" => [
435 "current_fg", "color",
436 "foreground color for current buffer",
437 "", 0, 0, "lightcyan", "lightcyan", 0,
438 "", "", "buffers_signal_config", "", "", ""
440 "color_current_bg" => [
441 "current_bg", "color",
442 "background color for current buffer",
443 "", 0, 0, "red", "red", 0,
444 "", "", "buffers_signal_config", "", "", ""
446 "color_default_fg" => [
447 "default_fg", "color",
448 "default foreground color for buffer name",
449 "", 0, 0, "default", "default", 0,
450 "", "", "buffers_signal_config", "", "", ""
452 "color_default_bg" => [
453 "default_bg", "color",
454 "default background color for buffer name",
455 "", 0, 0, "default", "default", 0,
456 "", "", "buffers_signal_config", "", "", ""
458 "color_hotlist_highlight_fg" => [
459 "hotlist_highlight_fg", "color",
460 "change foreground color of buffer name if a highlight messaged received",
461 "", 0, 0, "magenta", "magenta", 0,
462 "", "", "buffers_signal_config", "", "", ""
464 "color_hotlist_highlight_bg" => [
465 "hotlist_highlight_bg", "color",
466 "change background color of buffer name if a highlight messaged received",
467 "", 0, 0, "default", "default", 0,
468 "", "", "buffers_signal_config", "", "", ""
470 "color_hotlist_low_fg" => [
471 "hotlist_low_fg", "color",
472 "change foreground color of buffer name if a low message received",
473 "", 0, 0, "white", "white", 0,
474 "", "", "buffers_signal_config", "", "", ""
476 "color_hotlist_low_bg" => [
477 "hotlist_low_bg", "color",
478 "change background color of buffer name if a low message received",
479 "", 0, 0, "default", "default", 0,
480 "", "", "buffers_signal_config", "", "", ""
482 "color_hotlist_message_fg" => [
483 "hotlist_message_fg", "color",
484 "change foreground color of buffer name if a normal message received",
485 "", 0, 0, "yellow", "yellow", 0,
486 "", "", "buffers_signal_config", "", "", ""
488 "color_hotlist_message_bg" => [
489 "hotlist_message_bg", "color",
490 "change background color of buffer name if a normal message received",
491 "", 0, 0, "default", "default", 0,
492 "", "", "buffers_signal_config", "", "", ""
494 "color_hotlist_private_fg" => [
495 "hotlist_private_fg", "color",
496 "change foreground color of buffer name if a private message received",
497 "", 0, 0, "lightgreen", "lightgreen", 0,
498 "", "", "buffers_signal_config", "", "", ""
500 "color_hotlist_private_bg" => [
501 "hotlist_private_bg", "color",
502 "change background color of buffer name if a private message received",
503 "", 0, 0, "default", "default", 0,
504 "", "", "buffers_signal_config", "", "", ""
508 "color for buffer number",
509 "", 0, 0, "lightgreen", "lightgreen", 0,
510 "", "", "buffers_signal_config", "", "", ""
512 "color_number_char" => [
513 "number_char", "color",
514 "color for buffer number char",
515 "", 0, 0, "lightgreen", "lightgreen", 0,
516 "", "", "buffers_signal_config", "", "", ""
518 "color_whitelist_default_fg" => [
519 "whitelist_default_fg", "color",
520 "default foreground color for whitelist buffer name",
522 "", "", "buffers_signal_config", "", "", ""
524 "color_whitelist_default_bg" => [
525 "whitelist_default_bg", "color",
526 "default background color for whitelist buffer name",
528 "", "", "buffers_signal_config", "", "", ""
530 "color_whitelist_low_fg" => [
531 "whitelist_low_fg", "color",
532 "low color of whitelist buffer name",
534 "", "", "buffers_signal_config", "", "", ""
536 "color_whitelist_low_bg" => [
537 "whitelist_low_bg", "color",
538 "low color of whitelist buffer name",
540 "", "", "buffers_signal_config", "", "", ""
542 "color_whitelist_message_fg" => [
543 "whitelist_message_fg", "color",
544 "message color of whitelist buffer name",
546 "", "", "buffers_signal_config", "", "", ""
548 "color_whitelist_message_bg" => [
549 "whitelist_message_bg", "color",
550 "message color of whitelist buffer name",
552 "", "", "buffers_signal_config", "", "", ""
554 "color_whitelist_private_fg" => [
555 "whitelist_private_fg", "color",
556 "private color of whitelist buffer name",
558 "", "", "buffers_signal_config", "", "", ""
560 "color_whitelist_private_bg" => [
561 "whitelist_private_bg", "color",
562 "private color of whitelist buffer name",
564 "", "", "buffers_signal_config", "", "", ""
566 "color_whitelist_highlight_fg" => [
567 "whitelist_highlight_fg", "color",
568 "highlight color of whitelist buffer name",
570 "", "", "buffers_signal_config", "", "", ""
572 "color_whitelist_highlight_bg" => [
573 "whitelist_highlight_bg", "color",
574 "highlight color of whitelist buffer name",
576 "", "", "buffers_signal_config", "", "", ""
578 "color_none_channel_fg" => [
579 "none_channel_fg", "color",
580 "foreground color for none channel buffer (e.g.: core/server/plugin ".
582 "", 0, 0, "default", "default", 0,
583 "", "", "buffers_signal_config", "", "", ""
585 "color_none_channel_bg" => [
586 "none_channel_bg", "color",
587 "background color for none channel buffer (e.g.: core/server/plugin ".
589 "", 0, 0, "default", "default", 0,
590 "", "", "buffers_signal_config", "", "", ""
592 "queries_default_fg" => [
593 "queries_default_fg", "color",
594 "foreground color for query buffer without message",
595 "", 0, 0, "default", "default", 0,
596 "", "", "buffers_signal_config", "", "", ""
598 "queries_default_bg" => [
599 "queries_default_bg", "color",
600 "background color for query buffer without message",
601 "", 0, 0, "default", "default", 0,
602 "", "", "buffers_signal_config", "", "", ""
604 "queries_message_fg" => [
605 "queries_message_fg", "color",
606 "foreground color for query buffer with unread message",
607 "", 0, 0, "default", "default", 0,
608 "", "", "buffers_signal_config", "", "", ""
610 "queries_message_bg" => [
611 "queries_message_bg", "color",
612 "background color for query buffer with unread message",
613 "", 0, 0, "default", "default", 0,
614 "", "", "buffers_signal_config", "", "", ""
616 "queries_highlight_fg" => [
617 "queries_highlight_fg", "color",
618 "foreground color for query buffer with unread highlight",
619 "", 0, 0, "default", "default", 0,
620 "", "", "buffers_signal_config", "", "", ""
622 "queries_highlight_bg" => [
623 "queries_highlight_bg", "color",
624 "background color for query buffer with unread highlight",
625 "", 0, 0, "default", "default", 0,
626 "", "", "buffers_signal_config", "", "", ""
628 "color_prefix_bufname" => [
629 "prefix_bufname", "color",
630 "color for prefix of buffer name",
631 "", 0, 0, "default", "default", 0,
632 "", "", "buffers_signal_config", "", "", ""
634 "color_suffix_bufname" => [
635 "suffix_bufname", "color",
636 "color for suffix of buffer name",
637 "", 0, 0, "default", "default", 0,
638 "", "", "buffers_signal_config", "", "", ""
642 my %default_options_look =
644 "hotlist_counter" => [
645 "hotlist_counter", "boolean",
646 "show number of message for the buffer (this option needs WeeChat >= ".
647 "0.3.5). The relevant option for notification is \"weechat.look.".
648 "buffer_notify_default\"",
649 "", 0, 0, "off", "off", 0,
650 "", "", "buffers_signal_config", "", "", ""
653 "show_lag", "boolean",
654 "show lag behind server name. This option is using \"irc.color.".
655 "item_lag_finished\", ".
656 "\"irc.network.lag_min_show\" and \"irc.network.lag_refresh_interval\"",
657 "", 0, 0, "off", "off", 0,
658 "", "", "buffers_signal_config", "", "", ""
660 "look_whitelist_buffers" => [
661 "whitelist_buffers", "string",
662 "comma separated list of buffers for using a different color scheme ".
663 "(for example: freenode.#weechat,freenode.#weechat-fr)",
665 "", "", "buffers_signal_config_whitelist", "", "", ""
667 "hide_merged_buffers" => [
668 "hide_merged_buffers", "integer",
669 "hide merged buffers. The value determines which merged buffers should ".
670 "be hidden, keepserver meaning 'all except server buffers'. Other values ".
671 "correspondent to the buffer type.",
672 "server|channel|private|keepserver|all|none", 0, 0, "none", "none", 0,
673 "", "", "buffers_signal_config", "", "", ""
676 "indenting", "integer", "use indenting for channel and query buffers. ".
677 "This option only takes effect if bar is left/right positioned",
678 "off|on|under_name", 0, 0, "off", "off", 0,
679 "", "", "buffers_signal_config", "", "", ""
681 "indenting_number" => [
682 "indenting_number", "boolean",
683 "use indenting for numbers. This option only takes effect if bar is ".
684 "left/right positioned",
685 "", 0, 0, "on", "on", 0,
686 "", "", "buffers_signal_config", "", "", ""
688 "indenting_amount" => [
689 "indenting_amount", "integer",
690 "amount of indenting to use. This option only takes effect if bar ".
691 "is left/right positioned, and indenting is enabled",
693 "", "", "buffers_signal_config", "", "", ""
696 "short_names", "boolean",
697 "display short names (remove text before first \".\" in buffer name)",
698 "", 0, 0, "on", "on", 0,
699 "", "", "buffers_signal_config", "", "", ""
702 "show_number", "boolean",
703 "display buffer number in front of buffer name",
704 "", 0, 0, "on", "on", 0,
705 "", "", "buffers_signal_config", "", "", ""
707 "show_number_char" => [
708 "number_char", "string",
709 "display a char behind buffer number",
710 "", 0, 0, ".", ".", 0,
711 "", "", "buffers_signal_config", "", "", ""
713 "show_prefix_bufname" => [
714 "prefix_bufname", "string",
715 "prefix displayed in front of buffer name",
717 "", "", "buffers_signal_config", "", "", ""
719 "show_suffix_bufname" => [
720 "suffix_bufname", "string",
721 "suffix displayed at end of buffer name",
723 "", "", "buffers_signal_config", "", "", ""
727 "displays your prefix for channel in front of buffer name",
728 "", 0, 0, "off", "off", 0,
729 "", "", "buffers_signal_config", "", "", ""
731 "show_prefix_empty" => [
732 "prefix_empty", "boolean",
733 "use a placeholder for channels without prefix",
734 "", 0, 0, "on", "on", 0,
735 "", "", "buffers_signal_config", "", "", ""
737 "show_prefix_query" => [
738 "prefix_for_query", "string",
739 "prefix displayed in front of query buffer",
741 "", "", "buffers_signal_config", "", "", ""
745 "sort buffer-list by \"number\" or \"name\"",
746 "number|name", 0, 0, "number", "number", 0,
747 "", "", "buffers_signal_config", "", "", ""
750 "core_to_front", "boolean",
751 "core buffer and buffers with free content will be listed first. ".
752 "Take only effect if buffer sort is by name",
753 "", 0, 0, "off", "off", 0,
754 "", "", "buffers_signal_config", "", "", ""
756 "jump_prev_next_visited_buffer" => [
757 "jump_prev_next_visited_buffer", "boolean",
758 "jump to previously or next visited buffer if you click with ".
759 "left/right mouse button on currently visiting buffer",
760 "", 0, 0, "off", "off", 0,
761 "", "", "buffers_signal_config", "", "", ""
764 "name_size_max", "integer",
765 "maximum size of buffer name. 0 means no limitation",
767 "", "", "buffers_signal_config", "", "", ""
769 "name_crop_suffix" => [
770 "name_crop_suffix", "string",
771 "contains an optional char(s) that is appended when buffer name is ".
773 "", 0, 0, "+", "+", 0,
774 "", "", "buffers_signal_config", "", "", ""
778 "detach buffer from buffers list after a specific period of time ".
779 "(in seconds) without action (weechat ≥ 0.3.8 required) (0 means \"off\")",
780 "", 0, 31536000, 0, "number", 0,
781 "", "", "buffers_signal_config", "", "", ""
783 "immune_detach_buffers" => [
784 "immune_detach_buffers", "string",
785 "comma separated list of buffers to NOT automatically detach. ".
786 "Allows \"*\" wildcard. Ex: \"BitlBee,freenode.*\"",
788 "", "", "buffers_signal_config_immune_detach_buffers", "", "", ""
791 "detach_query", "boolean",
792 "query buffer will be detached",
793 "", 0, 0, "off", "off", 0,
794 "", "", "buffers_signal_config", "", "", ""
796 "detach_buffer_immediately" => [
797 "detach_buffer_immediately", "string",
798 "comma separated list of buffers to detach immediately. Buffers ".
799 "will attach again based on notify level set in ".
800 "\"detach_buffer_immediately_level\". Allows \"*\" wildcard. ".
801 "Ex: \"BitlBee,freenode.*\"",
803 "", "", "buffers_signal_config_detach_buffer_immediately", "", "", ""
805 "detach_buffer_immediately_level" => [
806 "detach_buffer_immediately_level", "integer",
807 "The value determines what notify level messages are reattached from activity. ".
808 " This option works in conjunction with \"detach_buffer_immediately\" ".
809 "0: low priority (like join/part messages), ".
814 "", "", "buffers_signal_config", "", "", ""
816 "detach_free_content" => [
817 "detach_free_content", "boolean",
818 "buffers with free content will be detached (Ex: iset, chanmon)",
819 "", 0, 0, "off", "off", 0,
820 "", "", "buffers_signal_config", "", "", ""
822 "detach_displayed_buffers" => [
823 "detach_displayed_buffers", "boolean",
824 "buffers displayed in a (split) window will be detached",
825 "", 0, 0, "on", "on", 0,
826 "", "", "buffers_signal_config", "", "", ""
828 "detach_display_window_number" => [
829 "detach_display_window_number", "boolean",
830 "window number will be add, behind buffer name (this option takes only ".
831 "effect with \"detach_displayed_buffers\" option)",
832 "", 0, 0, "off", "off", 0,
833 "", "", "buffers_signal_config", "", "", ""
836 "mark_inactive", "boolean",
837 "if option is \"on\", inactive buffers (those you are not in) will have ".
838 "parentheses around them. An inactive buffer will not be detached.",
839 "", 0, 0, "off", "off", 0,
840 "", "", "buffers_signal_config", "", "", ""
843 "toggle_bar", "boolean",
844 "if option is \"on\", buffers bar will hide/show when script is ".
846 "", 0, 0, "on", "on", 0,
847 "", "", "buffers_signal_config", "", "", ""
849 "mouse_move_buffer" => [
850 "mouse_move_buffer", "boolean",
851 "if option is \"on\", mouse gestures (drag & drop) can move buffers in list.",
852 "", 0, 0, "on", "on", 0,
853 "", "", "buffers_signal_config", "", "", ""
856 "mouse_wheel", "boolean",
857 "if option is \"on\", mouse wheel jumps to previous/next buffer in list.",
858 "", 0, 0, "on", "on", 0,
859 "", "", "buffers_signal_config", "", "", ""
863 my $section_color = weechat
::config_new_section
(
864 $buffers_config_file,
865 "color", 0, 0, "", "", "", "", "", "", "", "", "", "");
866 if ($section_color eq "")
868 weechat
::config_free
($buffers_config_file);
871 foreach my $option (keys %default_options_color)
873 $options{$option} = weechat
::config_new_option
(
874 $buffers_config_file,
876 $default_options_color{$option}[0],
877 $default_options_color{$option}[1],
878 $default_options_color{$option}[2],
879 $default_options_color{$option}[3],
880 $default_options_color{$option}[4],
881 $default_options_color{$option}[5],
882 $default_options_color{$option}[6],
883 $default_options_color{$option}[7],
884 $default_options_color{$option}[8],
885 $default_options_color{$option}[9],
886 $default_options_color{$option}[10],
887 $default_options_color{$option}[11],
888 $default_options_color{$option}[12],
889 $default_options_color{$option}[13],
890 $default_options_color{$option}[14]);
894 my $section_look = weechat
::config_new_section
(
895 $buffers_config_file,
896 "look", 0, 0, "", "", "", "", "", "", "", "", "", "");
897 if ($section_look eq "")
899 weechat
::config_free
($buffers_config_file);
902 foreach my $option (keys %default_options_look)
904 $options{$option} = weechat
::config_new_option
(
905 $buffers_config_file,
907 $default_options_look{$option}[0],
908 $default_options_look{$option}[1],
909 $default_options_look{$option}[2],
910 $default_options_look{$option}[3],
911 $default_options_look{$option}[4],
912 $default_options_look{$option}[5],
913 $default_options_look{$option}[6],
914 $default_options_look{$option}[7],
915 $default_options_look{$option}[8],
916 $default_options_look{$option}[9],
917 $default_options_look{$option}[10],
918 $default_options_look{$option}[11],
919 $default_options_look{$option}[12],
920 $default_options_look{$option}[13],
921 $default_options_look{$option}[14],
922 $default_options_look{$option}[15]);
930 # get bar position (left/right/top/bottom)
931 my $position = "left";
932 my $option_position = weechat
::config_get
("weechat.bar.buffers.position");
933 if ($option_position ne "")
935 $position = weechat
::config_string
($option_position);
940 my $infolist = weechat
::infolist_get
("hotlist", "", "");
941 while (weechat
::infolist_next
($infolist))
943 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")} =
944 weechat
::infolist_integer
($infolist, "priority");
945 if ( weechat
::config_boolean
( $options{"hotlist_counter"} ) eq 1 and $weechat_version >= 0x00030500)
947 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")."_count_00"} =
948 weechat
::infolist_integer
($infolist, "count_00"); # low message
949 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")."_count_01"} =
950 weechat
::infolist_integer
($infolist, "count_01"); # channel message
951 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")."_count_02"} =
952 weechat
::infolist_integer
($infolist, "count_02"); # private message
953 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")."_count_03"} =
954 weechat
::infolist_integer
($infolist, "count_03"); # highlight message
957 weechat
::infolist_free
($infolist);
966 my $max_number_digits = 0;
968 $infolist = weechat
::infolist_get
("buffer", "", "");
969 while (weechat
::infolist_next
($infolist))
971 # ignore hidden buffers (WeeChat >= 0.4.4)
972 if ($weechat_version >= 0x00040400)
974 next if (weechat
::infolist_integer
($infolist, "hidden"));
977 my $number = weechat
::infolist_integer
($infolist, "number");
978 if ($number ne $old_number)
980 @buffers = (@buffers, @current2, @current1);
985 if ($number > $max_number)
987 $max_number = $number;
989 $old_number = $number;
990 my $active = weechat
::infolist_integer
($infolist, "active");
995 $buffer->{"pointer"} = weechat
::infolist_pointer
($infolist, "pointer");
996 $buffer->{"number"} = $number;
997 $buffer->{"active"} = $active;
998 $buffer->{"current_buffer"} = weechat
::infolist_integer
($infolist, "current_buffer");
999 $buffer->{"num_displayed"} = weechat
::infolist_integer
($infolist, "num_displayed");
1000 $buffer->{"plugin_name"} = weechat
::infolist_string
($infolist, "plugin_name");
1001 $buffer->{"name"} = weechat
::infolist_string
($infolist, "name");
1002 $buffer->{"short_name"} = weechat
::infolist_string
($infolist, "short_name");
1003 $buffer->{"full_name"} = $buffer->{"plugin_name"}.".".$buffer->{"name"};
1004 $buffer->{"type"} = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type");
1005 #weechat::print("", $buffer->{"type"});
1007 # check if buffer is active (or maybe a /part, /kick channel)
1008 if ($buffer->{"type"} eq "channel" and weechat
::config_boolean
( $options{"mark_inactive"} ) eq 1)
1010 my $server = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_server");
1011 my $channel = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_channel");
1012 my $infolist_channel = weechat
::infolist_get
("irc_channel", "", $server.",".$channel);
1013 if ($infolist_channel)
1015 weechat
::infolist_next
($infolist_channel);
1016 $buffer->{"nicks_count"} = weechat
::infolist_integer
($infolist_channel, "nicks_count");
1019 $buffer->{"nicks_count"} = 0;
1021 weechat
::infolist_free
($infolist_channel);
1024 my $result = check_immune_detached_buffers
($buffer->{"name"}); # checking for wildcard
1025 my $maxlevel = weechat
::config_integer
($options{"detach_buffer_immediately_level"});
1026 next if ( check_detach_buffer_immediately
($buffer->{"name"}) eq 1
1027 and $buffer->{"current_buffer"} eq 0
1028 and ( not exists $hotlist{$buffer->{"pointer"}} or $hotlist{$buffer->{"pointer"}} < $maxlevel) ); # checking for buffer to immediately detach
1032 my $detach_time = weechat
::config_integer
( $options{"detach"});
1033 my $current_time = time();
1034 # set timer for buffers with no hotlist action
1035 $buffers_timer{$buffer->{"pointer"}} = $current_time
1036 if ( not exists $hotlist{$buffer->{"pointer"}}
1037 and $buffer->{"type"} eq "channel"
1038 and not exists $buffers_timer{$buffer->{"pointer"}}
1039 and $detach_time > 0);
1041 $buffers_timer{$buffer->{"pointer"}} = $current_time
1042 if (weechat
::config_boolean
($options{"detach_query"}) eq 1
1043 and not exists $hotlist{$buffer->{"pointer"}}
1044 and $buffer->{"type"} eq "private"
1045 and not exists $buffers_timer{$buffer->{"pointer"}}
1046 and $detach_time > 0);
1049 if (weechat
::config_boolean
($options{"detach_query"}) eq 0
1050 and $buffer->{"type"} eq "private");
1052 # free content buffer
1053 $buffers_timer{$buffer->{"pointer"}} = $current_time
1054 if (weechat
::config_boolean
($options{"detach_free_content"}) eq 1
1055 and not exists $hotlist{$buffer->{"pointer"}}
1056 and $buffer->{"type"} eq ""
1057 and not exists $buffers_timer{$buffer->{"pointer"}}
1058 and $detach_time > 0);
1060 if (weechat
::config_boolean
($options{"detach_free_content"}) eq 0
1061 and $buffer->{"type"} eq "");
1063 $detach_time = 0 if (weechat
::config_boolean
($options{"mark_inactive"}) eq 1 and defined $buffer->{"nicks_count"} and $buffer->{"nicks_count"} == 0);
1066 unless ( $buffer->{"current_buffer"} eq 0
1067 and not exists $hotlist{$buffer->{"pointer"}}
1068 # and $buffer->{"type"} eq "channel"
1069 and exists $buffers_timer{$buffer->{"pointer"}}
1070 and $detach_time > 0
1071 and $weechat_version >= 0x00030800
1072 and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
1076 push(@current2, $buffer);
1080 push(@current1, $buffer);
1083 elsif ( $buffer->{"current_buffer"} eq 0
1084 and not exists $hotlist{$buffer->{"pointer"}}
1085 # and $buffer->{"type"} eq "channel"
1086 and exists $buffers_timer{$buffer->{"pointer"}}
1087 and $detach_time > 0
1088 and $weechat_version >= 0x00030800
1089 and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time)
1090 { # check for option detach_displayed_buffers and if buffer is displayed in a split window
1091 if ( $buffer->{"num_displayed"} eq 1
1092 and weechat
::config_boolean
($options{"detach_displayed_buffers"}) eq 0 )
1094 my $infolist_window = weechat
::infolist_get
("window", "", "");
1095 while (weechat
::infolist_next
($infolist_window))
1097 my $buffer_ptr = weechat
::infolist_pointer
($infolist_window, "buffer");
1098 if ($buffer_ptr eq $buffer->{"pointer"})
1100 $buffer->{"window"} = weechat
::infolist_integer
($infolist_window, "number");
1103 weechat
::infolist_free
($infolist_window);
1105 push(@current2, $buffer);
1109 else # buffer in "immune_detach_buffers"
1113 push(@current2, $buffer);
1117 push(@current1, $buffer);
1123 if ($max_number >= 1)
1125 $max_number_digits = length(int($max_number));
1127 @buffers = (@buffers, @current2, @current1);
1128 weechat
::infolist_free
($infolist);
1130 # sort buffers by number, name or shortname
1135 for my $buffer (@buffers)
1138 if (weechat
::config_integer
( $options{"sort"} ) eq 1) # number = 0; name = 1
1140 my $name = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_custom_name");
1141 if (not defined $name or $name eq "") {
1142 if (weechat
::config_boolean
( $options{"short_names"} ) eq 1) {
1143 $name = $buffer->{"short_name"};
1145 $name = $buffer->{"name"};
1148 if (weechat
::config_integer
($options{"name_size_max"}) >= 1)
1150 $maxlength = weechat
::config_integer
($options{"name_size_max"});
1151 if($buffer->{"type"} eq "channel" and weechat
::config_boolean
( $options{"mark_inactive"} ) eq 1 and $buffer->{"nicks_count"} == 0)
1155 $name = encode
("UTF-8", substr(decode
("UTF-8", $name), 0, $maxlength));
1157 if ( weechat
::config_boolean
($options{"core_to_front"}) eq 1)
1159 if ( (weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "private") )
1161 my $type = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type");
1162 if ( $type eq "" and $name ne "weechat")
1167 $name = " " . $name;
1171 $key = sprintf("%s%08d", lc($name), $buffer->{"number"});
1175 $key = sprintf("%08d", $number);
1177 $sorted_buffers{$key} = $buffer;
1182 # build string with buffers
1184 foreach my $key (sort keys %sorted_buffers)
1186 my $buffer = $sorted_buffers{$key};
1188 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "server" )
1190 # buffer type "server" or merged with core?
1191 if ( ($buffer->{"type"} eq "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1196 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "channel" )
1198 # buffer type "channel" or merged with core?
1199 if ( ($buffer->{"type"} eq "channel" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1204 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "private" )
1206 # buffer type "private" or merged with core?
1207 if ( ($buffer->{"type"} eq "private" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1212 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "keepserver" )
1214 if ( ($buffer->{"type"} ne "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
1219 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "all" )
1221 if ( ! $buffer->{"active"} )
1227 push(@buffers_focus, $buffer); # buffer > buffers_focus, for mouse support
1231 $color = weechat
::config_color
( $options{"color_default_fg"} );
1232 $bg = weechat
::config_color
( $options{"color_default_bg"} );
1234 if ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") eq "private" )
1236 if ( (weechat
::config_color
($options{"queries_default_bg"})) ne "default" || (weechat
::config_color
($options{"queries_default_fg"})) ne "default" )
1238 $bg = weechat
::config_color
( $options{"queries_default_bg"} );
1239 $color = weechat
::config_color
( $options{"queries_default_fg"} );
1242 # check for core and buffer with free content
1243 if ( (weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "private") )
1245 $color = weechat
::config_color
( $options{"color_none_channel_fg"} );
1246 $bg = weechat
::config_color
( $options{"color_none_channel_bg"} );
1248 # default whitelist buffer?
1249 if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
1251 $color = weechat
::config_color
( $options{"color_whitelist_default_fg"} );
1252 $bg = weechat
::config_color
( $options{"color_whitelist_default_bg"} );
1255 $color = "default" if ($color eq "");
1257 # color for channel and query buffer
1258 if (exists $hotlist{$buffer->{"pointer"}})
1260 delete $buffers_timer{$buffer->{"pointer"}};
1261 # check if buffer is in whitelist buffer
1262 if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
1264 $bg = weechat
::config_color
( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
1265 $color = weechat
::config_color
( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
1267 elsif ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") eq "private" )
1269 # queries_default_fg/bg and buffers.color.queries_message_fg/bg
1270 if ( (weechat
::config_color
($options{"queries_highlight_fg"})) ne "default" ||
1271 (weechat
::config_color
($options{"queries_highlight_bg"})) ne "default" ||
1272 (weechat
::config_color
($options{"queries_message_fg"})) ne "default" ||
1273 (weechat
::config_color
($options{"queries_message_bg"})) ne "default" )
1275 if ( ($hotlist{$buffer->{"pointer"}}) == 2 )
1277 $bg = weechat
::config_color
( $options{"queries_message_bg"} );
1278 $color = weechat
::config_color
( $options{"queries_message_fg"} );
1281 elsif ( ($hotlist{$buffer->{"pointer"}}) == 3 )
1283 $bg = weechat
::config_color
( $options{"queries_highlight_bg"} );
1284 $color = weechat
::config_color
( $options{"queries_highlight_fg"} );
1288 $bg = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
1289 $color = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
1293 $bg = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
1294 $color = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
1298 if ($buffer->{"current_buffer"})
1300 $color = weechat
::config_color
( $options{"color_current_fg"} );
1301 $bg = weechat
::config_color
( $options{"color_current_bg"} );
1304 $color_bg = weechat
::color
(",".$bg) if ($bg ne "");
1306 # create channel number for output
1307 if ( weechat
::config_string
( $options{"show_prefix_bufname"} ) ne "" )
1310 weechat
::color
( weechat
::config_color
( $options{"color_prefix_bufname"} ) ).
1311 weechat
::config_string
( $options{"show_prefix_bufname"} ).
1312 weechat
::color
("default");
1315 if ( weechat
::config_boolean
( $options{"show_number"} ) eq 1 ) # on
1317 if (( weechat
::config_boolean
( $options{"indenting_number"} ) eq 1)
1318 && (($position eq "left") || ($position eq "right")))
1320 $str .= weechat
::color
("default").$color_bg
1321 .(" " x
($max_number_digits - length(int($buffer->{"number"}))));
1323 if ($old_number ne $buffer->{"number"})
1325 $str .= weechat
::color
( weechat
::config_color
( $options{"color_number"} ) )
1327 .$buffer->{"number"}
1328 .weechat
::color
("default")
1330 .weechat
::color
( weechat
::config_color
( $options{"color_number_char"} ) )
1331 .weechat
::config_string
( $options{"show_number_char"} )
1336 # Indentation aligns channels in a visually appealing way
1337 # when viewing list top-to-bottom...
1338 my $indent = (" " x
length($buffer->{"number"}))." ";
1339 # ...except when list is top/bottom and channels left-to-right.
1340 my $option_pos = weechat
::config_string
( weechat
::config_get
( "weechat.bar.buffers.position" ) );
1341 if (($option_pos eq 'top') || ($option_pos eq 'bottom')) {
1342 my $option_filling = weechat
::config_string
( weechat
::config_get
( "weechat.bar.buffers.filling_top_bottom" ) );
1343 if ($option_filling =~ /horizontal/) {
1347 $str .= weechat
::color
("default")
1353 if (( weechat
::config_integer
( $options{"indenting"} ) ne 0 ) # indenting NOT off
1354 && (($position eq "left") || ($position eq "right")))
1356 my $type = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type");
1357 if (($type eq "channel") || ($type eq "private"))
1359 if ( weechat
::config_integer
( $options{"indenting"} ) eq 1 )
1361 $str .= (" " x weechat
::config_integer
( $options{"indenting_amount"} ) );
1363 elsif ( (weechat
::config_integer
($options{"indenting"}) eq 2) and (weechat
::config_integer
($options{"indenting_number"}) eq 0) ) #under_name
1365 if ( weechat
::config_boolean
( $options{"show_number"} ) eq 0 )
1367 $str .= (" " x weechat
::config_integer
( $options{"indenting_amount"} ) );
1371 $str .= ( (" " x
( $max_number_digits - length($buffer->{"number"}) )).(" " x weechat
::config_integer
( $options{"indenting_amount"} ) ) );
1377 $str .= weechat
::config_string
( $options{"show_prefix_query"}) if (weechat
::config_string
( $options{"show_prefix_query"} ) ne "" and $buffer->{"type"} eq "private");
1379 if (weechat
::config_boolean
( $options{"show_prefix"} ) eq 1)
1381 my $nickname = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_nick");
1382 if ($nickname ne "")
1384 # with version >= 0.3.2, this infolist will return only nick
1385 # with older versions, whole nicklist is returned for buffer, and this can be very slow
1386 my $infolist_nick = weechat
::infolist_get
("nicklist", $buffer->{"pointer"}, "nick_".$nickname);
1387 if ($infolist_nick ne "")
1389 while (weechat
::infolist_next
($infolist_nick))
1391 if ((weechat
::infolist_string
($infolist_nick, "type") eq "nick")
1392 && (weechat
::infolist_string
($infolist_nick, "name") eq $nickname))
1394 my $prefix = weechat
::infolist_string
($infolist_nick, "prefix");
1395 if (($prefix ne " ") or (weechat
::config_boolean
( $options{"show_prefix_empty"} ) eq 1))
1397 # with version >= 0.3.5, it is now a color name (for older versions: option name with color)
1398 if (int($weechat_version) >= 0x00030500)
1400 $str .= weechat
::color
(weechat
::infolist_string
($infolist_nick, "prefix_color"));
1404 $str .= weechat
::color
(weechat
::config_color
(
1405 weechat
::config_get
(
1406 weechat
::infolist_string
($infolist_nick, "prefix_color"))));
1413 weechat
::infolist_free
($infolist_nick);
1417 if ($buffer->{"type"} eq "channel" and weechat
::config_boolean
( $options{"mark_inactive"} ) eq 1 and $buffer->{"nicks_count"} == 0)
1422 $str .= weechat
::color
($color) . weechat
::color
(",".$bg);
1424 my $name = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_custom_name");
1425 if (not defined $name or $name eq "")
1427 if (weechat
::config_boolean
( $options{"short_names"} ) eq 1) {
1428 $name = $buffer->{"short_name"};
1430 $name = $buffer->{"name"};
1434 if (weechat
::config_integer
($options{"name_size_max"}) >= 1) # check max_size of buffer name
1436 $name = decode
("UTF-8", $name);
1438 $maxlength = weechat
::config_integer
($options{"name_size_max"});
1439 if($buffer->{"type"} eq "channel" and weechat
::config_boolean
( $options{"mark_inactive"} ) eq 1 and $buffer->{"nicks_count"} == 0)
1444 $str .= encode
("UTF-8", substr($name, 0, $maxlength));
1445 $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"}));
1446 $str .= add_inactive_parentless
($buffer->{"type"}, $buffer->{"nicks_count"});
1447 $str .= add_hotlist_count
($buffer->{"pointer"}, %hotlist);
1452 $str .= add_inactive_parentless
($buffer->{"type"}, $buffer->{"nicks_count"});
1453 $str .= add_hotlist_count
($buffer->{"pointer"}, %hotlist);
1456 if ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") eq "server" and weechat
::config_boolean
($options{"show_lag"}) eq 1)
1458 my $color_lag = weechat
::config_color
(weechat
::config_get
("irc.color.item_lag_finished"));
1459 my $min_lag = weechat
::config_integer
(weechat
::config_get
("irc.network.lag_min_show"));
1460 my $infolist_server = weechat
::infolist_get
("irc_server", "", $buffer->{"short_name"});
1461 weechat
::infolist_next
($infolist_server);
1462 my $lag = (weechat
::infolist_integer
($infolist_server, "lag"));
1463 weechat
::infolist_free
($infolist_server);
1464 if ( int($lag) > int($min_lag) )
1467 $str .= weechat
::color
("default") . " (" . weechat
::color
($color_lag) . $lag . weechat
::color
("default") . ")";
1470 if (weechat
::config_boolean
($options{"detach_displayed_buffers"}) eq 0
1471 and weechat
::config_boolean
($options{"detach_display_window_number"}) eq 1)
1473 if ($buffer->{"window"})
1475 $str .= weechat
::color
("default") . " (" . weechat
::color
(weechat
::config_color
( $options{"color_number"})) . $buffer->{"window"} . weechat
::color
("default") . ")";
1478 $str .= weechat
::color
("default");
1480 if ( weechat
::config_string
( $options{"show_suffix_bufname"} ) ne "" )
1482 $str .= weechat
::color
( weechat
::config_color
( $options{"color_suffix_bufname"} ) ).
1483 weechat
::config_string
( $options{"show_suffix_bufname"} ).
1484 weechat
::color
("default");
1488 $old_number = $buffer->{"number"};
1491 # remove spaces and/or linefeed at the end
1497 sub add_inactive_parentless
1499 my ($buf_type, $buf_nicks_count) = @_;
1501 if ($buf_type eq "channel" and weechat
::config_boolean
( $options{"mark_inactive"} ) eq 1 and $buf_nicks_count == 0)
1503 $str .= weechat
::color
(weechat
::config_color
( $options{"color_number_char"}));
1509 sub add_hotlist_count
1511 my ($bufpointer, %hotlist) = @_;
1513 return "" if ( weechat
::config_boolean
( $options{"hotlist_counter"} ) eq 0 or ($weechat_version < 0x00030500)); # off
1514 my $col_number_char = weechat
::color
(weechat
::config_color
( $options{"color_number_char"}) );
1515 my $str = " ".$col_number_char."(";
1518 if (defined $hotlist{$bufpointer."_count_00"})
1520 my $bg = weechat
::config_color
( $options{"color_hotlist_low_bg"} );
1521 my $color = weechat
::config_color
( $options{"color_hotlist_low_fg"} );
1522 $str .= weechat
::color
($bg).
1523 weechat
::color
($color).
1524 $hotlist{$bufpointer."_count_00"} if ($hotlist{$bufpointer."_count_00"} ne "0");
1528 if (defined $hotlist{$bufpointer."_count_01"})
1530 my $bg = weechat
::config_color
( $options{"color_hotlist_message_bg"} );
1531 my $color = weechat
::config_color
( $options{"color_hotlist_message_fg"} );
1532 if ($str =~ /[0-9]$/)
1535 weechat
::color
($bg).
1536 weechat
::color
($color).
1537 $hotlist{$bufpointer."_count_01"} if ($hotlist{$bufpointer."_count_01"} ne "0");
1540 $str .= weechat
::color
($bg).
1541 weechat
::color
($color).
1542 $hotlist{$bufpointer."_count_01"} if ($hotlist{$bufpointer."_count_01"} ne "0");
1546 if (defined $hotlist{$bufpointer."_count_02"})
1548 my $bg = weechat
::config_color
( $options{"color_hotlist_private_bg"} );
1549 my $color = weechat
::config_color
( $options{"color_hotlist_private_fg"} );
1550 if ($str =~ /[0-9]$/)
1553 weechat
::color
($bg).
1554 weechat
::color
($color).
1555 $hotlist{$bufpointer."_count_02"} if ($hotlist{$bufpointer."_count_02"} ne "0");
1558 $str .= weechat
::color
($bg).
1559 weechat
::color
($color).
1560 $hotlist{$bufpointer."_count_02"} if ($hotlist{$bufpointer."_count_02"} ne "0");
1564 if (defined $hotlist{$bufpointer."_count_03"})
1566 my $bg = weechat
::config_color
( $options{"color_hotlist_highlight_bg"} );
1567 my $color = weechat
::config_color
( $options{"color_hotlist_highlight_fg"} );
1568 if ($str =~ /[0-9]$/)
1571 weechat
::color
($bg).
1572 weechat
::color
($color).
1573 $hotlist{$bufpointer."_count_03"} if ($hotlist{$bufpointer."_count_03"} ne "0");
1576 $str .= weechat
::color
($bg).
1577 weechat
::color
($color).
1578 $hotlist{$bufpointer."_count_03"} if ($hotlist{$bufpointer."_count_03"} ne "0");
1581 $str .= $col_number_char. ")";
1583 $str = "" if (weechat
::string_remove_color
($str, "") eq " ()"); # remove color and check for buffer with no messages
1587 sub buffers_signal_buffer
1589 my ($data, $signal, $signal_data) = @_;
1591 # check for buffer_switch and set or remove detach time
1592 if ($weechat_version >= 0x00030800)
1594 if ($signal eq "buffer_switch")
1596 my $pointer = weechat
::hdata_get_list
(weechat
::hdata_get
("buffer"), "gui_buffer_last_displayed"); # get switched buffer
1597 my $current_time = time();
1598 if ( weechat
::buffer_get_string
($pointer, "localvar_type") eq "channel")
1600 $buffers_timer{$pointer} = $current_time;
1604 delete $buffers_timer{$pointer};
1607 if ($signal eq "buffer_opened")
1609 my $current_time = time();
1610 $buffers_timer{$signal_data} = $current_time;
1612 if ($signal eq "buffer_closing")
1614 delete $buffers_timer{$signal_data};
1617 weechat
::bar_item_update
($SCRIPT_NAME);
1618 return weechat
::WEECHAT_RC_OK
;
1621 sub buffers_signal_hotlist
1623 weechat
::bar_item_update
($SCRIPT_NAME);
1624 return weechat
::WEECHAT_RC_OK
;
1628 sub buffers_signal_config_whitelist
1630 @whitelist_buffers = ();
1631 @whitelist_buffers = split( /,/, weechat
::config_string
( $options{"look_whitelist_buffers"} ) );
1632 weechat
::bar_item_update
($SCRIPT_NAME);
1633 return weechat
::WEECHAT_RC_OK
;
1636 sub buffers_signal_config_immune_detach_buffers
1638 @immune_detach_buffers = ();
1639 @immune_detach_buffers = split( /,/, weechat
::config_string
( $options{"immune_detach_buffers"} ) );
1640 weechat
::bar_item_update
($SCRIPT_NAME);
1641 return weechat
::WEECHAT_RC_OK
;
1644 sub buffers_signal_config_detach_buffer_immediately
1646 @detach_buffer_immediately = ();
1647 @detach_buffer_immediately = split( /,/, weechat
::config_string
( $options{"detach_buffer_immediately"} ) );
1648 weechat
::bar_item_update
($SCRIPT_NAME);
1649 return weechat
::WEECHAT_RC_OK
;
1652 sub buffers_signal_config
1654 weechat
::bar_item_update
($SCRIPT_NAME);
1655 return weechat
::WEECHAT_RC_OK
;
1658 # called when mouse click occured in buffers item: this callback returns buffer
1659 # hash according to line of item where click occured
1660 sub buffers_focus_buffers
1662 my %info = %{$_[1]};
1663 my $item_line = int($info{"_bar_item_line"});
1665 if (($info{"_bar_item_name"} eq $SCRIPT_NAME) && ($item_line >= 0) && ($item_line <= $#buffers_focus))
1667 $hash = $buffers_focus[$item_line];
1672 my $hash_focus = $buffers_focus[0];
1673 foreach my $key (keys %$hash_focus)
1675 $hash->{$key} = "?";
1681 # called when a mouse action is done on buffers item, to execute action
1682 # possible actions: jump to a buffer or move buffer in list (drag & drop of buffer)
1683 sub buffers_hsignal_mouse
1685 my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
1686 my $current_buffer = weechat
::buffer_get_integer
(weechat
::current_buffer
(), "number"); # get current buffer number
1688 if ( $hash{"_key"} eq "button1" )
1691 if ($hash{"number"} eq $hash{"number2"})
1693 if ( weechat
::config_boolean
($options{"jump_prev_next_visited_buffer"}) )
1695 if ( $current_buffer eq $hash{"number"} )
1697 weechat
::command
("", "/input jump_previously_visited_buffer");
1701 weechat
::command
("", "/buffer ".$hash{"full_name"});
1706 weechat
::command
("", "/buffer ".$hash{"full_name"});
1711 move_buffer
(%hash) if (weechat
::config_boolean
($options{"mouse_move_buffer"}));
1714 elsif ( ($hash{"_key"} eq "button2") && (weechat
::config_boolean
($options{"jump_prev_next_visited_buffer"})) )
1716 # right mouse button
1717 if ( $current_buffer eq $hash{"number2"} )
1719 weechat
::command
("", "/input jump_next_visited_buffer");
1722 elsif ( $hash{"_key"} =~ /wheelup$/ )
1725 if (weechat
::config_boolean
($options{"mouse_wheel"}))
1727 weechat
::command
("", "/buffer -1");
1730 elsif ( $hash{"_key"} =~ /wheeldown$/ )
1733 if (weechat
::config_boolean
($options{"mouse_wheel"}))
1735 weechat
::command
("", "/buffer +1");
1740 my $infolist = weechat
::infolist_get
("hook", "", "command,menu");
1741 my $has_menu_command = weechat
::infolist_next
($infolist);
1742 weechat
::infolist_free
($infolist);
1744 if ( $has_menu_command && $hash{"_key"} =~ /button2/ )
1746 if ($hash{"number"} eq $hash{"number2"})
1748 weechat
::command
($hash{"pointer"}, "/menu buffer1 $hash{short_name} $hash{number}");
1752 weechat
::command
($hash{"pointer"}, "/menu buffer2 $hash{short_name}/$hash{short_name2} $hash{number} $hash{number2}")
1757 move_buffer
(%hash) if (weechat
::config_boolean
($options{"mouse_move_buffer"}));
1765 my $number2 = $hash{"number2"};
1766 if ($number2 eq "?")
1768 # if number 2 is not known (end of gesture outside buffers list), then set it
1769 # according to mouse gesture
1771 if (($hash{"_key"} =~ /gesture-right/) || ($hash{"_key"} =~ /gesture-down/))
1773 $number2 = "999999";
1774 if ($weechat_version >= 0x00030600)
1776 my $hdata_buffer = weechat
::hdata_get
("buffer");
1777 my $last_gui_buffer = weechat
::hdata_get_list
($hdata_buffer, "last_gui_buffer");
1778 if ($last_gui_buffer)
1780 $number2 = weechat
::hdata_integer
($hdata_buffer, $last_gui_buffer, "number") + 1;
1785 my $ptrbuf = weechat
::current_buffer
();
1786 weechat
::command
($hash{"pointer"}, "/buffer move ".$number2);
1789 sub check_immune_detached_buffers
1791 my ($buffername) = @_;
1792 foreach ( @immune_detach_buffers ){
1793 my $immune_buffer = weechat
::string_mask_to_regex
($_);
1794 if ($buffername =~ /^$immune_buffer$/i)
1802 sub check_detach_buffer_immediately
1804 my ($buffername) = @_;
1805 foreach ( @detach_buffer_immediately ){
1806 my $detach_buffer = weechat
::string_mask_to_regex
($_);
1807 if ($buffername =~ /^$detach_buffer$/i)
1817 weechat
::command
("", "/bar hide " . $SCRIPT_NAME) if ( weechat
::config_boolean
($options{"toggle_bar"}) eq 1 );
1818 return weechat
::WEECHAT_RC_OK
1824 my $infolist = weechat
::infolist_get
("bar", "", "");
1825 while (weechat
::infolist_next
($infolist))
1827 my $bar_items = weechat
::infolist_string
($infolist, "items");
1828 if (index($bar_items, $SCRIPT_NAME) != -1)
1830 my $name = weechat
::infolist_string
($infolist, "name");
1831 if ($name ne $SCRIPT_NAME)
1838 weechat
::infolist_free
($infolist);