2 # Copyright (C) 2008-2012 Sebastien Helleu <flashcode@flashtux.org>
3 # Copyright (C) 2011-2012 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 # 2012-06-02, nils_2 <weechatter@arcor.de>:
24 # v3.5: add values "server|channel|private|all|keepserver|none" to option "hide_merged_buffers" (suggested by dominikh).
25 # 2012-05-25, nils_2 <weechatter@arcor.de>:
26 # v3.4: add new option "show_lag".
27 # 2012-04-07, Sebastien Helleu <flashcode@flashtux.org>:
28 # v3.3: fix truncation of wide chars in buffer name (option name_size_max) (bug #36034)
29 # 2012-03-15, nils_2 <weechatter@arcor.de>:
30 # v3.2: add new option "detach"(weechat >= 0.3.8)
31 # add new option "immune_detach_buffers" (requested by Mkaysi)
32 # add new function buffers_whitelist add|del|reset (suggested by FiXato)
33 # add new function buffers_detach add|del|reset
34 # 2012-03-09, Sebastien Helleu <flashcode@flashtux.org>:
35 # v3.1: fix reload of config file
36 # 2012-01-29, nils_2 <weechatter@arcor.de>:
37 # v3.0: fix: buffers did not update directly during window_switch (reported by FiXato)
38 # 2012-01-29, nils_2 <weechatter@arcor.de>:
39 # v2.9: add options "name_size_max" and "name_crop_suffix"
40 # 2012-01-08, nils_2 <weechatter@arcor.de>:
41 # v2.8: fix indenting for option "show_number off"
42 # fix unset of buffer activity in hotlist when buffer was moved with mouse
43 # add buffer with free content and core buffer sorted first (suggested by nyuszika7h)
44 # add options queries_default_fg/bg and queries_message_fg/bg (suggested by FiXato)
45 # add clicking with left button on current buffer will do a jump_previously_visited_buffer (suggested by FiXato)
46 # add clicking with right button on current buffer will do a jump_next_visited_buffer
47 # add additional informations in help texts
48 # add default_fg and default_bg for whitelist channels
49 # internal changes (script is now 3Kb smaller)
50 # 2012-01-04, Sebastien Helleu <flashcode@flashtux.org>:
51 # v2.7: fix regex lookup in whitelist buffers list
52 # 2011-12-04, nils_2 <weechatter@arcor.de>:
53 # v2.6: add own config file (buffers.conf)
54 # add new behavior for indenting (under_name)
55 # add new option to set different color for server buffers and buffers with free content
56 # 2011-10-30, nils_2 <weechatter@arcor.de>:
57 # v2.5: add new options "show_number_char" and "color_number_char",
58 # add help-description for options
59 # 2011-08-24, Sebastien Helleu <flashcode@flashtux.org>:
60 # v2.4: add mouse support
61 # 2011-06-06, nils_2 <weechatter@arcor.de>:
62 # v2.3: added: missed option "color_whitelist_default"
63 # 2011-03-23, Sebastien Helleu <flashcode@flashtux.org>:
64 # v2.2: fix color of nick prefix with WeeChat >= 0.3.5
65 # 2011-02-13, nils_2 <weechatter@arcor.de>:
66 # v2.1: add options "color_whitelist_*"
67 # 2010-10-05, Sebastien Helleu <flashcode@flashtux.org>:
68 # v2.0: add options "sort" and "show_number"
69 # 2010-04-12, Sebastien Helleu <flashcode@flashtux.org>:
70 # v1.9: replace call to log() by length() to align buffer numbers
71 # 2010-04-02, Sebastien Helleu <flashcode@flashtux.org>:
72 # v1.8: fix bug with background color and option indenting_number
73 # 2010-04-02, Helios <helios@efemes.de>:
74 # v1.7: add indenting_number option
75 # 2010-02-25, m4v <lambdae2@gmail.com>:
76 # v1.6: add option to hide empty prefixes
77 # 2010-02-12, Sebastien Helleu <flashcode@flashtux.org>:
78 # v1.5: add optional nick prefix for buffers like IRC channels
79 # 2009-09-30, Sebastien Helleu <flashcode@flashtux.org>:
80 # v1.4: remove spaces for indenting when bar position is top/bottom
81 # 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
82 # v1.3: add option "hide_merged_buffers"
83 # 2009-06-14, Sebastien Helleu <flashcode@flashtux.org>:
84 # v1.2: improve display with merged buffers
85 # 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
86 # v1.1: sync with last API changes
87 # 2009-02-21, Sebastien Helleu <flashcode@flashtux.org>:
88 # v1.0: remove timer used to update bar item first time (not needed any more)
89 # 2009-02-17, Sebastien Helleu <flashcode@flashtux.org>:
90 # v0.9: fix bug with indenting of private buffers
91 # 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
92 # v0.8: update syntax for command /set (comments)
93 # 2008-10-20, Jiri Golembiovsky <golemj@gmail.com>:
94 # v0.7: add indenting option
95 # 2008-10-01, Sebastien Helleu <flashcode@flashtux.org>:
96 # v0.6: add default color for buffers, and color for current active buffer
97 # 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
98 # v0.5: fix color for "low" level entry in hotlist
99 # 2008-09-18, Sebastien Helleu <flashcode@flashtux.org>:
100 # v0.4: rename option "show_category" to "short_names",
101 # remove option "color_slash"
102 # 2008-09-15, Sebastien Helleu <flashcode@flashtux.org>:
103 # v0.3: fix bug with priority in hotlist (var not defined)
104 # 2008-09-02, Sebastien Helleu <flashcode@flashtux.org>:
105 # v0.2: add color for buffers with activity and config options for
106 # colors, add config option to display/hide categories
107 # 2008-03-15, Sebastien Helleu <flashcode@flashtux.org>:
108 # v0.1: script creation
110 # Help about settings:
111 # display all settings for script (or use iset.pl script to change settings):
113 # show help text for option buffers.look.whitelist_buffers:
114 # /help buffers.look.whitelist_buffers
116 # Mouse-support (standard key bindings):
118 # - click on a buffer to switch to selected buffer
119 # - click on current buffer will do action jump_previously_visited_buffer
120 # - drag a buffer and drop it on another position will move the buffer to position
121 # right mouse-button:
122 # - click on current buffer will do action jump_next_visited_buffer
123 # - moving buffer to the left/right will close buffer.
127 use Encode
qw( decode encode );
128 # -------------------------------[ internal ]-------------------------------------
131 my $BUFFERS_CONFIG_FILE_NAME = "buffers";
132 my $buffers_config_file;
133 my $cmd_buffers_whitelist= "buffers_whitelist";
134 my $cmd_buffers_detach = "buffers_detach";
136 my %mouse_keys = ("\@item(buffers):button1*" => "hsignal:buffers_mouse", # catch all left mouse button gestures
137 "\@item(buffers):button2" => "hsignal:buffers_mouse"); # catch right mouse button
139 my %hotlist_level = (0 => "low", 1 => "message", 2 => "private", 3 => "highlight");
140 my @whitelist_buffers = ();
141 my @immune_detach_buffers= ();
142 my @buffers_focus = ();
143 my %buffers_timer = ();
146 # --------------------------------[ init ]--------------------------------------
147 weechat
::register
("buffers", "Sebastien Helleu <flashcode\@flashtux.org>", $version,
148 "GPL3", "Sidebar with list of buffers", "", "");
149 my $weechat_version = weechat
::info_get
("version_number", "") || 0;
151 buffers_config_init
();
152 buffers_config_read
();
154 weechat
::bar_item_new
("buffers", "build_buffers", "");
155 weechat
::bar_new
("buffers", "0", "0", "root", "", "left", "horizontal",
156 "vertical", "0", "0", "default", "default", "default", "1",
158 weechat
::hook_signal
("buffer_*", "buffers_signal_buffer", "");
159 weechat
::hook_signal
("window_switch", "buffers_signal_buffer", "");
160 weechat
::hook_signal
("hotlist_*", "buffers_signal_hotlist", "");
161 weechat
::bar_item_update
("buffers");
162 if ($weechat_version >= 0x00030600)
164 weechat
::hook_focus
("buffers", "buffers_focus_buffers", "");
165 weechat
::hook_hsignal
("buffers_mouse", "buffers_hsignal_mouse", "");
166 weechat
::key_bind
("mouse", \
%mouse_keys);
169 weechat
::hook_command
( $cmd_buffers_whitelist,
170 "add/del current buffer to/from buffers whitelist",
171 "[add] || [del] || [reset]",
173 " add: add current buffer in configuration file\n".
174 " del: delete current buffer from configuration file\n".
175 "reset: reset all buffers from configuration file (no confirmation!)\n\n".
177 "/$cmd_buffers_whitelist add\n",
181 "buffers_cmd_whitelist", "");
183 weechat
::hook_command
( $cmd_buffers_detach,
184 "add/del current buffer to/from buffers detach",
185 "[add] || [del] || [reset]",
187 " add: add current buffer in configuration file\n".
188 " del: delete current buffer from configuration file\n".
189 "reset: reset all buffers from configuration file (no confirmation!)\n\n".
191 "/$cmd_buffers_detach add\n",
195 "buffers_cmd_detach", "");
197 if ($weechat_version >= 0x00030800)
199 weechat
::hook_config
("buffers.look.detach", "hook_timer_detach", "");
202 weechat
::hook_config
("buffers.look.show_lag", "hook_timer_lag", "");
204 # -------------------------------- [ command ] --------------------------------
205 sub buffers_cmd_whitelist
207 my ( $data, $buffer, $args ) = @_;
209 my $buffers_whitelist = weechat
::config_string
( weechat
::config_get
("buffers.look.whitelist_buffers") );
210 return weechat
::WEECHAT_RC_OK
if ( $buffers_whitelist eq "" and $args eq "del" or $buffers_whitelist eq "" and $args eq "reset" );
211 my @buffers_list = split( /,/, $buffers_whitelist );
213 my $infolist = weechat
::infolist_get
("buffer", weechat
::current_buffer
(), "");
214 weechat
::infolist_next
($infolist);
215 my $buffers_name = weechat
::infolist_string
($infolist, "name");
216 weechat
::infolist_free
($infolist);
217 return weechat
::WEECHAT_RC_OK
if ( $buffers_name eq "" ); # should never happen
219 if ( $args eq "add" )
221 return weechat
::WEECHAT_RC_OK
if ( grep /^$buffers_name$/, @buffers_list ); # check if buffer already in list
222 push @buffers_list,( $buffers_name );
223 my $buffers_list = &create_whitelist
(\
@buffers_list);
224 weechat
::config_option_set
( weechat
::config_get
("buffers.look.whitelist_buffers"), $buffers_list,1 );
225 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" added to buffers whitelist");
227 elsif ( $args eq "del" )
229 return weechat
::WEECHAT_RC_OK
unless ( grep /^$buffers_name$/, @buffers_list ); # check if buffer is in list
230 @buffers_list = grep {$_ ne $buffers_name} @buffers_list; # delete entry
231 my $buffers_list = &create_whitelist
(\
@buffers_list);
232 weechat
::config_option_set
( weechat
::config_get
("buffers.look.whitelist_buffers"), $buffers_list,1 );
233 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" deleted from buffers whitelist");
235 elsif ( $args eq "reset" )
237 return weechat
::WEECHAT_RC_OK
if ( $buffers_whitelist eq "" );
238 weechat
::config_option_set
( weechat
::config_get
("buffers.look.whitelist_buffers"), "",1 );
239 weechat
::print(weechat
::current_buffer
(), "buffers whitelist is empty, now...");
241 return weechat
::WEECHAT_RC_OK
;
243 sub buffers_cmd_detach
245 my ( $data, $buffer, $args ) = @_;
247 my $immune_detach_buffers = weechat
::config_string
( weechat
::config_get
("buffers.look.immune_detach_buffers") );
248 return weechat
::WEECHAT_RC_OK
if ( $immune_detach_buffers eq "" and $args eq "del" or $immune_detach_buffers eq "" and $args eq "reset" );
249 my @buffers_list = split( /,/, $immune_detach_buffers );
251 my $infolist = weechat
::infolist_get
("buffer", weechat
::current_buffer
(), "");
252 weechat
::infolist_next
($infolist);
253 my $buffers_name = weechat
::infolist_string
($infolist, "name");
254 weechat
::infolist_free
($infolist);
255 return weechat
::WEECHAT_RC_OK
if ( $buffers_name eq "" ); # should never happen
257 if ( $args eq "add" )
259 return weechat
::WEECHAT_RC_OK
if ( grep /^$buffers_name$/, @buffers_list ); # check if buffer already in list
260 push @buffers_list,( $buffers_name );
261 my $buffers_list = &create_whitelist
(\
@buffers_list);
262 weechat
::config_option_set
( weechat
::config_get
("buffers.look.immune_detach_buffers"), $buffers_list,1 );
263 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" added to immune detach buffers");
265 elsif ( $args eq "del" )
267 return weechat
::WEECHAT_RC_OK
unless ( grep /^$buffers_name$/, @buffers_list ); # check if buffer is in list
268 @buffers_list = grep {$_ ne $buffers_name} @buffers_list; # delete entry
269 my $buffers_list = &create_whitelist
(\
@buffers_list);
270 weechat
::config_option_set
( weechat
::config_get
("buffers.look.immune_detach_buffers"), $buffers_list,1 );
271 weechat
::print(weechat
::current_buffer
(), "buffer \"$buffers_name\" deleted from immune detach buffers");
273 elsif ( $args eq "reset" )
275 return weechat
::WEECHAT_RC_OK
if ( $immune_detach_buffers eq "" );
276 weechat
::config_option_set
( weechat
::config_get
("buffers.look.immune_detach_buffers"), "",1 );
277 weechat
::print(weechat
::current_buffer
(), "immune detach buffers is empty, now...");
279 return weechat
::WEECHAT_RC_OK
;
283 my @buffers_list = @{$_[0]};
284 my $buffers_list = "";
285 foreach (@buffers_list)
287 $buffers_list .= $_ .",";
289 chop $buffers_list; # remove last ","
290 return $buffers_list;
293 # -------------------------------- [ config ] --------------------------------
294 sub hook_timer_detach
299 weechat
::unhook
($Hooks{timer_detach
}) if $Hooks{timer_detach
};
300 $Hooks{timer_detach
} = "";
304 weechat
::unhook
($Hooks{timer_detach
}) if $Hooks{timer_detach
};
305 $Hooks{timer_detach
} = weechat
::hook_timer
( weechat
::config_integer
( $options{"detach"}) * 1000, 60, 0, "buffers_signal_buffer", "");
307 weechat
::bar_item_update
("buffers");
308 return weechat
::WEECHAT_RC_OK
;
316 weechat
::unhook
($Hooks{timer_lag
}) if $Hooks{timer_lag
};
317 $Hooks{timer_lag
} = "";
321 weechat
::unhook
($Hooks{timer_lag
}) if $Hooks{timer_lag
};
322 $Hooks{timer_lag
} = weechat
::hook_timer
( weechat
::config_integer
(weechat
::config_get
("irc.network.lag_refresh_interval")) * 1000, 0, 0, "buffers_signal_hotlist", "");
324 weechat
::bar_item_update
("buffers");
325 return weechat
::WEECHAT_RC_OK
;
328 sub buffers_config_read
330 return weechat
::config_read
($buffers_config_file) if ($buffers_config_file ne "");
332 sub buffers_config_write
334 return weechat
::config_write
($buffers_config_file) if ($buffers_config_file ne "");
336 sub buffers_config_reload_cb
338 my ($data,$config_file) = ($_[0], $_[1]);
339 return weechat
::config_reload
($config_file)
341 sub buffers_config_init
343 $buffers_config_file = weechat
::config_new
($BUFFERS_CONFIG_FILE_NAME,"buffers_config_reload_cb","");
344 return if ($buffers_config_file eq "");
346 my %default_options_color =
347 ("color_current_fg" => ["current_fg", "color", "foreground color for current buffer", "", 0, 0,"lightcyan", "lightcyan", 0, "", "","buffers_signal_config", "", "", ""],
348 "color_current_bg" => ["current_bg", "color", "background color for current buffer", "", 0, 0,"red", "red", 0, "", "","buffers_signal_config", "", "", ""],
349 "color_default_fg" => ["default_fg", "color", "default foreground color for buffer name", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
350 "color_default_bg" => ["default_bg", "color", "default background color for buffer name", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
351 "color_hotlist_highlight_fg" => ["hotlist_highlight_fg", "color", "change foreground color of buffer name if a highlight messaged received","", 0, 0,"magenta", "magenta", 0, "", "","buffers_signal_config", "", "", ""],
352 "color_hotlist_highlight_bg" => ["hotlist_highlight_bg", "color", "change background color of buffer name if a highlight messaged received", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
353 "color_hotlist_low_fg" => ["hotlist_low_fg", "color", "change foreground color of buffer name if a low message received", "", 0, 0,"white", "white", 0, "", "","buffers_signal_config", "", "", ""],
354 "color_hotlist_low_bg" => ["hotlist_low_bg", "color", "change background color of buffer name if a low message received", "", 0, 0,
355 "default", "default", 0, "", "","buffers_signal_config", "", "", ""],
356 "color_hotlist_message_fg" => ["hotlist_message_fg", "color", "change foreground color of buffer name if a normal message received", "", 0, 0,"yellow", "yellow", 0, "", "","buffers_signal_config", "", "", ""],
357 "color_hotlist_message_bg" => ["hotlist_message_bg", "color", "change background color of buffer name if a normal message received", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
358 "color_hotlist_private_fg" => ["hotlist_private_fg", "color", "change foreground color of buffer name if a private message received", "", 0, 0,"lightgreen", "lightgreen", 0, "", "","buffers_signal_config", "", "", ""],
359 "color_hotlist_private_bg" => ["hotlist_private_bg", "color", "change background color of buffer name if a private message received", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
360 "color_number" => ["number", "color", "color for buffer number", "", 0, 0,"lightgreen", "lightgreen", 0, "", "","buffers_signal_config", "", "", ""],
361 "color_number_char" => ["number_char", "color", "color for buffer number char", "", 0, 0,"lightgreen", "lightgreen", 0, "", "","buffers_signal_config", "", "", ""],
362 "color_whitelist_default_fg" => ["whitelist_default_fg", "color", "default foreground color for whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
363 "color_whitelist_default_bg" => ["whitelist_default_bg", "color", "default background color for whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
364 "color_whitelist_low_fg" => ["whitelist_low_fg", "color", "low color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
365 "color_whitelist_low_bg" => ["whitelist_low_bg", "color", "low color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
366 "color_whitelist_message_fg" => ["whitelist_message_fg", "color", "message color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
367 "color_whitelist_message_bg" => ["whitelist_message_bg", "color", "message color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
368 "color_whitelist_private_fg" => ["whitelist_private_fg", "color", "private color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
369 "color_whitelist_private_bg" => ["whitelist_private_bg", "color", "private color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
370 "color_whitelist_highlight_fg" => ["whitelist_highlight_fg", "color", "highlight color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
371 "color_whitelist_highlight_bg" => ["whitelist_highlight_bg", "color", "highlight color of whitelist buffer name", "", 0, 0,"", "", 0, "", "","buffers_signal_config", "", "", ""],
372 "color_none_channel_fg" => ["none_channel_fg", "color", "foreground color for none channel buffer (e.g.: core/server/plugin buffer)", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
373 "color_none_channel_bg" => ["none_channel_bg", "color", "background color for none channel buffer (e.g.: core/server/plugin buffer)", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
374 "queries_default_fg" => ["queries_default_fg", "color", "foreground color for query buffer without message", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
375 "queries_default_bg" => ["queries_default_bg", "color", "background color for query buffer without message", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
376 "queries_message_fg" => ["queries_message_fg", "color", "foreground color for query buffer with unread message", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
377 "queries_message_bg" => ["queries_message_bg", "color", "background color for query buffer with unread message", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
378 "queries_highlight_fg" => ["queries_highlight_fg", "color", "foreground color for query buffer with unread highlight", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
379 "queries_highlight_bg" => ["queries_highlight_bg", "color", "background color for query buffer with unread highlight", "", 0, 0,"default", "default", 0, "", "","buffers_signal_config", "", "", ""],
382 my %default_options_look =
384 "show_lag" => ["show_lag","boolean","show lag behind servername. This option is using \"irc.color.item_lag_finished\", \"irc.network.lag_min_show\" and \"irc.network.lag_refresh_interval\"","",0,0,"off","off",0,"","","buffers_signal_config","","",""],
385 "look_whitelist_buffers" => ["whitelist_buffers", "string", "comma separated list of buffers for using a differnt color scheme (for example: freenode.#weechat,freenode.#weechat-fr)", "", 0, 0,"", "", 0, "", "", "buffers_signal_config_whitelist", "", "", ""],
386 "hide_merged_buffers" => ["hide_merged_buffers", "integer", "hide merged buffers. The value determines which merged buffers should be hidden, keepserver meaning 'all except server buffers'. Other values correspondent to the buffer type.", "server|channel|private|keepserver|all|none", 0, 0,"none", "none", 0, "", "", "buffers_signal_config", "", "", ""],
387 "indenting" => ["indenting", "integer", "use indenting for channel and query buffers. This option only takes effect if bar is left/right positioned", "off|on|under_name", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
388 "indenting_number" => ["indenting_number", "boolean", "use indenting for numbers. This option only takes effect if bar is left/right positioned", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
389 "short_names" => ["short_names", "boolean", "display short names (remove text before first \".\" in buffer name)", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
390 "show_number" => ["show_number", "boolean", "display channel number in front of buffername", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
391 "show_number_char" => ["number_char", "string", "display a char after channel number", "", 0, 0,".", ".", 0, "", "", "buffers_signal_config", "", "", ""],
392 "show_prefix" => ["prefix", "boolean", "show your prefix for channel", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
393 "show_prefix_empty" => ["prefix_empty", "boolean", "use a placeholder for channels without prefix", "", 0, 0,"on", "on", 0, "", "", "buffers_signal_config", "", "", ""],
394 "sort" => ["sort", "integer", "sort buffer-list by \"number\" or \"name\"", "number|name", 0, 0,"number", "number", 0, "", "", "buffers_signal_config", "", "", ""],
395 "core_to_front" => ["core_to_front", "boolean", "core buffer and buffers with free content will be listed first. Take only effect if buffer sort is by name", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
396 "jump_prev_next_visited_buffer" => ["jump_prev_next_visited_buffer", "boolean", "jump to previously or next visited buffer if you click with left/right mouse button on currently visiting buffer", "", 0, 0,"off", "off", 0, "", "", "buffers_signal_config", "", "", ""],
397 "name_size_max" => ["name_size_max","integer","maximum size of buffer name. 0 means no limitation","",0,256,0,0,0, "", "", "buffers_signal_config", "", "", ""],
398 "name_crop_suffix" => ["name_crop_suffix","string","contains an optional char(s) that is appended when buffer name is shortened","",0,0,"+","+",0,"","","buffers_signal_config", "", "", ""],
399 "detach" => ["detach", "integer","detach channel from buffers list after a specific period of time (in seconds) without action (weechat ≥ 0.3.8 required)", "", 0, 31536000,0, "number", 0, "", "", "buffers_signal_config", "", "", ""],
400 "immune_detach_buffers" => ["immune_detach_buffers", "string", "comma separated list of buffers which will not get detached automatically. Good with e.g. BitlBee", "", 0, 0,"", "", 0, "", "", "buffers_signal_config_immune_detach_buffers", "", "", ""],
403 my $section_color = weechat
::config_new_section
($buffers_config_file,"color", 0, 0, "", "", "", "", "", "", "", "", "", "");
404 if ($section_color eq "")
406 weechat
::config_free
($buffers_config_file);
409 foreach my $option (keys %default_options_color)
411 $options{$option} = weechat
::config_new_option
($buffers_config_file, $section_color,
412 $default_options_color{$option}[0],$default_options_color{$option}[1],$default_options_color{$option}[2],
413 $default_options_color{$option}[3],$default_options_color{$option}[4],$default_options_color{$option}[5],
414 $default_options_color{$option}[6],$default_options_color{$option}[7],$default_options_color{$option}[8],
415 $default_options_color{$option}[9],$default_options_color{$option}[10],$default_options_color{$option}[11],
416 $default_options_color{$option}[12],$default_options_color{$option}[13],$default_options_color{$option}[14]);
420 my $section_look = weechat
::config_new_section
($buffers_config_file,"look", 0, 0, "", "", "", "", "", "", "", "", "", "");
421 if ($section_look eq "")
423 weechat
::config_free
($buffers_config_file);
426 foreach my $option (keys %default_options_look)
428 $options{$option} = weechat
::config_new_option
($buffers_config_file, $section_look,
429 $default_options_look{$option}[0],$default_options_look{$option}[1],$default_options_look{$option}[2],
430 $default_options_look{$option}[3],$default_options_look{$option}[4],$default_options_look{$option}[5],
431 $default_options_look{$option}[6],$default_options_look{$option}[7],$default_options_look{$option}[8],
432 $default_options_look{$option}[9],$default_options_look{$option}[10],$default_options_look{$option}[11],
433 $default_options_look{$option}[12],$default_options_look{$option}[13],$default_options_look{$option}[14]);
441 # get bar position (left/right/top/bottom)
442 my $position = "left";
443 my $option_position = weechat
::config_get
("weechat.bar.buffers.position");
444 if ($option_position ne "")
446 $position = weechat
::config_string
($option_position);
451 my $infolist = weechat
::infolist_get
("hotlist", "", "");
452 while (weechat
::infolist_next
($infolist))
454 $hotlist{weechat
::infolist_pointer
($infolist, "buffer_pointer")} =
455 weechat
::infolist_integer
($infolist, "priority");
457 weechat
::infolist_free
($infolist);
466 my $max_number_digits = 0;
468 $infolist = weechat
::infolist_get
("buffer", "", "");
469 while (weechat
::infolist_next
($infolist))
472 my $number = weechat
::infolist_integer
($infolist, "number");
473 if ($number ne $old_number)
475 @buffers = (@buffers, @current2, @current1);
480 if ($number > $max_number)
482 $max_number = $number;
484 $old_number = $number;
485 my $active = weechat
::infolist_integer
($infolist, "active");
490 $buffer->{"pointer"} = weechat
::infolist_pointer
($infolist, "pointer");
491 $buffer->{"number"} = $number;
492 $buffer->{"active"} = $active;
493 $buffer->{"current_buffer"} = weechat
::infolist_integer
($infolist, "current_buffer");
494 $buffer->{"plugin_name"} = weechat
::infolist_string
($infolist, "plugin_name");
495 $buffer->{"name"} = weechat
::infolist_string
($infolist, "name");
496 $buffer->{"short_name"} = weechat
::infolist_string
($infolist, "short_name");
497 $buffer->{"full_name"} = $buffer->{"plugin_name"}.".".$buffer->{"name"};
498 $buffer->{"type"} = weechat
::buffer_get_string
($buffer->{"pointer"},"localvar_type");
499 # weechat::print("",$buffer->{"type"});
501 unless( grep {$_ eq $buffer->{"name"}} @immune_detach_buffers )
503 my $detach_time = weechat
::config_integer
( $options{"detach"});
504 my $current_time = time();
505 # set timer for buffers with no hotlist action
506 $buffers_timer{$buffer->{"pointer"}} = $current_time
507 if ( not exists $hotlist{$buffer->{"pointer"}}
508 and $buffer->{"type"} eq "channel"
509 and not exists $buffers_timer{$buffer->{"pointer"}}
510 and $detach_time > 0);
513 unless ( $buffer->{"current_buffer"} eq 0
514 and not exists $hotlist{$buffer->{"pointer"}}
515 and $buffer->{"type"} eq "channel"
516 and exists $buffers_timer{$buffer->{"pointer"}}
518 and $weechat_version >= 0x00030800
519 and $current_time - $buffers_timer{$buffer->{"pointer"}} >= $detach_time )
523 push(@current2, $buffer);
527 push(@current1, $buffer);
535 push(@current2, $buffer);
539 push(@current1, $buffer);
546 if ($max_number >= 1)
548 $max_number_digits = length(int($max_number));
550 @buffers = (@buffers, @current2, @current1);
551 weechat
::infolist_free
($infolist);
553 # sort buffers by number, name or shortname
558 for my $buffer (@buffers)
561 if (weechat
::config_integer
( $options{"sort"} ) eq 1) # number = 0; name = 1
563 my $name = $buffer->{"name"};
564 $name = $buffer->{"short_name"} if (weechat
::config_boolean
( $options{"short_names"} ) eq 1);
565 if (weechat
::config_integer
($options{"name_size_max"}) >= 1){
566 $name = encode
("UTF-8", substr(decode
("UTF-8", $name), 0, weechat
::config_integer
($options{"name_size_max"})));
568 if ( weechat
::config_boolean
($options{"core_to_front"}) eq 1)
570 if ( (weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "private") )
572 my $type = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type");
573 if ( $type eq "" and $name ne "weechat")
582 $key = sprintf("%s%08d", lc($name), $buffer->{"number"});
586 $key = sprintf("%08d", $number);
588 $sorted_buffers{$key} = $buffer;
593 # build string with buffers
595 foreach my $key (sort keys %sorted_buffers)
597 my $buffer = $sorted_buffers{$key};
599 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "server" )
601 # buffer type "server" or merged with core?
602 if ( ($buffer->{"type"} eq "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
607 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "channel" )
609 # buffer type "channel" or merged with core?
610 if ( ($buffer->{"type"} eq "channel" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
615 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "private" )
617 # buffer type "private" or merged with core?
618 if ( ($buffer->{"type"} eq "private" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
623 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "keepserver" )
625 if ( ($buffer->{"type"} ne "server" or $buffer->{"plugin_name"} eq "core") && (! $buffer->{"active"}) )
630 if ( weechat
::config_string
($options{"hide_merged_buffers"}) eq "all" )
632 if ( ! $buffer->{"active"} )
638 push(@buffers_focus, $buffer); # buffer > buffers_focus, for mouse support
642 $color = weechat
::config_color
( $options{"color_default_fg"} );
643 $bg = weechat
::config_color
( $options{"color_default_bg"} );
645 if ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") eq "private" )
647 if ( (weechat
::config_color
($options{"queries_default_bg"})) ne "default" || (weechat
::config_color
($options{"queries_default_fg"})) ne "default" )
649 $bg = weechat
::config_color
( $options{"queries_default_bg"} );
650 $color = weechat
::config_color
( $options{"queries_default_fg"} );
653 # check for core and buffer with free content
654 if ( (weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "channel" ) and ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") ne "private") )
656 $color = weechat
::config_color
( $options{"color_none_channel_fg"} );
657 $bg = weechat
::config_color
( $options{"color_none_channel_bg"} );
659 # default whitelist buffer?
660 if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
662 $color = weechat
::config_color
( $options{"color_whitelist_default_fg"} );
663 $bg = weechat
::config_color
( $options{"color_whitelist_default_bg"} );
666 $color = "default" if ($color eq "");
668 # color for channel and query buffer
669 if (exists $hotlist{$buffer->{"pointer"}})
671 delete $buffers_timer{$buffer->{"pointer"}};
672 # check if buffer is in whitelist buffer
673 if (grep {$_ eq $buffer->{"name"}} @whitelist_buffers)
675 $bg = weechat
::config_color
( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
676 $color = weechat
::config_color
( $options{"color_whitelist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
678 elsif ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") eq "private" )
680 # queries_default_fg/bg and buffers.color.queries_message_fg/bg
681 if ( (weechat
::config_color
($options{"queries_highlight_fg"})) ne "default" ||
682 (weechat
::config_color
($options{"queries_highlight_bg"})) ne "default" ||
683 (weechat
::config_color
($options{"queries_message_fg"})) ne "default" ||
684 (weechat
::config_color
($options{"queries_message_bg"})) ne "default" )
686 if ( ($hotlist{$buffer->{"pointer"}}) == 2 )
688 $bg = weechat
::config_color
( $options{"queries_message_bg"} );
689 $color = weechat
::config_color
( $options{"queries_message_fg"} );
692 elsif ( ($hotlist{$buffer->{"pointer"}}) == 3 )
694 $bg = weechat
::config_color
( $options{"queries_highlight_bg"} );
695 $color = weechat
::config_color
( $options{"queries_highlight_fg"} );
699 $bg = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
700 $color = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
704 $bg = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_bg"} );
705 $color = weechat
::config_color
( $options{"color_hotlist_".$hotlist_level{$hotlist{$buffer->{"pointer"}}}."_fg"} );
709 if ($buffer->{"current_buffer"})
711 $color = weechat
::config_color
( $options{"color_current_fg"} );
712 $bg = weechat
::config_color
( $options{"color_current_bg"} );
715 $color_bg = weechat
::color
(",".$bg) if ($bg ne "");
717 # create channel number for output
718 if ( weechat
::config_boolean
( $options{"show_number"} ) eq 1 ) # on
720 if (( weechat
::config_boolean
( $options{"indenting_number"} ) eq 1)
721 && (($position eq "left") || ($position eq "right")))
723 $str .= weechat
::color
("default").$color_bg
724 .(" " x
($max_number_digits - length(int($buffer->{"number"}))));
726 if ($old_number ne $buffer->{"number"})
728 $str .= weechat
::color
( weechat
::config_color
( $options{"color_number"} ) )
731 .weechat
::color
("default")
733 .weechat
::color
( weechat
::config_color
( $options{"color_number_char"} ) )
734 .weechat
::config_string
( $options{"show_number_char"} )
740 $indent = ((" " x
length($buffer->{"number"}))." ") if (($position eq "left") || ($position eq "right"));
741 $str .= weechat
::color
("default")
747 if (( weechat
::config_integer
( $options{"indenting"} ) ne 0 ) # indenting NOT off
748 && (($position eq "left") || ($position eq "right")))
750 my $type = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type");
751 if (($type eq "channel") || ($type eq "private"))
753 if ( weechat
::config_integer
( $options{"indenting"} ) eq 1 )
757 elsif ( (weechat
::config_integer
($options{"indenting"}) eq 2) and (weechat
::config_integer
($options{"indenting_number"}) eq 0) ) #under_name
759 if ( weechat
::config_boolean
( $options{"show_number"} ) eq 0 )
764 $str .= ( (" " x
( $max_number_digits - length($buffer->{"number"}) ))." " );
769 if (weechat
::config_boolean
( $options{"show_prefix"} ) eq 1)
771 my $nickname = weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_nick");
774 # with version >= 0.3.2, this infolist will return only nick
775 # with older versions, whole nicklist is returned for buffer, and this can be very slow
776 my $infolist_nick = weechat
::infolist_get
("nicklist", $buffer->{"pointer"}, "nick_".$nickname);
777 if ($infolist_nick ne "")
779 my $version = weechat
::info_get
("version_number", "");
780 $version = 0 if ($version eq "");
781 while (weechat
::infolist_next
($infolist_nick))
783 if ((weechat
::infolist_string
($infolist_nick, "type") eq "nick")
784 && (weechat
::infolist_string
($infolist_nick, "name") eq $nickname))
786 my $prefix = weechat
::infolist_string
($infolist_nick, "prefix");
787 if (($prefix ne " ") or (weechat
::config_boolean
( $options{"show_prefix_empty"} ) eq 1))
789 # with version >= 0.3.5, it is now a color name (for older versions: option name with color)
790 if (int($version) >= 0x00030500)
792 $str .= weechat
::color
(weechat
::infolist_string
($infolist_nick, "prefix_color"));
796 $str .= weechat
::color
(weechat
::config_color
(
798 weechat
::infolist_string
($infolist_nick, "prefix_color"))));
805 weechat
::infolist_free
($infolist_nick);
809 $str .= weechat
::color
($color) . weechat
::color
(",".$bg);
811 if (weechat
::config_boolean
( $options{"short_names"} ) eq 1)
813 if (weechat
::config_integer
($options{"name_size_max"}) >= 1) # check max_size of buffer name
815 $str .= encode
("UTF-8", substr(decode
("UTF-8", $buffer->{"short_name"}), 0, weechat
::config_integer
($options{"name_size_max"})));
816 $str .= weechat
::color
(weechat
::config_color
( $options{"color_number_char"})).weechat
::config_string
($options{"name_crop_suffix"}) if (length($buffer->{"short_name"}) > weechat
::config_integer
($options{"name_size_max"}));
820 $str .= $buffer->{"short_name"};
825 if (weechat
::config_integer
($options{"name_size_max"}) >= 1) # check max_size of buffer name
827 $str .= encode
("UTF-8", substr(decode
("UTF-8", $buffer->{"name"},), 0, weechat
::config_integer
($options{"name_size_max"})));
828 $str .= weechat
::color
(weechat
::config_color
( $options{"color_number_char"})).weechat
::config_string
($options{"name_crop_suffix"}) if (length($buffer->{"name"}) > weechat
::config_integer
($options{"name_size_max"}));
832 $str .= $buffer->{"name"};
835 if ( weechat
::buffer_get_string
($buffer->{"pointer"}, "localvar_type") eq "server" and weechat
::config_boolean
($options{"show_lag"}) eq 1)
837 my $color_lag = weechat
::config_color
(weechat
::config_get
("irc.color.item_lag_finished"));
838 my $min_lag = weechat
::config_integer
(weechat
::config_get
("irc.network.lag_min_show"));
839 my $infolist_server = weechat
::infolist_get
("irc_server","",$buffer->{"short_name"});
840 weechat
::infolist_next
($infolist_server);
841 my $lag = (weechat
::infolist_integer
($infolist_server, "lag"));
842 weechat
::infolist_free
($infolist_server);
843 if ( int($lag) > int($min_lag) )
846 $str .= weechat
::color
("default") . " (" . weechat
::color
($color_lag) . $lag . weechat
::color
("default") . ")";
850 $old_number = $buffer->{"number"};
856 sub buffers_signal_buffer
858 my ($data, $signal, $signal_data) = @_;
859 # check for buffer_switch and set the detach time or remove detach time
860 if ($weechat_version >= 0x00030800)
862 if ($signal eq "buffer_switch")
864 my $pointer = weechat
::hdata_get_list
(weechat
::hdata_get
("buffer"), "gui_buffer_last_displayed"); # get switched buffer
865 my $current_time = time();
866 if ( weechat
::buffer_get_string
($pointer, "localvar_type") eq "channel")
868 $buffers_timer{$pointer} = $current_time;
872 delete $buffers_timer{$pointer};
875 if ($signal eq "buffer_opened")
877 my $current_time = time();
878 $buffers_timer{$signal_data} = $current_time;
880 if ($signal eq "buffer_closing")
882 delete $buffers_timer{$signal_data};
886 weechat
::bar_item_update
("buffers");
887 return weechat
::WEECHAT_RC_OK
;
890 sub buffers_signal_hotlist
892 weechat
::bar_item_update
("buffers");
893 return weechat
::WEECHAT_RC_OK
;
897 sub buffers_signal_config_whitelist
899 @whitelist_buffers = ();
900 @whitelist_buffers = split( /,/, weechat
::config_string
( $options{"look_whitelist_buffers"} ) );
901 weechat
::bar_item_update
("buffers");
902 return weechat
::WEECHAT_RC_OK
;
904 sub buffers_signal_config_immune_detach_buffers
906 @immune_detach_buffers = ();
907 @immune_detach_buffers = split( /,/, weechat
::config_string
( $options{"immune_detach_buffers"} ) );
908 weechat
::bar_item_update
("buffers");
909 return weechat
::WEECHAT_RC_OK
;
912 sub buffers_signal_config
914 weechat
::bar_item_update
("buffers");
915 return weechat
::WEECHAT_RC_OK
;
918 # called when mouse click occured in buffers item: this callback returns buffer
919 # hash according to line of item where click occured
920 sub buffers_focus_buffers
923 my $item_line = int($info{"_bar_item_line"});
925 if (($info{"_bar_item_name"} eq "buffers") && ($item_line >= 0) && ($item_line <= $#buffers_focus))
927 $hash = $buffers_focus[$item_line];
932 my $hash_focus = $buffers_focus[0];
933 foreach my $key (keys %$hash_focus)
941 # called when a mouse action is done on buffers item, to execute action
942 # possible actions: jump to a buffer or move buffer in list (drag & drop of buffer)
943 sub buffers_hsignal_mouse
945 my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
946 my $current_buffer = weechat
::buffer_get_integer
(weechat
::current_buffer
(), "number"); # get current buffer number
948 if ( $hash{"_key"} eq "button1" ) # left mouse button
950 if ($hash{"number"} eq $hash{"number2"})
952 if ( weechat
::config_integer
($options{"jump_prev_next_visited_buffer"}) eq 1 )
954 if ( $current_buffer eq $hash{"number"} )
956 weechat
::command
("","/input jump_previously_visited_buffer");
960 weechat
::command
("", "/buffer ".$hash{"full_name"});
965 weechat
::command
("", "/buffer ".$hash{"full_name"});
973 elsif ( ($hash{"_key"} eq "button2") && (weechat
::config_integer
($options{"jump_prev_next_visited_buffer"}) eq 1) )# right mouse button
975 if ( $current_buffer eq $hash{"number2"} )
977 weechat
::command
("","/input jump_next_visited_buffer");
988 my $number2 = $hash{"number2"};
991 # if number 2 is not known (end of gesture outside buffers list), then set it
992 # according to mouse gesture
994 $number2 = "1" if (($hash{"_key"} =~ /gesture-left/) || ($hash{"_key"} =~ /gesture-up/));
996 my $ptrbuf = weechat
::current_buffer
();
997 weechat
::command
($hash{"pointer"}, "/buffer move ".$number2);