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