]> git.rmz.io Git - dotfiles.git/blob - weechat/perl/iset.pl
dwb: cleanup bookmarks
[dotfiles.git] / weechat / perl / iset.pl
1 #
2 # Copyright (C) 2008-2013 Sebastien Helleu <flashcode@flashtux.org>
3 # Copyright (C) 2010-2012 Nils Görs <weechatter@arcor.de>
4 #
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.
9 #
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.
14 #
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/>.
17 #
18 # Set WeeChat and plugins options interactively.
19 #
20 # History:
21 #
22 # 2013-08-03, Sebastien Helleu <flashcode@flashtux.org>:
23 # version 3.2: allow "q" as input in iset buffer to close it
24 # 2013-07-14, Sebastien Helleu <flashcode@flashtux.org>:
25 # version 3.1: remove unneeded calls to iset_refresh() in mouse callback
26 # (faster mouse actions when lot of options are displayed),
27 # fix bug when clicking on a line after the last option displayed
28 # 2013-04-30, arza <arza@arza.us>:
29 # version 3.0: simpler title, fix refresh on unset
30 # 2012-12-16, nils_2 <weechatter@arcor.de>:
31 # version 2.9: fix focus window with iset buffer on mouse click
32 # 2012-08-25, nils_2 <weechatter@arcor.de>:
33 # version 2.8: most important key and mouse bindings for iset buffer added to title-bar (idea The-Compiler)
34 # 2012-07-31, nils_2 <weechatter@arcor.de>:
35 # version 2.7: add combined option and value search (see /help iset)
36 # : add exact value search (see /help iset)
37 # : fix problem with metacharacter in value search
38 # : fix use of uninitialized value for unset option and reset value of option
39 # 2012-07-25, nils_2 <weechatter@arcor.de>:
40 # version 2.6: switch to iset buffer (if existing) when command /iset is called with arguments
41 # 2012-03-17, Sebastien Helleu <flashcode@flashtux.org>:
42 # version 2.5: fix check of sections when creating config file
43 # 2012-03-09, Sebastien Helleu <flashcode@flashtux.org>:
44 # version 2.4: fix reload of config file
45 # 2012-02-02, nils_2 <weechatter@arcor.de>:
46 # version 2.3: fixed: refresh problem with new search results and cursor was outside window.
47 # : add: new option "current_line" in title bar
48 # version 2.2: fixed: refresh error when toggling plugins description
49 # 2011-11-05, nils_2 <weechatter@arcor.de>:
50 # version 2.1: use own config file (iset.conf), fix own help color (used immediately)
51 # 2011-10-16, nils_2 <weechatter@arcor.de>:
52 # version 2.0: add support for left-mouse-button and more sensitive mouse gesture (for integer/color options)
53 # add help text for mouse support
54 # 2011-09-20, Sebastien Helleu <flashcode@flashtux.org>:
55 # version 1.9: add mouse support, fix iset buffer, fix errors on first load under FreeBSD
56 # 2011-07-21, nils_2 <weechatter@arcor.de>:
57 # version 1.8: added: option "show_plugin_description" (alt+p)
58 # fixed: typos in /help iset (lower case for alt+'x' keys)
59 # 2011-05-29, nils_2 <weechatter@arcor.de>:
60 # version 1.7: added: version check for future needs
61 # added: new option (scroll_horiz) and usage of scroll_horiz function (weechat >= 0.3.6 required)
62 # fixed: help_bar did not pop up immediately using key-shortcut
63 # 2011-02-19, nils_2 <weechatter@arcor.de>:
64 # version 1.6: added: display of all possible values in help bar (show_help_extra_info)
65 # fixed: external user options never loaded when starting iset first time
66 # 2011-02-13, Sebastien Helleu <flashcode@flashtux.org>:
67 # version 1.5: use new help format for command arguments
68 # 2011-02-03, nils_2 <weechatter@arcor.de>:
69 # version 1.4: fixed: restore value filter after /upgrade using buffer local variable.
70 # 2011-01-14, nils_2 <weechatter@arcor.de>:
71 # version 1.3: added function to search for values (option value_search_char).
72 # code optimization.
73 # 2010-12-26, Sebastien Helleu <flashcode@flashtux.org>:
74 # version 1.2: improve speed of /upgrade when iset buffer is open,
75 # restore filter used after /upgrade using buffer local variable,
76 # use /iset filter argument if buffer is open.
77 # 2010-11-21, drubin <drubin+weechat@smartcube.co.za>:
78 # version 1.1.1: fix bugs with cursor position
79 # 2010-11-20, nils_2 <weechatter@arcor.de>:
80 # version 1.1: cursor position set to value
81 # 2010-08-03, Sebastien Helleu <flashcode@flashtux.org>:
82 # version 1.0: move misplaced call to infolist_free()
83 # 2010-02-02, rettub <rettub@gmx.net>:
84 # version 0.9: turn all the help stuff off if option 'show_help_bar' is 'off',
85 # new key binding <alt>-<v> to toggle help_bar and help stuff on/off
86 # 2010-01-30, nils_2 <weechatter@arcor.de>:
87 # version 0.8: fix error when option does not exist
88 # 2010-01-24, Sebastien Helleu <flashcode@flashtux.org>:
89 # version 0.7: display iset bar only on iset buffer
90 # 2010-01-22, nils_2 <weechatter@arcor.de> and drubin:
91 # version 0.6: add description in a bar, fix singular/plural bug in title bar,
92 # fix selected line when switching buffer
93 # 2009-06-21, Sebastien Helleu <flashcode@flashtux.org>:
94 # version 0.5: fix bug with iset buffer after /upgrade
95 # 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
96 # version 0.4: sync with last API changes
97 # 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
98 # version 0.3: open iset buffer when /iset command is executed
99 # 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
100 # version 0.2: use null values for options, add colors, fix refresh bugs,
101 # use new keys to reset/unset options, sort options by name,
102 # display number of options in buffer's title
103 # 2008-11-05, Sebastien Helleu <flashcode@flashtux.org>:
104 # version 0.1: first official version
105 # 2008-04-19, Sebastien Helleu <flashcode@flashtux.org>:
106 # script creation
107
108 use strict;
109
110 my $PRGNAME = "iset";
111 my $VERSION = "3.2";
112 my $DESCR = "Interactive Set for configuration options";
113 my $AUTHOR = "Sebastien Helleu <flashcode\@flashtux.org>";
114 my $LICENSE = "GPL3";
115 my $LANG = "perl";
116 my $ISET_CONFIG_FILE_NAME = "iset";
117
118 my $iset_config_file;
119 my $iset_buffer = "";
120 my $wee_version_number = 0;
121 my @iset_focus = ();
122 my @options_names = ();
123 my @options_types = ();
124 my @options_values = ();
125 my @options_is_null = ();
126 my $option_max_length = 0;
127 my $current_line = 0;
128 my $filter = "*";
129 my $description = "";
130 my $options_name_copy = "";
131 my $iset_filter_title = "";
132 # search modes: 0 = index() on value, 1 = grep() on value, 2 = grep() on option, 3 = grep on option & value
133 my $search_mode = 2;
134 my $search_value = "";
135 my $help_text_keys = "alt + space: toggle, +/-: increase/decrease, enter: change, ir: reset, iu: unset, v: toggle help bar";
136 my $help_text_mouse = "Mouse: left: select, right: toggle/set, right + drag left/right: increase/decrease";
137 my %options_iset;
138
139 my %mouse_keys = ("\@chat(perl.$PRGNAME):button1" => "hsignal:iset_mouse",
140 "\@chat(perl.$PRGNAME):button2*" => "hsignal:iset_mouse",
141 "\@chat(perl.$PRGNAME):wheelup" => "/repeat 5 /iset **up",
142 "\@chat(perl.$PRGNAME):wheeldown" => "/repeat 5 /iset **down");
143
144
145 sub iset_title
146 {
147 if ($iset_buffer ne "")
148 {
149 my $current_line_counter = "";
150 $current_line_counter = ($current_line + 1) . "/" if (weechat::config_boolean($options_iset{"show_current_line"}) == 1);
151 my $show_filter = "";
152 if ($search_mode eq 0)
153 {
154 $iset_filter_title = "(value) ";
155 $show_filter = $search_value;
156 if ( substr($show_filter,0,1) eq weechat::config_string($options_iset{"value_search_char"}) )
157 {
158 $show_filter = substr($show_filter,1,length($show_filter));
159 }
160 }
161 elsif ($search_mode eq 1)
162 {
163 $iset_filter_title = "(value) ";
164 $show_filter = "*".$search_value."*";
165 }
166 elsif ($search_mode eq 2)
167 {
168 $iset_filter_title = "";
169 $filter = "*" if ($filter eq "");
170 $show_filter = $filter;
171 }
172 elsif ($search_mode eq 3)
173 {
174 $iset_filter_title = "(option) ";
175 $show_filter = $filter
176 .weechat::color("default")
177 ." / (value) "
178 .weechat::color("yellow")
179 ."*".$search_value."*";
180 }
181 weechat::buffer_set($iset_buffer, "title",
182 $iset_filter_title
183 .weechat::color("yellow")
184 .$show_filter
185 .weechat::color("default")." | "
186 .$current_line_counter
187 .@options_names
188 ." | "
189 .$help_text_keys
190 ." | "
191 .$help_text_mouse);
192 }
193 }
194
195 sub iset_create_filter
196 {
197 $filter = $_[0];
198 if ( $search_mode == 3 )
199 {
200 my @cmd_array = split(/ /,$filter);
201 my $array_count = @cmd_array;
202 $filter = $cmd_array[0];
203 $filter = $cmd_array[0] . " " . $cmd_array[1] if ( $array_count >2 );
204 }
205 $filter = "$1.*" if ($filter =~ /f (.*)/); # search file
206 $filter = "*.$1.*" if ($filter =~ /s (.*)/); # search section
207 if ((substr($filter, 0, 1) ne "*") && (substr($filter, -1, 1) ne "*"))
208 {
209 $filter = "*".$filter."*";
210 }
211 if ($iset_buffer ne "")
212 {
213 weechat::buffer_set($iset_buffer, "localvar_set_iset_filter", $filter);
214 }
215 }
216
217 sub iset_buffer_input
218 {
219 my ($data, $buffer, $string) = ($_[0], $_[1], $_[2]);
220 if ($string eq "q")
221 {
222 weechat::buffer_close($buffer);
223 return weechat::WEECHAT_RC_OK;
224 }
225 $search_value = "";
226 my @cmd_array = split(/ /,$string);
227 my $array_count = @cmd_array;
228 my $string2 = substr($string, 0, 1);
229 if ($string2 eq weechat::config_string($options_iset{"value_search_char"})
230 or (defined $cmd_array[0] and $cmd_array[0] eq weechat::config_string($options_iset{"value_search_char"}).weechat::config_string($options_iset{"value_search_char"})) )
231 {
232 $search_mode = 1;
233 $search_value = substr($string, 1);
234 iset_get_values($search_value);
235 if ($iset_buffer ne "")
236 {
237 weechat::buffer_set($iset_buffer, "localvar_set_iset_search_value", $search_value);
238 }
239 }
240 else
241 {
242 $search_mode = 2;
243 if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s")
244 {
245 if ( defined $cmd_array[1] and substr($cmd_array[1], 0, 1) eq weechat::config_string($options_iset{"value_search_char"})
246 or defined $cmd_array[2] and substr($cmd_array[2], 0, 1) eq weechat::config_string($options_iset{"value_search_char"}) )
247 {
248 $search_mode = 3;
249 $search_value = substr($cmd_array[1], 1); # cut value_search_char
250 $search_value = substr($cmd_array[2], 1) if ( $array_count > 2); # cut value_search_char
251 }
252 }
253 if ( $search_mode == 3)
254 {
255 iset_create_filter($string);
256 iset_get_options($search_value);
257 }else
258 {
259 iset_create_filter($string);
260 iset_get_options("");
261 }
262 }
263 weechat::buffer_set($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
264 weechat::buffer_clear($buffer);
265 $current_line = 0;
266 iset_refresh();
267 return weechat::WEECHAT_RC_OK;
268 }
269
270 sub iset_buffer_close
271 {
272 $iset_buffer = "";
273
274 return weechat::WEECHAT_RC_OK;
275 }
276
277 sub iset_init
278 {
279 $current_line = 0;
280 $iset_buffer = weechat::buffer_search($LANG, $PRGNAME);
281 if ($iset_buffer eq "")
282 {
283 $iset_buffer = weechat::buffer_new($PRGNAME, "iset_buffer_input", "", "iset_buffer_close", "");
284 }
285 else
286 {
287 my $new_filter = weechat::buffer_get_string($iset_buffer, "localvar_iset_filter");
288 $search_mode = weechat::buffer_get_string($iset_buffer, "localvar_iset_search_mode");
289 $search_value = weechat::buffer_get_string($iset_buffer, "localvar_iset_search_value");
290 $filter = $new_filter if ($new_filter ne "");
291 }
292 if ($iset_buffer ne "")
293 {
294 weechat::buffer_set($iset_buffer, "type", "free");
295 iset_title();
296 weechat::buffer_set($iset_buffer, "key_bind_ctrl-L", "/iset **refresh");
297 weechat::buffer_set($iset_buffer, "key_bind_meta2-A", "/iset **up");
298 weechat::buffer_set($iset_buffer, "key_bind_meta2-B", "/iset **down");
299 weechat::buffer_set($iset_buffer, "key_bind_meta2-23~", "/iset **left");
300 weechat::buffer_set($iset_buffer, "key_bind_meta2-24~" , "/iset **right");
301 weechat::buffer_set($iset_buffer, "key_bind_meta- ", "/iset **toggle");
302 weechat::buffer_set($iset_buffer, "key_bind_meta-+", "/iset **incr");
303 weechat::buffer_set($iset_buffer, "key_bind_meta--", "/iset **decr");
304 weechat::buffer_set($iset_buffer, "key_bind_meta-imeta-r", "/iset **reset");
305 weechat::buffer_set($iset_buffer, "key_bind_meta-imeta-u", "/iset **unset");
306 weechat::buffer_set($iset_buffer, "key_bind_meta-ctrl-J", "/iset **set");
307 weechat::buffer_set($iset_buffer, "key_bind_meta-ctrl-M", "/iset **set");
308 weechat::buffer_set($iset_buffer, "key_bind_meta-meta2-1~", "/iset **scroll_top");
309 weechat::buffer_set($iset_buffer, "key_bind_meta-meta2-4~", "/iset **scroll_bottom");
310 weechat::buffer_set($iset_buffer, "key_bind_meta-v", "/iset **toggle_help");
311 weechat::buffer_set($iset_buffer, "key_bind_meta-p", "/iset **toggle_show_plugin_desc");
312 weechat::buffer_set($iset_buffer, "localvar_set_iset_filter", $filter);
313 weechat::buffer_set($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
314 weechat::buffer_set($iset_buffer, "localvar_set_iset_search_value", $search_value);
315 }
316 }
317
318 sub iset_get_options
319 {
320 my $var_value = $_[0];
321 $var_value = "" if (not defined $var_value);
322 $var_value = lc($var_value);
323 $search_value = $var_value;
324 @iset_focus = ();
325 @options_names = ();
326 @options_types = ();
327 @options_values = ();
328 @options_is_null = ();
329 $option_max_length = 0;
330 my %options_internal = ();
331 my $i = 0;
332 my $key;
333 my $iset_struct;
334 my %iset_struct;
335
336 weechat::buffer_set($iset_buffer, "localvar_set_iset_search_value", $var_value) if ($search_mode == 3);
337
338 my $infolist = weechat::infolist_get("option", "", $filter);
339 while (weechat::infolist_next($infolist))
340 {
341 $key = sprintf("%08d", $i);
342 my $name = weechat::infolist_string($infolist, "full_name");
343 next if (weechat::config_boolean($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1);
344 my $type = weechat::infolist_string($infolist, "type");
345 my $value = weechat::infolist_string($infolist, "value");
346 my $is_null = weechat::infolist_integer($infolist, "value_is_null");
347 if ($search_mode == 3)
348 {
349 my $value = weechat::infolist_string($infolist, "value");
350 if ( grep /\Q$var_value/,lc($value) )
351 {
352 $options_internal{$name}{"type"} = $type;
353 $options_internal{$name}{"value"} = $value;
354 $options_internal{$name}{"is_null"} = $is_null;
355 $option_max_length = length($name) if (length($name) > $option_max_length);
356 $iset_struct{$key} = $options_internal{$name};
357 push(@iset_focus, $iset_struct{$key});
358 }
359 }
360 else
361 {
362 $options_internal{$name}{"type"} = $type;
363 $options_internal{$name}{"value"} = $value;
364 $options_internal{$name}{"is_null"} = $is_null;
365 $option_max_length = length($name) if (length($name) > $option_max_length);
366 $iset_struct{$key} = $options_internal{$name};
367 push(@iset_focus, $iset_struct{$key});
368 }
369 $i++;
370 }
371 weechat::infolist_free($infolist);
372
373 foreach my $name (sort keys %options_internal)
374 {
375 push(@options_names, $name);
376 push(@options_types, $options_internal{$name}{"type"});
377 push(@options_values, $options_internal{$name}{"value"});
378 push(@options_is_null, $options_internal{$name}{"is_null"});
379 }
380 }
381
382 sub iset_get_values
383 {
384 my $var_value = $_[0];
385 $var_value = lc($var_value);
386 if (substr($var_value,0,1) eq weechat::config_string($options_iset{"value_search_char"}) and $var_value ne weechat::config_string($options_iset{"value_search_char"}))
387 {
388 $var_value = substr($var_value,1,length($var_value));
389 $search_mode = 0;
390 }
391 iset_search_values($var_value,$search_mode);
392 weechat::buffer_set($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
393 weechat::buffer_set($iset_buffer, "localvar_set_iset_search_value", $var_value);
394 $search_value = $var_value;
395 }
396 sub iset_search_values
397 {
398 my ($var_value,$search_mode) = ($_[0],$_[1]);
399 @options_names = ();
400 @options_types = ();
401 @options_values = ();
402 @options_is_null = ();
403 $option_max_length = 0;
404 my %options_internal = ();
405 my $i = 0;
406 my $infolist = weechat::infolist_get("option", "", "*");
407 while (weechat::infolist_next($infolist))
408 {
409 my $name = weechat::infolist_string($infolist, "full_name");
410 next if (weechat::config_boolean($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1);
411 my $type = weechat::infolist_string($infolist, "type");
412 my $is_null = weechat::infolist_integer($infolist, "value_is_null");
413 my $value = weechat::infolist_string($infolist, "value");
414 if ($search_mode)
415 {
416 if ( grep /\Q$var_value/,lc($value) )
417 {
418 $options_internal{$name}{"type"} = $type;
419 $options_internal{$name}{"value"} = $value;
420 $options_internal{$name}{"is_null"} = $is_null;
421 $option_max_length = length($name) if (length($name) > $option_max_length);
422 }
423 }
424 else
425 {
426 # if ($value =~ /\Q$var_value/si)
427 if (lc($value) eq $var_value)
428 {
429 $options_internal{$name}{"type"} = $type;
430 $options_internal{$name}{"value"} = $value;
431 $options_internal{$name}{"is_null"} = $is_null;
432 $option_max_length = length($name) if (length($name) > $option_max_length);
433 }
434 }
435 $i++;
436 }
437 weechat::infolist_free($infolist);
438 foreach my $name (sort keys %options_internal)
439 {
440 push(@options_names, $name);
441 push(@options_types, $options_internal{$name}{"type"});
442 push(@options_values, $options_internal{$name}{"value"});
443 push(@options_is_null, $options_internal{$name}{"is_null"});
444 }
445 }
446
447 sub iset_refresh_line
448 {
449 if ($iset_buffer ne "")
450 {
451 my $y = $_[0];
452 if ($y <= $#options_names)
453 {
454 return if (! defined($options_types[$y]));
455 my $format = sprintf("%%s%%-%ds %%s %%-7s %%s %%s%%s%%s", $option_max_length);
456 my $around = "";
457 $around = "\"" if ((!$options_is_null[$y]) && ($options_types[$y] eq "string"));
458
459 my $color1 = weechat::color(weechat::config_color($options_iset{"color_option"}));
460 my $color2 = weechat::color(weechat::config_color($options_iset{"color_type"}));
461 my $color3 = "";
462 if ($options_is_null[$y])
463 {
464 $color3 = weechat::color(weechat::config_color($options_iset{"color_value_undef"}));
465 }
466 else
467 {
468 $color3 = weechat::color(weechat::config_color($options_iset{"color_value"}));
469 }
470 if ($y == $current_line)
471 {
472 $color1 = weechat::color(weechat::config_color($options_iset{"color_option_selected"}).",".weechat::config_color($options_iset{"color_bg_selected"}));
473 $color2 = weechat::color(weechat::config_color($options_iset{"color_type_selected"}).",".weechat::config_color($options_iset{"color_bg_selected"}));
474 if ($options_is_null[$y])
475 {
476 $color3 = weechat::color(weechat::config_color($options_iset{"color_value_undef_selected"}).",".weechat::config_color($options_iset{"color_bg_selected"}));
477 }
478 else
479 {
480 $color3 = weechat::color(weechat::config_color($options_iset{"color_value_selected"}).",".weechat::config_color($options_iset{"color_bg_selected"}));
481 }
482 }
483 my $value = $options_values[$y];
484 $value = "(undef)" if ($options_is_null[$y]);
485 my $strline = sprintf($format,
486 $color1, $options_names[$y],
487 $color2, $options_types[$y],
488 $color3, $around, $value, $around);
489 weechat::print_y($iset_buffer, $y, $strline);
490 }
491 }
492 }
493
494 sub iset_refresh
495 {
496 iset_title();
497 if (($iset_buffer ne "") && ($#options_names >= 0))
498 {
499 foreach my $y (0 .. $#options_names)
500 {
501 iset_refresh_line($y);
502 }
503 }
504
505 weechat::bar_item_update("isetbar_help") if (weechat::config_boolean($options_iset{"show_help_bar"}) == 1);
506 }
507
508 sub iset_full_refresh
509 {
510 $iset_buffer = weechat::buffer_search($LANG, $PRGNAME);
511 if ($iset_buffer ne "")
512 {
513 weechat::buffer_clear($iset_buffer) unless defined $_[0]; # iset_full_refresh(1) does a full refresh without clearing buffer
514 # search for "*" in $filter.
515 if ($filter =~ m/\*/ and $search_mode == 2)
516 {
517 iset_get_options("");
518 }
519 else
520 {
521 if ($search_mode == 0)
522 {
523 $search_value = "=" . $search_value;
524 iset_get_values($search_value);
525 }
526 elsif ($search_mode == 1)
527 {
528 iset_get_values($search_value);
529 }
530 elsif ($search_mode == 3)
531 {
532 iset_create_filter($filter);
533 iset_get_options($search_value);
534 }
535 }
536 if (weechat::config_boolean($options_iset{"show_plugin_description"}) == 1)
537 {
538 iset_set_current_line($current_line);
539 }else
540 {
541 $current_line = $#options_names if ($current_line > $#options_names);
542 }
543 iset_refresh();
544 weechat::command($iset_buffer, "/window refresh");
545 }
546 }
547
548 sub iset_set_current_line
549 {
550 my $new_current_line = $_[0];
551 if ($new_current_line >= 0)
552 {
553 my $old_current_line = $current_line;
554 $current_line = $new_current_line;
555 $current_line = $#options_names if ($current_line > $#options_names);
556 if ($old_current_line != $current_line)
557 {
558 iset_refresh_line($old_current_line);
559 iset_refresh_line($current_line);
560 weechat::bar_item_update("isetbar_help") if (weechat::config_boolean($options_iset{"show_help_bar"}) == 1);
561 }
562 }
563 }
564
565 sub iset_signal_window_scrolled_cb
566 {
567 my ($data, $signal, $signal_data) = ($_[0], $_[1], $_[2]);
568 if ($iset_buffer ne "")
569 {
570 my $infolist = weechat::infolist_get("window", $signal_data, "");
571 if (weechat::infolist_next($infolist))
572 {
573 if (weechat::infolist_pointer($infolist, "buffer") eq $iset_buffer)
574 {
575 my $old_current_line = $current_line;
576 my $new_current_line = $current_line;
577 my $start_line_y = weechat::infolist_integer($infolist, "start_line_y");
578 my $chat_height = weechat::infolist_integer($infolist, "chat_height");
579 $new_current_line += $chat_height if ($new_current_line < $start_line_y);
580 $new_current_line -= $chat_height if ($new_current_line >= $start_line_y + $chat_height);
581 $new_current_line = $start_line_y if ($new_current_line < $start_line_y);
582 $new_current_line = $start_line_y + $chat_height - 1 if ($new_current_line >= $start_line_y + $chat_height);
583 iset_set_current_line($new_current_line);
584 }
585 }
586 weechat::infolist_free($infolist);
587 }
588
589 return weechat::WEECHAT_RC_OK;
590 }
591
592 sub iset_get_window_number
593 {
594 if ($iset_buffer ne "")
595 {
596 my $window = weechat::window_search_with_buffer($iset_buffer);
597 return "-window ".weechat::window_get_integer ($window, "number")." " if ($window ne "");
598 }
599 return "";
600 }
601
602 sub iset_check_line_outside_window
603 {
604 if ($iset_buffer ne "")
605 {
606 undef my $infolist;
607 if ($wee_version_number >= 0x00030500)
608 {
609 my $window = weechat::window_search_with_buffer($iset_buffer);
610 $infolist = weechat::infolist_get("window", $window, "") if $window;
611 }
612 else
613 {
614 $infolist = weechat::infolist_get("window", "", "current");
615 }
616 if ($infolist)
617 {
618 if (weechat::infolist_next($infolist))
619 {
620 my $start_line_y = weechat::infolist_integer($infolist, "start_line_y");
621 my $chat_height = weechat::infolist_integer($infolist, "chat_height");
622 my $window_number = "";
623 if ($wee_version_number >= 0x00030500)
624 {
625 $window_number = "-window ".weechat::infolist_integer($infolist, "number")." ";
626 }
627 if ($start_line_y > $current_line)
628 {
629 weechat::command($iset_buffer, "/window scroll ".$window_number."-".($start_line_y - $current_line));
630 }
631 else
632 {
633 if ($start_line_y <= $current_line - $chat_height)
634 {
635 weechat::command($iset_buffer, "/window scroll ".$window_number."+".($current_line - $start_line_y - $chat_height + 1));
636
637 }
638 }
639 }
640 weechat::infolist_free($infolist);
641 }
642 }
643 }
644
645 sub iset_get_option_name_index
646 {
647 my $option_name = $_[0];
648 my $index = 0;
649 while ($index <= $#options_names)
650 {
651 return -1 if ($options_names[$index] gt $option_name);
652 return $index if ($options_names[$index] eq $option_name);
653 $index++;
654 }
655 return -1;
656 }
657
658 sub iset_config_cb
659 {
660 my ($data, $option_name, $value) = ($_[0], $_[1], $_[2]);
661
662 if ($iset_buffer ne "")
663 {
664 return weechat::WEECHAT_RC_OK if (weechat::info_get("weechat_upgrading", "") eq "1");
665
666 my $index = iset_get_option_name_index($option_name);
667 if ($index >= 0)
668 {
669 # refresh info about changed option
670 my $infolist = weechat::infolist_get("option", "", $option_name);
671 if ($infolist)
672 {
673 weechat::infolist_next($infolist);
674 if (weechat::infolist_fields($infolist))
675 {
676 $options_types[$index] = weechat::infolist_string($infolist, "type");
677 $options_values[$index] = weechat::infolist_string($infolist, "value");
678 $options_is_null[$index] = weechat::infolist_integer($infolist, "value_is_null");
679 iset_refresh_line($index);
680 iset_title() if ($option_name eq "iset.look.show_current_line");
681 }
682 else
683 {
684 iset_full_refresh(1); # if not found, refresh fully without clearing buffer
685 weechat::print_y($iset_buffer, $#options_names + 1, "");
686 }
687 weechat::infolist_free($infolist);
688 }
689 }
690 else
691 {
692 iset_full_refresh() if ($option_name ne "weechat.bar.isetbar.hidden");
693 }
694 }
695
696 return weechat::WEECHAT_RC_OK;
697 }
698
699 sub iset_set_option
700 {
701 my ($option, $value) = ($_[0],$_[1]);
702 if (defined $option and defined $value)
703 {
704 $option = weechat::config_get($option);
705 weechat::config_option_set($option, $value, 1) if ($option ne "");
706 }
707 }
708
709 sub iset_reset_option
710 {
711 my $option = $_[0];
712 if (defined $option)
713 {
714 $option = weechat::config_get($option);
715 weechat::config_option_reset($option, 1) if ($option ne "");
716 }
717 }
718
719 sub iset_unset_option
720 {
721 my $option = $_[0];
722 if (defined $option)
723 {
724 $option = weechat::config_get($option);
725 weechat::config_option_unset($option) if ($option ne "");
726 }
727 }
728
729
730 sub iset_cmd_cb
731 {
732 my ($data, $buffer, $args) = ($_[0], $_[1], $_[2]);
733 my $filter_set = 0;
734 # $search_value = "";
735 if (($args ne "") && (substr($args, 0, 2) ne "**"))
736 {
737 my @cmd_array = split(/ /,$args);
738 my $array_count = @cmd_array;
739 if (substr($args, 0, 1) eq weechat::config_string($options_iset{"value_search_char"})
740 or (defined $cmd_array[0] and $cmd_array[0] eq weechat::config_string($options_iset{"value_search_char"}).weechat::config_string($options_iset{"value_search_char"})) )
741 {
742 $search_mode = 1;
743 my $search_value = substr($args, 1); # cut value_search_char
744 if ($iset_buffer ne "")
745 {
746 weechat::buffer_clear($iset_buffer);
747 weechat::command($iset_buffer, "/window refresh");
748 }
749 weechat::buffer_set($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
750 weechat::buffer_set($iset_buffer, "localvar_set_iset_search_value", $search_value);
751 iset_init();
752 iset_get_values($search_value);
753 iset_refresh();
754 weechat::buffer_set($iset_buffer, "display", "1");
755 # $filter = $var_value;
756 return weechat::WEECHAT_RC_OK;
757 }
758 else
759 {
760 # f/s option =value
761 # option =value
762 $search_mode = 2;
763 if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s")
764 {
765 if ( defined $cmd_array[1] and substr($cmd_array[1], 0, 1) eq weechat::config_string($options_iset{"value_search_char"})
766 or defined $cmd_array[2] and substr($cmd_array[2], 0, 1) eq weechat::config_string($options_iset{"value_search_char"}) )
767 {
768 $search_mode = 3;
769 $search_value = substr($cmd_array[1], 1); # cut value_search_char
770 $search_value = substr($cmd_array[2], 1) if ( $array_count > 2); # cut value_search_char
771 }
772 }
773 iset_create_filter($args);
774 $filter_set = 1;
775 my $ptrbuf = weechat::buffer_search($LANG, $PRGNAME);
776 if ($ptrbuf eq "")
777 {
778 iset_init();
779 iset_get_options($search_value);
780 iset_full_refresh();
781 weechat::buffer_set(weechat::buffer_search($LANG, $PRGNAME), "display", "1");
782 weechat::buffer_set($iset_buffer, "localvar_set_iset_search_value", $search_value);
783 weechat::buffer_set($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
784 return weechat::WEECHAT_RC_OK;
785 }
786 else
787 {
788 iset_get_options($search_value);
789 iset_full_refresh();
790 weechat::buffer_set($ptrbuf, "display", "1");
791 }
792 }
793 weechat::buffer_set($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
794 weechat::buffer_set($iset_buffer, "localvar_set_iset_search_value", $search_value);
795 }
796 if ($iset_buffer eq "")
797 {
798 iset_init();
799 iset_get_options("");
800 iset_refresh();
801 }
802 else
803 {
804 # iset_get_options($search_value);
805 iset_full_refresh() if ($filter_set);
806 }
807
808 if ($args eq "")
809 {
810 weechat::buffer_set($iset_buffer, "display", "1");
811 }
812 else
813 {
814 if ($args eq "**refresh")
815 {
816 iset_full_refresh();
817 }
818 if ($args eq "**up")
819 {
820 if ($current_line > 0)
821 {
822 $current_line--;
823 iset_refresh_line($current_line + 1);
824 iset_refresh_line($current_line);
825 iset_check_line_outside_window();
826 }
827 }
828 if ($args eq "**down")
829 {
830 if ($current_line < $#options_names)
831 {
832 $current_line++;
833 iset_refresh_line($current_line - 1);
834 iset_refresh_line($current_line);
835 iset_check_line_outside_window();
836 }
837 }
838 if ($args eq "**left" && $wee_version_number >= 0x00030600)
839 {
840 weechat::command($iset_buffer, "/window scroll_horiz ".iset_get_window_number()."-".weechat::config_integer($options_iset{"scroll_horiz"})."%");
841 }
842 if ($args eq "**right" && $wee_version_number >= 0x00030600)
843 {
844 weechat::command($iset_buffer, "/window scroll_horiz ".iset_get_window_number().weechat::config_integer($options_iset{"scroll_horiz"})."%");
845 }
846 if ($args eq "**scroll_top")
847 {
848 my $old_current_line = $current_line;
849 $current_line = 0;
850 iset_refresh_line ($old_current_line);
851 iset_refresh_line ($current_line);
852 iset_title();
853 weechat::command($iset_buffer, "/window scroll_top ".iset_get_window_number());
854 }
855 if ($args eq "**scroll_bottom")
856 {
857 my $old_current_line = $current_line;
858 $current_line = $#options_names;
859 iset_refresh_line ($old_current_line);
860 iset_refresh_line ($current_line);
861 iset_title();
862 weechat::command($iset_buffer, "/window scroll_bottom ".iset_get_window_number());
863 }
864 if ($args eq "**toggle")
865 {
866 if ($options_types[$current_line] eq "boolean")
867 {
868 iset_set_option($options_names[$current_line], "toggle");
869 }
870 }
871 if ($args eq "**incr")
872 {
873 if (($options_types[$current_line] eq "integer")
874 || ($options_types[$current_line] eq "color"))
875 {
876 iset_set_option($options_names[$current_line], "++1");
877 }
878 }
879 if ($args eq "**decr")
880 {
881 if (($options_types[$current_line] eq "integer")
882 || ($options_types[$current_line] eq "color"))
883 {
884 iset_set_option($options_names[$current_line], "--1");
885 }
886 }
887 if ($args eq "**reset")
888 {
889 iset_reset_option($options_names[$current_line]);
890 }
891 if ($args eq "**unset")
892 {
893 iset_unset_option($options_names[$current_line]);
894 }
895 if ($args eq "**toggle_help")
896 {
897 if (weechat::config_boolean($options_iset{"show_help_bar"}) == 1)
898 {
899 weechat::config_option_set($options_iset{"show_help_bar"},0,1);
900 iset_show_bar(0);
901 }
902 else
903 {
904 weechat::config_option_set($options_iset{"show_help_bar"},1,1);
905 iset_show_bar(1);
906 }
907 }
908 if ($args eq "**toggle_show_plugin_desc")
909 {
910 if (weechat::config_boolean($options_iset{"show_plugin_description"}) == 1)
911 {
912 weechat::config_option_set($options_iset{"show_plugin_description"},0,1);
913 iset_full_refresh();
914 iset_check_line_outside_window();
915 iset_title();
916 }
917 else
918 {
919 weechat::config_option_set($options_iset{"show_plugin_description"},1,1);
920 iset_full_refresh();
921 iset_check_line_outside_window();
922 iset_title();
923 }
924 }
925 if ($args eq "**set")
926 {
927 my $quote = "";
928 my $value = $options_values[$current_line];
929 if ($options_is_null[$current_line])
930 {
931 $value = "null";
932 }
933 else
934 {
935 $quote = "\"" if ($options_types[$current_line] eq "string");
936 }
937 weechat::buffer_set($iset_buffer, "input", "/set ".$options_names[$current_line]." ".$quote.$value.$quote);
938 weechat::command($iset_buffer, "/input move_beginning_of_line");
939 weechat::command($iset_buffer, "/input move_next_word");
940 weechat::command($iset_buffer, "/input move_next_word");
941 weechat::command($iset_buffer, "/input move_next_char");
942 weechat::command($iset_buffer, "/input move_next_char") if ($quote ne "");
943 }
944 }
945 weechat::bar_item_update("isetbar_help") if (weechat::config_boolean($options_iset{"show_help_bar"}) == 1);
946 return weechat::WEECHAT_RC_OK;
947 }
948
949 sub iset_get_help
950 {
951 my ($redraw) = ($_[0]);
952
953 return '' if (weechat::config_boolean($options_iset{"show_help_bar"}) == 0);
954
955 if (not defined $options_names[$current_line])
956 {
957 return "No option selected. Set a new filter using command line (use '*' to see all options)";
958 }
959 if ($options_name_copy eq $options_names[$current_line] and not defined $redraw)
960 {
961 return $description;
962 }
963 $options_name_copy = $options_names[$current_line];
964 my $optionlist ="";
965 $optionlist = weechat::infolist_get("option", "", $options_names[$current_line]);
966 weechat::infolist_next($optionlist);
967 my $full_name = weechat::infolist_string($optionlist,"full_name");
968 my $option_desc = "";
969 my $option_default_value = "";
970 my $option_range = "";
971 my $possible_values = "";
972 my $re = qq(\Q$full_name);
973 if (grep (/^$re$/,$options_names[$current_line]))
974 {
975 $option_desc = weechat::infolist_string($optionlist, "description_nls");
976 $option_desc = weechat::infolist_string($optionlist, "description") if ($option_desc eq "");
977 $option_desc = "No help found" if ($option_desc eq "");
978 $option_default_value = weechat::infolist_string($optionlist, "default_value");
979 $possible_values = weechat::infolist_string($optionlist, "string_values") if (weechat::infolist_string($optionlist, "string_values") ne "");
980 if ((weechat::infolist_string($optionlist, "type") eq "integer") && ($possible_values eq ""))
981 {
982 $option_range = weechat::infolist_integer($optionlist, "min")
983 ." .. ".weechat::infolist_integer($optionlist, "max");
984 }
985 }
986 weechat::infolist_free($optionlist);
987 iset_title();
988
989 $description = weechat::color(weechat::config_color($options_iset{"color_help_option_name"})).$options_names[$current_line]
990 .weechat::color("bar_fg").": "
991 .weechat::color(weechat::config_color($options_iset{"color_help_text"})).$option_desc;
992
993 # show additional infos like default value and possible values
994
995 if (weechat::config_boolean($options_iset{"show_help_extra_info"}) == 1)
996 {
997 $description .=
998 weechat::color("bar_delim")." ["
999 .weechat::color("bar_fg")."default: "
1000 .weechat::color("bar_delim")."\""
1001 .weechat::color(weechat::config_color($options_iset{"color_help_default_value"})).$option_default_value
1002 .weechat::color("bar_delim")."\"";
1003 if ($option_range ne "")
1004 {
1005 $description .= weechat::color("bar_fg").", values: ".$option_range;
1006 }
1007 if ($possible_values ne "")
1008 {
1009 $possible_values =~ s/\|/", "/g; # replace '|' to '", "'
1010 $description .= weechat::color("bar_fg").", values: ". "\"" . $possible_values . "\"";
1011
1012 }
1013 $description .= weechat::color("bar_delim")."]";
1014 }
1015 return $description;
1016 }
1017
1018 sub iset_check_condition_isetbar_cb
1019 {
1020 my ($data, $modifier, $modifier_data, $string) = ($_[0], $_[1], $_[2], $_[3]);
1021 my $buffer = weechat::window_get_pointer($modifier_data, "buffer");
1022 if ($buffer ne "")
1023 {
1024 if ((weechat::buffer_get_string($buffer, "plugin") eq $LANG)
1025 && (weechat::buffer_get_string($buffer, "name") eq $PRGNAME))
1026 {
1027 return "1";
1028 }
1029 }
1030 return "0";
1031 }
1032
1033 sub iset_show_bar
1034 {
1035 my $show = $_[0];
1036 my $barhidden = weechat::config_get("weechat.bar.isetbar.hidden");
1037 if ($barhidden)
1038 {
1039 if ($show)
1040 {
1041 if (weechat::config_boolean($options_iset{"show_help_bar"}) == 1)
1042 {
1043 if (weechat::config_boolean($barhidden))
1044 {
1045 weechat::config_option_set($barhidden, 0, 1);
1046 }
1047 }
1048 }
1049 else
1050 {
1051 if (!weechat::config_boolean($barhidden))
1052 {
1053 weechat::config_option_set($barhidden, 1, 1);
1054 }
1055 }
1056 }
1057 }
1058
1059 sub iset_signal_buffer_switch_cb
1060 {
1061 my $buffer_pointer = $_[2];
1062 my $show_bar = 0;
1063 $show_bar = 1 if (weechat::buffer_get_integer($iset_buffer, "num_displayed") > 0);
1064 iset_show_bar($show_bar);
1065 iset_check_line_outside_window() if ($buffer_pointer eq $iset_buffer);
1066 return weechat::WEECHAT_RC_OK;
1067 }
1068
1069 sub iset_item_cb
1070 {
1071 return iset_get_help();
1072 }
1073
1074 sub iset_upgrade_ended
1075 {
1076 iset_full_refresh();
1077 }
1078
1079 sub iset_end
1080 {
1081 # when script is unloaded, we hide bar
1082 iset_show_bar(0);
1083 }
1084
1085 # -------------------------------[ mouse support ]-------------------------------------
1086
1087 sub hook_focus_iset_cb
1088 {
1089 my %info = %{$_[1]};
1090 my $bar_item_line = int($info{"_bar_item_line"});
1091 undef my $hash;
1092 if (($info{"_buffer_name"} eq $PRGNAME) && $info{"_buffer_plugin"} eq $LANG && ($bar_item_line >= 0) && ($bar_item_line <= $#iset_focus))
1093 {
1094 $hash = $iset_focus[$bar_item_line];
1095 }
1096 else
1097 {
1098 $hash = {};
1099 my $hash_focus = $iset_focus[0];
1100 foreach my $key (keys %$hash_focus)
1101 {
1102 $hash->{$key} = "?";
1103 }
1104 }
1105 return $hash;
1106 }
1107
1108 # _chat_line_y contains selected line
1109 sub iset_hsignal_mouse_cb
1110 {
1111 my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
1112
1113 if ($hash{"_buffer_name"} eq $PRGNAME && ($hash{"_buffer_plugin"} eq $LANG))
1114 {
1115 if ($hash{"_key"} eq "button1")
1116 {
1117 iset_set_current_line($hash{"_chat_line_y"});
1118 }
1119 elsif ($hash{"_key"} eq "button2")
1120 {
1121 if ($options_types[$hash{"_chat_line_y"}] eq "boolean")
1122 {
1123 iset_set_option($options_names[$hash{"_chat_line_y"}], "toggle");
1124 iset_set_current_line($hash{"_chat_line_y"});
1125 }
1126 elsif ($options_types[$hash{"_chat_line_y"}] eq "string")
1127 {
1128 iset_set_current_line($hash{"_chat_line_y"});
1129 weechat::command("", "/$PRGNAME **set");
1130 }
1131 }
1132 elsif ($hash{"_key"} eq "button2-gesture-left" or $hash{"_key"} eq "button2-gesture-left-long")
1133 {
1134 if ($options_types[$hash{"_chat_line_y"}] eq "integer" or ($options_types[$hash{"_chat_line_y"}] eq "color"))
1135 {
1136 iset_set_current_line($hash{"_chat_line_y"});
1137 my $distance = distance($hash{"_chat_line_x"},$hash{"_chat_line_x2"});
1138 weechat::command("", "/repeat $distance /$PRGNAME **decr");
1139 }
1140 }
1141 elsif ($hash{"_key"} eq "button2-gesture-right" or $hash{"_key"} eq "button2-gesture-right-long")
1142 {
1143 if ($options_types[$hash{"_chat_line_y"}] eq "integer" or ($options_types[$hash{"_chat_line_y"}] eq "color"))
1144 {
1145 iset_set_current_line($hash{"_chat_line_y"});
1146 my $distance = distance($hash{"_chat_line_x"},$hash{"_chat_line_x2"});
1147 weechat::command("", "/repeat $distance /$PRGNAME **incr");
1148 }
1149 }
1150 }
1151 window_switch();
1152 }
1153
1154 sub window_switch
1155 {
1156 my $current_window = weechat::current_window();
1157 my $dest_window = weechat::window_search_with_buffer(weechat::buffer_search("perl","iset"));
1158 return 0 if ($dest_window eq "" or $current_window eq $dest_window);
1159
1160 my $infolist = weechat::infolist_get("window", $dest_window, "");
1161 weechat::infolist_next($infolist);
1162 my $number = weechat::infolist_integer($infolist, "number");
1163 weechat::infolist_free($infolist);
1164 weechat::command("","/window " . $number);
1165 }
1166
1167 sub distance
1168 {
1169 my ($x1,$x2) = ($_[0], $_[1]);
1170 my $distance;
1171 $distance = $x1 - $x2;
1172 $distance = abs($distance);
1173 if ($distance > 0)
1174 {
1175 use integer;
1176 $distance = $distance / 3;
1177 $distance = 1 if ($distance == 0);
1178 }
1179 elsif ($distance == 0)
1180 {
1181 $distance = 1;
1182 }
1183 return $distance;
1184 }
1185
1186 # -----------------------------------[ config ]---------------------------------------
1187
1188 sub iset_config_init
1189 {
1190 $iset_config_file = weechat::config_new($ISET_CONFIG_FILE_NAME,"iset_config_reload_cb","");
1191 return if ($iset_config_file eq "");
1192
1193 # section "color"
1194 my $section_color = weechat::config_new_section($iset_config_file,"color", 0, 0, "", "", "", "", "", "", "", "", "", "");
1195 if ($section_color eq "")
1196 {
1197 weechat::config_free($iset_config_file);
1198 return;
1199 }
1200 $options_iset{"color_option"} = weechat::config_new_option(
1201 $iset_config_file, $section_color,
1202 "option", "color", "Color for option name in iset buffer", "", 0, 0,
1203 "default", "default", 0, "", "", "full_refresh_cb", "", "", "");
1204 $options_iset{"color_option_selected"} = weechat::config_new_option(
1205 $iset_config_file, $section_color,
1206 "option_selected", "color", "Color for selected option name in iset buffer", "", 0, 0,
1207 "white", "white", 0, "", "", "full_refresh_cb", "", "", "");
1208 $options_iset{"color_type"} = weechat::config_new_option(
1209 $iset_config_file, $section_color,
1210 "type", "color", "Color for option type (integer, boolean, string)", "", 0, 0,
1211 "brown", "brown", 0, "", "", "full_refresh_cb", "", "", "");
1212 $options_iset{"color_type_selected"} = weechat::config_new_option(
1213 $iset_config_file, $section_color,
1214 "type_selected", "color", "Color for selected option type (integer, boolean, string)", "", 0, 0,
1215 "yellow", "yellow", 0, "", "", "full_refresh_cb", "", "", "");
1216 $options_iset{"color_value"} = weechat::config_new_option(
1217 $iset_config_file, $section_color,
1218 "value", "color", "Color for option value", "", 0, 0,
1219 "cyan", "cyan", 0, "", "", "full_refresh_cb", "", "", "");
1220 $options_iset{"color_value_selected"} = weechat::config_new_option(
1221 $iset_config_file, $section_color,
1222 "value_selected", "color", "Color for selected option value", "", 0, 0,
1223 "lightcyan", "lightcyan", 0, "", "", "full_refresh_cb", "", "", "");
1224 $options_iset{"color_value_undef"} = weechat::config_new_option(
1225 $iset_config_file, $section_color,
1226 "value_undef", "color", "Color for option value undef", "", 0, 0,
1227 "green", "green", 0, "", "", "full_refresh_cb", "", "", "");
1228 $options_iset{"color_value_undef_selected"} = weechat::config_new_option(
1229 $iset_config_file, $section_color,
1230 "value_undef_selected", "color", "Color for selected option value undef", "", 0, 0,
1231 "lightgreen", "lightgreen", 0, "", "", "full_refresh_cb", "", "", "");
1232 $options_iset{"color_bg_selected"} = weechat::config_new_option(
1233 $iset_config_file, $section_color,
1234 "bg_selected", "color", "Background color for current selected option", "", 0, 0,
1235 "red", "red", 0, "", "", "full_refresh_cb", "", "", "");
1236 $options_iset{"color_help_option_name"} = weechat::config_new_option(
1237 $iset_config_file, $section_color,
1238 "help_option_name", "color", "Color for option name in help-bar", "", 0, 0,
1239 "white", "white", 0, "", "", "bar_refresh", "", "", "");
1240 $options_iset{"color_help_text"} = weechat::config_new_option(
1241 $iset_config_file, $section_color,
1242 "help_text", "color", "Color for option description in help-bar", "", 0, 0,
1243 "default", "default", 0, "", "", "bar_refresh", "", "", "");
1244 $options_iset{"color_help_default_value"} = weechat::config_new_option(
1245 $iset_config_file, $section_color,
1246 "help_default_value", "color", "Color for default option value in help-bar", "", 0, 0,
1247 "green", "green", 0, "", "", "bar_refresh", "", "", "");
1248
1249 # section "help"
1250 my $section_help = weechat::config_new_section($iset_config_file,"help", 0, 0, "", "", "", "", "", "", "", "", "", "");
1251 if ($section_help eq "")
1252 {
1253 weechat::config_free($iset_config_file);
1254 return;
1255 }
1256 $options_iset{"show_help_bar"} = weechat::config_new_option(
1257 $iset_config_file, $section_help,
1258 "show_help_bar", "boolean", "Show help bar", "", 0, 0,
1259 "on", "on", 0, "", "", "toggle_help_cb", "", "", "");
1260 $options_iset{"show_help_extra_info"} = weechat::config_new_option(
1261 $iset_config_file, $section_help,
1262 "show_help_extra_info", "boolean", "Show additional information in help bar (default value, max./min. value) ", "", 0, 0,
1263 "on", "on", 0, "", "", "", "", "", "");
1264 $options_iset{"show_plugin_description"} = weechat::config_new_option(
1265 $iset_config_file, $section_help,
1266 "show_plugin_description", "boolean", "Show plugin description in iset buffer", "", 0, 0,
1267 "off", "off", 0, "", "", "full_refresh_cb", "", "", "");
1268
1269 # section "look"
1270 my $section_look = weechat::config_new_section($iset_config_file, "look", 0, 0, "", "", "", "", "", "", "", "", "", "");
1271 if ($section_look eq "")
1272 {
1273 weechat::config_free($iset_config_file);
1274 return;
1275 }
1276 $options_iset{"value_search_char"} = weechat::config_new_option(
1277 $iset_config_file, $section_look,
1278 "value_search_char", "string", "Trigger char to tell iset to search for value instead of option (for example: =red)", "", 0, 0,
1279 "=", "=", 0, "", "", "", "", "", "");
1280 $options_iset{"scroll_horiz"} = weechat::config_new_option(
1281 $iset_config_file, $section_look,
1282 "scroll_horiz", "integer", "scroll content of iset buffer n%", "", 1, 100,
1283 "10", "10", 0, "", "", "", "", "", "");
1284 $options_iset{"show_current_line"} = weechat::config_new_option(
1285 $iset_config_file, $section_look,
1286 "show_current_line", "boolean", "show current line in title bar.", "", 0, 0,
1287 "on", "on", 0, "", "", "", "", "", "");
1288 }
1289
1290 sub iset_config_reload_cb
1291 {
1292 my ($data,$config_file) = ($_[0], $_[1]);
1293 return weechat::config_reload($config_file)
1294 }
1295
1296 sub iset_config_read
1297 {
1298 return weechat::config_read($iset_config_file) if ($iset_config_file ne "");
1299 }
1300
1301 sub iset_config_write
1302 {
1303 return weechat::config_write($iset_config_file) if ($iset_config_file ne "");
1304 }
1305
1306 sub full_refresh_cb
1307 {
1308 iset_full_refresh();
1309 return weechat::WEECHAT_RC_OK;
1310 }
1311
1312 sub bar_refresh
1313 {
1314 iset_get_help(1);
1315 weechat::bar_item_update("isetbar_help") if (weechat::config_boolean($options_iset{"show_help_bar"}) == 1);
1316 return weechat::WEECHAT_RC_OK;
1317 }
1318
1319 sub toggle_help_cb
1320 {
1321 my $value = weechat::config_boolean($options_iset{"show_help_bar"});
1322 iset_show_bar($value);
1323 return weechat::WEECHAT_RC_OK;
1324 }
1325
1326 # -----------------------------------[ main ]-----------------------------------------
1327
1328 weechat::register($PRGNAME, $AUTHOR, $VERSION, $LICENSE,
1329 $DESCR, "iset_end", "");
1330
1331 $wee_version_number = weechat::info_get("version_number", "") || 0;
1332
1333 iset_config_init();
1334 iset_config_read();
1335
1336 weechat::hook_command($PRGNAME, "Interactive set", "f <file> || s <section> || [=][=]<text>",
1337 "f file : show options for a file\n".
1338 "s section: show options for a section\n".
1339 "text : show options with 'text' in name\n".
1340 weechat::config_string($options_iset{"value_search_char"})."text : show options with 'text' in value\n".
1341 weechat::config_string($options_iset{"value_search_char"}).weechat::config_string($options_iset{"value_search_char"})."text : show options with exact 'text' in value\n\n".
1342 "Keys for iset buffer:\n".
1343 "f11,f12 : move iset content left/right\n".
1344 "up,down : move one option up/down\n".
1345 "pgup,pdwn : move one page up/down\n".
1346 "home,end : move to first/last option\n".
1347 "ctrl+'L' : refresh options and screen\n".
1348 "alt+space : toggle boolean on/off\n".
1349 "alt+'+' : increase value (for integer or color)\n".
1350 "alt+'-' : decrease value (for integer or color)\n".
1351 "alt+'i',alt+'r': reset value of option\n".
1352 "alt+'i',alt+'u': unset option\n".
1353 "alt+enter : set new value for option (edit it with command line)\n".
1354 "text,enter : set a new filter using command line (use '*' to see all options)\n".
1355 "alt+'v' : toggle help bar on/off\n".
1356 "alt+'p' : toggle option \"show_plugin_description\" on/off\n".
1357 "\n".
1358 "Mouse actions:\n".
1359 "wheel up/down : move cursor up/down\n".
1360 "left button : select an option from list\n".
1361 "right button : toggle boolean (on/off) or set a new value for option (edit it with command line)\n".
1362 "right button + drag left/right: increase/decrease value (for integer or color)\n".
1363 "\n".
1364 "Examples:\n".
1365 " show options for file 'weechat'\n".
1366 " /iset f weechat\n".
1367 " show options for file 'irc'\n".
1368 " /iset f irc\n".
1369 " show options for section 'look'\n".
1370 " /iset s look\n".
1371 " show all options with text 'nicklist' in name\n".
1372 " /iset nicklist\n".
1373 " show all values which contain 'red'. ('" . weechat::config_string($options_iset{"value_search_char"}) . "' is a trigger char).\n".
1374 " /iset ". weechat::config_string($options_iset{"value_search_char"}) ."red\n".
1375 " show all values which hit 'off'. ('" . weechat::config_string($options_iset{"value_search_char"}) . weechat::config_string($options_iset{"value_search_char"}) . "' is a trigger char).\n".
1376 " /iset ". weechat::config_string($options_iset{"value_search_char"}) . weechat::config_string($options_iset{"value_search_char"}) ."off\n".
1377 " show options for file 'weechat' which contains value 'off'\n".
1378 " /iset f weechat ".weechat::config_string($options_iset{"value_search_char"})."off\n".
1379 "",
1380 "", "iset_cmd_cb", "");
1381 weechat::hook_signal("upgrade_ended", "iset_upgrade_ended", "");
1382 weechat::hook_signal("window_scrolled", "iset_signal_window_scrolled_cb", "");
1383 weechat::hook_signal("buffer_switch", "iset_signal_buffer_switch_cb","");
1384 weechat::bar_item_new("isetbar_help", "iset_item_cb", "");
1385 weechat::bar_new("isetbar", "on", "0", "window", "", "top", "horizontal",
1386 "vertical", "3", "3", "default", "cyan", "default", "1",
1387 "isetbar_help");
1388 weechat::hook_modifier("bar_condition_isetbar", "iset_check_condition_isetbar_cb", "");
1389 weechat::hook_config("*", "iset_config_cb", "");
1390 $iset_buffer = weechat::buffer_search($LANG, $PRGNAME);
1391 iset_init() if ($iset_buffer ne "");
1392
1393 if ($wee_version_number >= 0x00030600)
1394 {
1395 weechat::hook_focus("chat", "hook_focus_iset_cb", "");
1396 weechat::hook_hsignal($PRGNAME."_mouse", "iset_hsignal_mouse_cb", "");
1397 weechat::key_bind("mouse", \%mouse_keys);
1398 }