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