2 # Copyright (C) 2008-2017 Sebastien Helleu <flashcode@flashtux.org>
3 # Copyright (C) 2010-2017 Nils Görs <weechatter@arcor.de>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Set WeeChat and plugins options interactively.
22 # 2017-04-14, nils_2 <freenode.#weechat>
23 # version 4.3: add option "use_color" (https://github.com/weechat/scripts/issues/93)
24 # 2016-07-08, nils_2 <weechatter@arcor.de>
25 # version 4.2: add diff function
26 # 2016-02-06, Sebastien Helleu <flashcode@flashtux.org>:
27 # version 4.1: remove debug print
28 # 2015-12-24, Sebastien Helleu <flashcode@flashtux.org>:
29 # version 4.0: add support of parent options (inherited values in irc servers)
31 # 2015-05-16, Sebastien Helleu <flashcode@flashtux.org>:
32 # version 3.9: fix cursor position when editing an option with WeeChat >= 1.2
33 # 2015-05-02, arza <arza@arza.us>:
34 # version 3.8: don't append "null" to /set when setting an undefined setting
35 # 2015-05-01, nils_2 <weechatter@arcor.de>:
36 # version 3.7: fix two perl warnings (reported by t3chguy)
37 # 2014-09-30, arza <arza@arza.us>:
38 # version 3.6: fix current line counter when options aren't found
39 # 2014-06-03, nils_2 <weechatter@arcor.de>:
40 # version 3.5: add new option "use_mute"
41 # 2014-01-30, stfn <stfnmd@gmail.com>:
42 # version 3.4: add new options "color_value_diff" and "color_value_diff_selected"
43 # 2014-01-16, luz <ne.tetewi@gmail.com>:
44 # version 3.3: fix bug with column alignment in iset buffer when option
45 # name contains unicode characters
46 # 2013-08-03, Sebastien Helleu <flashcode@flashtux.org>:
47 # version 3.2: allow "q" as input in iset buffer to close it
48 # 2013-07-14, Sebastien Helleu <flashcode@flashtux.org>:
49 # version 3.1: remove unneeded calls to iset_refresh() in mouse callback
50 # (faster mouse actions when lot of options are displayed),
51 # fix bug when clicking on a line after the last option displayed
52 # 2013-04-30, arza <arza@arza.us>:
53 # version 3.0: simpler title, fix refresh on unset
54 # 2012-12-16, nils_2 <weechatter@arcor.de>:
55 # version 2.9: fix focus window with iset buffer on mouse click
56 # 2012-08-25, nils_2 <weechatter@arcor.de>:
57 # version 2.8: most important key and mouse bindings for iset buffer added to title-bar (idea The-Compiler)
58 # 2012-07-31, nils_2 <weechatter@arcor.de>:
59 # version 2.7: add combined option and value search (see /help iset)
60 # : add exact value search (see /help iset)
61 # : fix problem with metacharacter in value search
62 # : fix use of uninitialized value for unset option and reset value of option
63 # 2012-07-25, nils_2 <weechatter@arcor.de>:
64 # version 2.6: switch to iset buffer (if existing) when command /iset is called with arguments
65 # 2012-03-17, Sebastien Helleu <flashcode@flashtux.org>:
66 # version 2.5: fix check of sections when creating config file
67 # 2012-03-09, Sebastien Helleu <flashcode@flashtux.org>:
68 # version 2.4: fix reload of config file
69 # 2012-02-02, nils_2 <weechatter@arcor.de>:
70 # version 2.3: fixed: refresh problem with new search results and cursor was outside window.
71 # : add: new option "current_line" in title bar
72 # version 2.2: fixed: refresh error when toggling plugins description
73 # 2011-11-05, nils_2 <weechatter@arcor.de>:
74 # version 2.1: use own config file (iset.conf), fix own help color (used immediately)
75 # 2011-10-16, nils_2 <weechatter@arcor.de>:
76 # version 2.0: add support for left-mouse-button and more sensitive mouse gesture (for integer/color options)
77 # add help text for mouse support
78 # 2011-09-20, Sebastien Helleu <flashcode@flashtux.org>:
79 # version 1.9: add mouse support, fix iset buffer, fix errors on first load under FreeBSD
80 # 2011-07-21, nils_2 <weechatter@arcor.de>:
81 # version 1.8: added: option "show_plugin_description" (alt+p)
82 # fixed: typos in /help iset (lower case for alt+'x' keys)
83 # 2011-05-29, nils_2 <weechatter@arcor.de>:
84 # version 1.7: added: version check for future needs
85 # added: new option (scroll_horiz) and usage of scroll_horiz function (weechat >= 0.3.6 required)
86 # fixed: help_bar did not pop up immediately using key-shortcut
87 # 2011-02-19, nils_2 <weechatter@arcor.de>:
88 # version 1.6: added: display of all possible values in help bar (show_help_extra_info)
89 # fixed: external user options never loaded when starting iset first time
90 # 2011-02-13, Sebastien Helleu <flashcode@flashtux.org>:
91 # version 1.5: use new help format for command arguments
92 # 2011-02-03, nils_2 <weechatter@arcor.de>:
93 # version 1.4: fixed: restore value filter after /upgrade using buffer local variable.
94 # 2011-01-14, nils_2 <weechatter@arcor.de>:
95 # version 1.3: added function to search for values (option value_search_char).
97 # 2010-12-26, Sebastien Helleu <flashcode@flashtux.org>:
98 # version 1.2: improve speed of /upgrade when iset buffer is open,
99 # restore filter used after /upgrade using buffer local variable,
100 # use /iset filter argument if buffer is open.
101 # 2010-11-21, drubin <drubin+weechat@smartcube.co.za>:
102 # version 1.1.1: fix bugs with cursor position
103 # 2010-11-20, nils_2 <weechatter@arcor.de>:
104 # version 1.1: cursor position set to value
105 # 2010-08-03, Sebastien Helleu <flashcode@flashtux.org>:
106 # version 1.0: move misplaced call to infolist_free()
107 # 2010-02-02, rettub <rettub@gmx.net>:
108 # version 0.9: turn all the help stuff off if option 'show_help_bar' is 'off',
109 # new key binding <alt>-<v> to toggle help_bar and help stuff on/off
110 # 2010-01-30, nils_2 <weechatter@arcor.de>:
111 # version 0.8: fix error when option does not exist
112 # 2010-01-24, Sebastien Helleu <flashcode@flashtux.org>:
113 # version 0.7: display iset bar only on iset buffer
114 # 2010-01-22, nils_2 <weechatter@arcor.de> and drubin:
115 # version 0.6: add description in a bar, fix singular/plural bug in title bar,
116 # fix selected line when switching buffer
117 # 2009-06-21, Sebastien Helleu <flashcode@flashtux.org>:
118 # version 0.5: fix bug with iset buffer after /upgrade
119 # 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
120 # version 0.4: sync with last API changes
121 # 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
122 # version 0.3: open iset buffer when /iset command is executed
123 # 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
124 # version 0.2: use null values for options, add colors, fix refresh bugs,
125 # use new keys to reset/unset options, sort options by name,
126 # display number of options in buffer's title
127 # 2008-11-05, Sebastien Helleu <flashcode@flashtux.org>:
128 # version 0.1: first official version
129 # 2008-04-19, Sebastien Helleu <flashcode@flashtux.org>:
134 my $PRGNAME = "iset";
136 my $DESCR = "Interactive Set for configuration options";
137 my $AUTHOR = "Sebastien Helleu <flashcode\@flashtux.org>";
138 my $LICENSE = "GPL3";
140 my $ISET_CONFIG_FILE_NAME = "iset";
142 my $iset_config_file;
143 my $iset_buffer = "";
144 my $wee_version_number = 0;
146 my @options_names = ();
147 my @options_parent_names = ();
148 my @options_types = ();
149 my @options_values = ();
150 my @options_default_values = ();
151 my @options_parent_values = ();
152 my @options_is_null = ();
153 my $option_max_length = 0;
154 my $current_line = 0;
156 my $description = "";
157 my $options_name_copy = "";
158 my $iset_filter_title = "";
159 # search modes: 0 = index() on value, 1 = grep() on value, 2 = grep() on option, 3 = grep on option & value, 4 = diff all, 5 = diff parts
161 my $search_value = "";
162 my $help_text_keys = "alt + space: toggle, +/-: increase/decrease, enter: change, ir: reset, iu: unset, v: toggle help bar";
163 my $help_text_mouse = "Mouse: left: select, right: toggle/set, right + drag left/right: increase/decrease";
166 my %mouse_keys = ("\@chat(perl.$PRGNAME):button1" => "hsignal:iset_mouse",
167 "\@chat(perl.$PRGNAME):button2*" => "hsignal:iset_mouse",
168 "\@chat(perl.$PRGNAME):wheelup" => "/repeat 5 /iset **up",
169 "\@chat(perl.$PRGNAME):wheeldown" => "/repeat 5 /iset **down");
174 if ($iset_buffer ne "")
176 my $current_line_counter = "";
177 if (weechat
::config_boolean
($options_iset{"show_current_line"}) == 1)
179 if (@options_names eq 0)
181 $current_line_counter = "0/";
185 $current_line_counter = ($current_line + 1) . "/";
188 my $show_filter = "";
189 if ($search_mode eq 0)
191 $iset_filter_title = "(value) ";
192 $show_filter = $search_value;
193 if ( substr($show_filter,0,1) eq weechat
::config_string
($options_iset{"value_search_char"}) )
195 $show_filter = substr($show_filter,1,length($show_filter));
198 elsif ($search_mode eq 1)
200 $iset_filter_title = "(value) ";
201 $show_filter = "*".$search_value."*";
203 elsif ($search_mode eq 2)
205 $iset_filter_title = "";
206 $filter = "*" if ($filter eq "");
207 $show_filter = $filter;
209 elsif ($search_mode == 4 or $search_mode == 5)
211 $iset_filter_title = "diff: ";
212 $show_filter = "all";
213 $show_filter = $search_value if $search_mode == 5;
215 elsif ($search_mode eq 3)
217 $iset_filter_title = "(option) ";
218 $show_filter = $filter
219 .weechat
::color
("default")
221 .weechat
::color
("yellow")
222 ."*".$search_value."*";
224 weechat
::buffer_set
($iset_buffer, "title",
226 .weechat
::color
("yellow")
228 .weechat
::color
("default")." | "
229 .$current_line_counter
238 sub iset_create_filter
241 if ( $search_mode == 3 )
243 my @cmd_array = split(/ /,$filter);
244 my $array_count = @cmd_array;
245 $filter = $cmd_array[0];
246 $filter = $cmd_array[0] . " " . $cmd_array[1] if ( $array_count >2 );
248 $filter = "$1.*" if ($filter =~ /f (.*)/); # search file
249 $filter = "*.$1.*" if ($filter =~ /s (.*)/); # search section
250 if ((substr($filter, 0, 1) ne "*") && (substr($filter, -1, 1) ne "*"))
252 $filter = "*".$filter."*";
254 if ($iset_buffer ne "")
256 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_filter", $filter);
260 sub iset_buffer_input
262 my ($data, $buffer, $string) = ($_[0], $_[1], $_[2]);
264 # string begins with space?
265 return weechat
::WEECHAT_RC_OK
if (substr($string, 0, 1 ) eq " ");
269 weechat
::buffer_close
($buffer);
270 return weechat
::WEECHAT_RC_OK
;
273 my @cmd_array = split(/ /,$string);
274 my $array_count = @cmd_array;
275 my $string2 = substr($string, 0, 1);
276 if ($string2 eq weechat
::config_string
($options_iset{"value_search_char"})
277 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"})) )
280 $search_value = substr($string, 1);
281 iset_get_values
($search_value);
282 if ($iset_buffer ne "")
284 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $search_value);
287 # show all diff values
288 elsif ($string eq "d")
292 iset_create_filter
("*");
293 iset_get_options
("*");
295 elsif ( $array_count >= 2 and $cmd_array[0] eq "d")
298 $search_value = substr($cmd_array[1], 0); # cut value_search_char
299 $search_value = substr($cmd_array[2], 0) if ( $array_count > 2); # cut value_search_char
300 iset_create_filter
($search_value);
301 iset_get_options
($search_value);
307 if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s" )
309 if ( defined $cmd_array[1] and substr($cmd_array[1], 0, 1) eq weechat
::config_string
($options_iset{"value_search_char"})
310 or defined $cmd_array[2] and substr($cmd_array[2], 0, 1) eq weechat
::config_string
($options_iset{"value_search_char"}) )
313 $search_value = substr($cmd_array[1], 1); # cut value_search_char
314 $search_value = substr($cmd_array[2], 1) if ( $array_count > 2); # cut value_search_char
317 if ( $search_mode == 3)
319 iset_create_filter
($string);
320 iset_get_options
($search_value);
324 iset_create_filter
($string);
325 iset_get_options
("");
328 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
329 weechat
::buffer_clear
($buffer);
332 return weechat
::WEECHAT_RC_OK
;
335 sub iset_buffer_close
339 return weechat
::WEECHAT_RC_OK
;
345 $iset_buffer = weechat
::buffer_search
($LANG, $PRGNAME);
346 if ($iset_buffer eq "")
348 $iset_buffer = weechat
::buffer_new
($PRGNAME, "iset_buffer_input", "", "iset_buffer_close", "");
352 my $new_filter = weechat
::buffer_get_string
($iset_buffer, "localvar_iset_filter");
353 $search_mode = weechat
::buffer_get_string
($iset_buffer, "localvar_iset_search_mode");
354 $search_value = weechat
::buffer_get_string
($iset_buffer, "localvar_iset_search_value");
355 $filter = $new_filter if ($new_filter ne "");
357 if ($iset_buffer ne "")
359 weechat
::buffer_set
($iset_buffer, "type", "free");
361 weechat
::buffer_set
($iset_buffer, "key_bind_ctrl-L", "/iset **refresh");
362 weechat
::buffer_set
($iset_buffer, "key_bind_meta2-A", "/iset **up");
363 weechat
::buffer_set
($iset_buffer, "key_bind_meta2-B", "/iset **down");
364 weechat
::buffer_set
($iset_buffer, "key_bind_meta2-23~", "/iset **left");
365 weechat
::buffer_set
($iset_buffer, "key_bind_meta2-24~" , "/iset **right");
366 weechat
::buffer_set
($iset_buffer, "key_bind_meta- ", "/iset **toggle");
367 weechat
::buffer_set
($iset_buffer, "key_bind_meta-+", "/iset **incr");
368 weechat
::buffer_set
($iset_buffer, "key_bind_meta--", "/iset **decr");
369 weechat
::buffer_set
($iset_buffer, "key_bind_meta-imeta-r", "/iset **reset");
370 weechat
::buffer_set
($iset_buffer, "key_bind_meta-imeta-u", "/iset **unset");
371 weechat
::buffer_set
($iset_buffer, "key_bind_meta-ctrl-J", "/iset **set");
372 weechat
::buffer_set
($iset_buffer, "key_bind_meta-ctrl-M", "/iset **set");
373 weechat
::buffer_set
($iset_buffer, "key_bind_meta-meta2-1~", "/iset **scroll_top");
374 weechat
::buffer_set
($iset_buffer, "key_bind_meta-meta2-4~", "/iset **scroll_bottom");
375 weechat
::buffer_set
($iset_buffer, "key_bind_meta-v", "/iset **toggle_help");
376 weechat
::buffer_set
($iset_buffer, "key_bind_meta-p", "/iset **toggle_show_plugin_desc");
377 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_filter", $filter);
378 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
379 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $search_value);
385 my $var_value = $_[0];
386 $var_value = "" if (not defined $var_value);
387 $var_value = lc($var_value);
388 $search_value = $var_value;
391 @options_parent_names = ();
393 @options_values = ();
394 @options_default_values = ();
395 @options_parent_values = ();
396 @options_is_null = ();
397 $option_max_length = 0;
398 my %options_internal = ();
404 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $var_value) if ($search_mode == 3);
406 my $infolist = weechat
::infolist_get
("option", "", $filter);
407 while (weechat
::infolist_next
($infolist))
409 $key = sprintf("%08d", $i);
410 my $name = weechat
::infolist_string
($infolist, "full_name");
411 my $parent_name = weechat
::infolist_string
($infolist, "parent_name");
412 next if (weechat
::config_boolean
($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1);
413 my $type = weechat
::infolist_string
($infolist, "type");
414 my $value = weechat
::infolist_string
($infolist, "value");
415 my $default_value = weechat
::infolist_string
($infolist, "default_value");
417 if ($parent_name && (($wee_version_number < 0x00040300) || (weechat
::infolist_search_var
($infolist, "parent_value"))))
419 $parent_value = weechat
::infolist_string
($infolist, "parent_value");
421 my $is_null = weechat
::infolist_integer
($infolist, "value_is_null");
423 if ($search_mode == 3)
425 my $value = weechat
::infolist_string
($infolist, "value");
426 if ( grep /\Q$var_value/,lc($value) )
428 $options_internal{$name}{"parent_name"} = $parent_name;
429 $options_internal{$name}{"type"} = $type;
430 $options_internal{$name}{"value"} = $value;
431 $options_internal{$name}{"default_value"} = $default_value;
432 $options_internal{$name}{"parent_value"} = $parent_value;
433 $options_internal{$name}{"is_null"} = $is_null;
434 $option_max_length = length($name) if (length($name) > $option_max_length);
435 $iset_struct{$key} = $options_internal{$name};
436 push(@iset_focus, $iset_struct{$key});
440 elsif ( $search_mode == 4 or $search_mode == 5)
442 if ($value ne $default_value )
444 $options_internal{$name}{"parent_name"} = $parent_name;
445 $options_internal{$name}{"type"} = $type;
446 $options_internal{$name}{"value"} = $value;
447 $options_internal{$name}{"default_value"} = $default_value;
448 $options_internal{$name}{"parent_value"} = $parent_value;
449 $options_internal{$name}{"is_null"} = $is_null;
450 $option_max_length = length($name) if (length($name) > $option_max_length);
451 $iset_struct{$key} = $options_internal{$name};
452 push(@iset_focus, $iset_struct{$key});
457 $options_internal{$name}{"parent_name"} = $parent_name;
458 $options_internal{$name}{"type"} = $type;
459 $options_internal{$name}{"value"} = $value;
460 $options_internal{$name}{"default_value"} = $default_value;
461 $options_internal{$name}{"parent_value"} = $parent_value;
462 $options_internal{$name}{"is_null"} = $is_null;
463 $option_max_length = length($name) if (length($name) > $option_max_length);
464 $iset_struct{$key} = $options_internal{$name};
465 push(@iset_focus, $iset_struct{$key});
469 weechat
::infolist_free
($infolist);
471 foreach my $name (sort keys %options_internal)
473 push(@options_names, $name);
474 push(@options_parent_names, $options_internal{$name}{"parent_name"});
475 push(@options_types, $options_internal{$name}{"type"});
476 push(@options_values, $options_internal{$name}{"value"});
477 push(@options_default_values, $options_internal{$name}{"default_value"});
478 push(@options_parent_values, $options_internal{$name}{"parent_value"});
479 push(@options_is_null, $options_internal{$name}{"is_null"});
485 my $var_value = $_[0];
486 $var_value = lc($var_value);
487 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"}))
489 $var_value = substr($var_value,1,length($var_value));
492 iset_search_values
($var_value,$search_mode);
493 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
494 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $var_value);
495 $search_value = $var_value;
497 sub iset_search_values
499 my ($var_value,$search_mode) = ($_[0],$_[1]);
501 @options_parent_names = ();
503 @options_values = ();
504 @options_default_values = ();
505 @options_parent_values = ();
506 @options_is_null = ();
507 $option_max_length = 0;
508 my %options_internal = ();
510 my $infolist = weechat
::infolist_get
("option", "", "*");
511 while (weechat
::infolist_next
($infolist))
513 my $name = weechat
::infolist_string
($infolist, "full_name");
514 my $parent_name = weechat
::infolist_string
($infolist, "parent_name");
515 next if (weechat
::config_boolean
($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1);
516 my $type = weechat
::infolist_string
($infolist, "type");
517 my $is_null = weechat
::infolist_integer
($infolist, "value_is_null");
518 my $value = weechat
::infolist_string
($infolist, "value");
519 my $default_value = weechat
::infolist_string
($infolist, "default_value");
521 if ($parent_name && (($wee_version_number < 0x00040300) || (weechat
::infolist_search_var
($infolist, "parent_value"))))
523 $parent_value = weechat
::infolist_string
($infolist, "parent_value");
527 if ( grep /\Q$var_value/,lc($value) )
529 $options_internal{$name}{"parent_name"} = $parent_name;
530 $options_internal{$name}{"type"} = $type;
531 $options_internal{$name}{"value"} = $value;
532 $options_internal{$name}{"default_value"} = $default_value;
533 $options_internal{$name}{"parent_value"} = $parent_value;
534 $options_internal{$name}{"is_null"} = $is_null;
535 $option_max_length = length($name) if (length($name) > $option_max_length);
540 # if ($value =~ /\Q$var_value/si)
541 if (lc($value) eq $var_value)
543 $options_internal{$name}{"parent_name"} = $parent_name;
544 $options_internal{$name}{"type"} = $type;
545 $options_internal{$name}{"value"} = $value;
546 $options_internal{$name}{"default_value"} = $default_value;
547 $options_internal{$name}{"parent_value"} = $parent_value;
548 $options_internal{$name}{"is_null"} = $is_null;
549 $option_max_length = length($name) if (length($name) > $option_max_length);
554 weechat
::infolist_free
($infolist);
555 foreach my $name (sort keys %options_internal)
557 push(@options_names, $name);
558 push(@options_parent_names, $options_internal{$name}{"parent_name"});
559 push(@options_types, $options_internal{$name}{"type"});
560 push(@options_values, $options_internal{$name}{"value"});
561 push(@options_default_values, $options_internal{$name}{"default_value"});
562 push(@options_parent_values, $options_internal{$name}{"parent_value"});
563 push(@options_is_null, $options_internal{$name}{"is_null"});
567 sub iset_refresh_line
569 if ($iset_buffer ne "")
572 if ($y <= $#options_names)
574 return if (! defined($options_types[$y]));
575 my $format = sprintf("%%s%%s%%s %%s %%-7s %%s %%s%%s%%s");
577 if ($wee_version_number >= 0x00040200)
579 $padding = " " x
($option_max_length - weechat
::strlen_screen
($options_names[$y]));
583 $padding = " " x
($option_max_length - length($options_names[$y]));
586 $around = "\"" if ((!$options_is_null[$y]) && ($options_types[$y] eq "string"));
588 my $color1 = weechat
::color
(weechat
::config_color
($options_iset{"color_option"}));
589 my $color2 = weechat
::color
(weechat
::config_color
($options_iset{"color_type"}));
592 if ($options_is_null[$y])
594 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_undef"}));
595 $color4 = weechat
::color
(weechat
::config_color
($options_iset{"color_value"}));
597 elsif ($options_values[$y] ne $options_default_values[$y])
599 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_diff"}));
603 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value"}));
605 if ($y == $current_line)
607 $color1 = weechat
::color
(weechat
::config_color
($options_iset{"color_option_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
608 $color2 = weechat
::color
(weechat
::config_color
($options_iset{"color_type_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
609 if ($options_is_null[$y])
611 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_undef_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
612 $color4 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
614 elsif ($options_values[$y] ne $options_default_values[$y])
616 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_diff_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
620 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
623 my $value = $options_values[$y];
624 if (weechat
::config_boolean
($options_iset{"use_color"}) == 1 and $options_types[$y] eq "color")
626 $value = weechat
::color
($options_values[$y]) . $options_values[$y];
628 if ($options_is_null[$y])
631 if ($options_parent_names[$y])
633 if (defined $options_parent_values[$y])
635 my $around_parent = "";
636 $around_parent = "\"" if ($options_types[$y] eq "string");
637 $value .= $color1." -> ".$color4.$around_parent.$options_parent_values[$y].$around_parent;
641 $value .= $color1." -> ".$color3."null";
645 my $strline = sprintf($format,
646 $color1, $options_names[$y], $padding,
647 $color2, $options_types[$y],
648 $color3, $around, $value, $around);
649 weechat
::print_y
($iset_buffer, $y, $strline);
657 if (($iset_buffer ne "") && ($#options_names >= 0))
659 foreach my $y (0 .. $#options_names)
661 iset_refresh_line
($y);
665 weechat
::bar_item_update
("isetbar_help") if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1);
668 sub iset_full_refresh
670 $iset_buffer = weechat
::buffer_search
($LANG, $PRGNAME);
671 if ($iset_buffer ne "")
673 weechat
::buffer_clear
($iset_buffer) unless defined $_[0]; # iset_full_refresh(1) does a full refresh without clearing buffer
674 # search for "*" in $filter.
675 if ($filter =~ m/\*/ and $search_mode == 2)
677 iset_get_options
("");
681 if ($search_mode == 0)
683 $search_value = "=" . $search_value;
684 iset_get_values
($search_value);
686 elsif ($search_mode == 1)
688 iset_get_values
($search_value);
690 elsif ($search_mode == 3)
692 iset_create_filter
($filter);
693 iset_get_options
($search_value);
696 if (weechat
::config_boolean
($options_iset{"show_plugin_description"}) == 1)
698 iset_set_current_line
($current_line);
701 $current_line = $#options_names if ($current_line > $#options_names);
704 weechat
::command
($iset_buffer, "/window refresh");
708 sub iset_set_current_line
710 my $new_current_line = $_[0];
711 if ($new_current_line >= 0)
713 my $old_current_line = $current_line;
714 $current_line = $new_current_line;
715 $current_line = $#options_names if ($current_line > $#options_names);
716 if ($old_current_line != $current_line)
718 iset_refresh_line
($old_current_line);
719 iset_refresh_line
($current_line);
720 weechat
::bar_item_update
("isetbar_help") if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1);
725 sub iset_signal_window_scrolled_cb
727 my ($data, $signal, $signal_data) = ($_[0], $_[1], $_[2]);
728 if ($iset_buffer ne "")
730 my $infolist = weechat
::infolist_get
("window", $signal_data, "");
731 if (weechat
::infolist_next
($infolist))
733 if (weechat
::infolist_pointer
($infolist, "buffer") eq $iset_buffer)
735 my $old_current_line = $current_line;
736 my $new_current_line = $current_line;
737 my $start_line_y = weechat
::infolist_integer
($infolist, "start_line_y");
738 my $chat_height = weechat
::infolist_integer
($infolist, "chat_height");
739 $new_current_line += $chat_height if ($new_current_line < $start_line_y);
740 $new_current_line -= $chat_height if ($new_current_line >= $start_line_y + $chat_height);
741 $new_current_line = $start_line_y if ($new_current_line < $start_line_y);
742 $new_current_line = $start_line_y + $chat_height - 1 if ($new_current_line >= $start_line_y + $chat_height);
743 iset_set_current_line
($new_current_line);
746 weechat
::infolist_free
($infolist);
749 return weechat
::WEECHAT_RC_OK
;
752 sub iset_get_window_number
754 if ($iset_buffer ne "")
756 my $window = weechat
::window_search_with_buffer
($iset_buffer);
757 return "-window ".weechat
::window_get_integer
($window, "number")." " if ($window ne "");
762 sub iset_check_line_outside_window
764 if ($iset_buffer ne "")
767 if ($wee_version_number >= 0x00030500)
769 my $window = weechat
::window_search_with_buffer
($iset_buffer);
770 $infolist = weechat
::infolist_get
("window", $window, "") if $window;
774 $infolist = weechat
::infolist_get
("window", "", "current");
778 if (weechat
::infolist_next
($infolist))
780 my $start_line_y = weechat
::infolist_integer
($infolist, "start_line_y");
781 my $chat_height = weechat
::infolist_integer
($infolist, "chat_height");
782 my $window_number = "";
783 if ($wee_version_number >= 0x00030500)
785 $window_number = "-window ".weechat
::infolist_integer
($infolist, "number")." ";
787 if ($start_line_y > $current_line)
789 weechat
::command
($iset_buffer, "/window scroll ".$window_number."-".($start_line_y - $current_line));
793 if ($start_line_y <= $current_line - $chat_height)
795 weechat
::command
($iset_buffer, "/window scroll ".$window_number."+".($current_line - $start_line_y - $chat_height + 1));
800 weechat
::infolist_free
($infolist);
805 sub iset_get_option_name_index
807 my $option_name = $_[0];
809 while ($index <= $#options_names)
811 return -1 if ($options_names[$index] gt $option_name);
812 return $index if ($options_names[$index] eq $option_name);
818 sub iset_refresh_option
820 my $option_name = $_[0];
822 my $infolist = weechat
::infolist_get
("option", "", $option_name);
825 weechat
::infolist_next
($infolist);
826 if (weechat
::infolist_fields
($infolist))
828 $options_parent_names[$index] = weechat
::infolist_string
($infolist, "parent_name");
829 $options_types[$index] = weechat
::infolist_string
($infolist, "type");
830 $options_values[$index] = weechat
::infolist_string
($infolist, "value");
831 $options_default_values[$index] = weechat
::infolist_string
($infolist, "default_value");
832 $options_is_null[$index] = weechat
::infolist_integer
($infolist, "value_is_null");
833 $options_parent_values[$index] = undef;
834 if ($options_parent_names[$index]
835 && (($wee_version_number < 0x00040300) || (weechat
::infolist_search_var
($infolist, "parent_value"))))
837 $options_parent_values[$index] = weechat
::infolist_string
($infolist, "parent_value");
839 iset_refresh_line
($index);
840 iset_title
() if ($option_name eq "iset.look.show_current_line");
844 iset_full_refresh
(1); # if not found, refresh fully without clearing buffer
845 weechat
::print_y
($iset_buffer, $#options_names + 1, "");
847 weechat
::infolist_free
($infolist);
853 my ($data, $option_name, $value) = ($_[0], $_[1], $_[2]);
855 if ($iset_buffer ne "")
857 return weechat
::WEECHAT_RC_OK
if (weechat
::info_get
("weechat_upgrading", "") eq "1");
859 my $index = iset_get_option_name_index
($option_name);
862 # refresh info about changed option
863 iset_refresh_option
($option_name, $index);
864 # refresh any other option having this changed option as parent
865 foreach my $i (0 .. $#options_names)
867 if ($options_parent_names[$i] eq $option_name)
869 iset_refresh_option
($options_names[$i], $i);
875 iset_full_refresh
() if ($option_name ne "weechat.bar.isetbar.hidden");
879 return weechat
::WEECHAT_RC_OK
;
884 my ($option, $value) = ($_[0],$_[1]);
885 if (defined $option and defined $value)
887 $option = weechat
::config_get
($option);
888 weechat
::config_option_set
($option, $value, 1) if ($option ne "");
892 sub iset_reset_option
897 $option = weechat
::config_get
($option);
898 weechat
::config_option_reset
($option, 1) if ($option ne "");
902 sub iset_unset_option
907 $option = weechat
::config_get
($option);
908 weechat
::config_option_unset
($option) if ($option ne "");
915 my ($data, $buffer, $args) = ($_[0], $_[1], $_[2]);
917 # $search_value = "";
918 if (($args ne "") && (substr($args, 0, 2) ne "**"))
920 my @cmd_array = split(/ /,$args);
921 my $array_count = @cmd_array;
922 if (substr($args, 0, 1) eq weechat
::config_string
($options_iset{"value_search_char"})
923 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"})) )
926 my $search_value = substr($args, 1); # cut value_search_char
927 if ($iset_buffer ne "")
929 weechat
::buffer_clear
($iset_buffer);
930 weechat
::command
($iset_buffer, "/window refresh");
932 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
933 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $search_value);
935 iset_get_values
($search_value);
937 weechat
::buffer_set
($iset_buffer, "display", "1");
938 # $filter = $var_value;
939 return weechat
::WEECHAT_RC_OK
;
945 $search_mode = 2; # grep on option
946 if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s")
948 if ( defined $cmd_array[1] and substr($cmd_array[1], 0, 1) eq weechat
::config_string
($options_iset{"value_search_char"})
949 or defined $cmd_array[2] and substr($cmd_array[2], 0, 1) eq weechat
::config_string
($options_iset{"value_search_char"}) )
951 $search_mode = 3; # grep on option and value
952 $search_value = substr($cmd_array[1], 1); # cut value_search_char
953 $search_value = substr($cmd_array[2], 1) if ( $array_count > 2); # cut value_search_char
957 # show all diff values
962 $args = $search_value;
964 if ( $array_count >= 2 and $cmd_array[0] eq "d")
967 $search_value = substr($cmd_array[1], 0); # cut value_search_char
968 $search_value = substr($cmd_array[2], 0) if ( $array_count > 2); # cut value_search_char
969 $args = $search_value;
972 iset_create_filter
($args);
974 my $ptrbuf = weechat
::buffer_search
($LANG, $PRGNAME);
979 iset_get_options
($search_value);
981 weechat
::buffer_set
(weechat
::buffer_search
($LANG, $PRGNAME), "display", "1");
982 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $search_value);
983 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
984 return weechat
::WEECHAT_RC_OK
;
988 iset_get_options
($search_value);
990 weechat
::buffer_set
($ptrbuf, "display", "1");
993 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
994 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $search_value);
996 if ($iset_buffer eq "")
999 iset_get_options
("");
1004 # iset_get_options($search_value);
1005 iset_full_refresh
() if ($filter_set);
1010 weechat
::buffer_set
($iset_buffer, "display", "1");
1014 if ($args eq "**refresh")
1016 iset_full_refresh
();
1018 if ($args eq "**up")
1020 if ($current_line > 0)
1023 iset_refresh_line
($current_line + 1);
1024 iset_refresh_line
($current_line);
1025 iset_check_line_outside_window
();
1028 if ($args eq "**down")
1030 if ($current_line < $#options_names)
1033 iset_refresh_line
($current_line - 1);
1034 iset_refresh_line
($current_line);
1035 iset_check_line_outside_window
();
1038 if ($args eq "**left" && $wee_version_number >= 0x00030600)
1040 weechat
::command
($iset_buffer, "/window scroll_horiz ".iset_get_window_number
()."-".weechat
::config_integer
($options_iset{"scroll_horiz"})."%");
1042 if ($args eq "**right" && $wee_version_number >= 0x00030600)
1044 weechat
::command
($iset_buffer, "/window scroll_horiz ".iset_get_window_number
().weechat
::config_integer
($options_iset{"scroll_horiz"})."%");
1046 if ($args eq "**scroll_top")
1048 my $old_current_line = $current_line;
1050 iset_refresh_line
($old_current_line);
1051 iset_refresh_line
($current_line);
1053 weechat
::command
($iset_buffer, "/window scroll_top ".iset_get_window_number
());
1055 if ($args eq "**scroll_bottom")
1057 my $old_current_line = $current_line;
1058 $current_line = $#options_names;
1059 iset_refresh_line
($old_current_line);
1060 iset_refresh_line
($current_line);
1062 weechat
::command
($iset_buffer, "/window scroll_bottom ".iset_get_window_number
());
1064 if ($args eq "**toggle")
1066 if ($options_types[$current_line] eq "boolean")
1068 iset_set_option
($options_names[$current_line], "toggle");
1071 if ($args eq "**incr")
1073 if (($options_types[$current_line] eq "integer")
1074 || ($options_types[$current_line] eq "color"))
1076 iset_set_option
($options_names[$current_line], "++1");
1079 if ($args eq "**decr")
1081 if (($options_types[$current_line] eq "integer")
1082 || ($options_types[$current_line] eq "color"))
1084 iset_set_option
($options_names[$current_line], "--1");
1087 if ($args eq "**reset")
1089 iset_reset_option
($options_names[$current_line]);
1091 if ($args eq "**unset")
1093 iset_unset_option
($options_names[$current_line]);
1095 if ($args eq "**toggle_help")
1097 if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1)
1099 weechat
::config_option_set
($options_iset{"show_help_bar"},0,1);
1104 weechat
::config_option_set
($options_iset{"show_help_bar"},1,1);
1108 if ($args eq "**toggle_show_plugin_desc")
1110 if (weechat
::config_boolean
($options_iset{"show_plugin_description"}) == 1)
1112 weechat
::config_option_set
($options_iset{"show_plugin_description"},0,1);
1113 iset_full_refresh
();
1114 iset_check_line_outside_window
();
1119 weechat
::config_option_set
($options_iset{"show_plugin_description"},1,1);
1120 iset_full_refresh
();
1121 iset_check_line_outside_window
();
1125 if ($args eq "**set")
1128 my $value = $options_values[$current_line];
1129 if ($options_is_null[$current_line])
1135 $quote = "\"" if ($options_types[$current_line] eq "string");
1137 $value = " ".$quote.$value.$quote if ($value ne "" or $quote ne "");
1139 my $set_command = "/set";
1140 my $start_index = 5;
1141 if (weechat
::config_boolean
($options_iset{"use_mute"}) == 1)
1143 $set_command = "/mute ".$set_command;
1146 $set_command = $set_command." ".$options_names[$current_line].$value;
1147 my $pos_space = index($set_command, " ", $start_index);
1154 $pos_space = $pos_space + 1;
1155 $pos_space = $pos_space + 1 if ($quote ne "");
1157 weechat
::buffer_set
($iset_buffer, "input", $set_command);
1158 weechat
::buffer_set
($iset_buffer, "input_pos", "".$pos_space);
1161 weechat
::bar_item_update
("isetbar_help") if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1);
1162 return weechat
::WEECHAT_RC_OK
;
1167 my ($redraw) = ($_[0]);
1169 return '' if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 0);
1171 if (not defined $options_names[$current_line])
1173 return "No option selected. Set a new filter using command line (use '*' to see all options)";
1175 if ($options_name_copy eq $options_names[$current_line] and not defined $redraw)
1177 return $description;
1179 $options_name_copy = $options_names[$current_line];
1181 $optionlist = weechat
::infolist_get
("option", "", $options_names[$current_line]);
1182 weechat
::infolist_next
($optionlist);
1183 my $full_name = weechat
::infolist_string
($optionlist,"full_name");
1184 my $option_desc = "";
1185 my $option_default_value = "";
1186 my $option_range = "";
1187 my $possible_values = "";
1188 my $re = qq(\Q$full_name);
1189 if (grep (/^$re$/,$options_names[$current_line]))
1191 $option_desc = weechat
::infolist_string
($optionlist, "description_nls");
1192 $option_desc = weechat
::infolist_string
($optionlist, "description") if ($option_desc eq "");
1193 $option_desc = "No help found" if ($option_desc eq "");
1194 $option_default_value = weechat
::infolist_string
($optionlist, "default_value");
1195 $possible_values = weechat
::infolist_string
($optionlist, "string_values") if (weechat
::infolist_string
($optionlist, "string_values") ne "");
1196 if ((weechat
::infolist_string
($optionlist, "type") eq "integer") && ($possible_values eq ""))
1198 $option_range = weechat
::infolist_integer
($optionlist, "min")
1199 ." .. ".weechat
::infolist_integer
($optionlist, "max");
1202 weechat
::infolist_free
($optionlist);
1205 $description = weechat
::color
(weechat
::config_color
($options_iset{"color_help_option_name"})).$options_names[$current_line]
1206 .weechat
::color
("bar_fg").": "
1207 .weechat
::color
(weechat
::config_color
($options_iset{"color_help_text"})).$option_desc;
1209 # show additional infos like default value and possible values
1211 if (weechat
::config_boolean
($options_iset{"show_help_extra_info"}) == 1)
1214 weechat
::color
("bar_delim")." ["
1215 .weechat
::color
("bar_fg")."default: "
1216 .weechat
::color
("bar_delim")."\""
1217 .weechat
::color
(weechat
::config_color
($options_iset{"color_help_default_value"})).$option_default_value
1218 .weechat
::color
("bar_delim")."\"";
1219 if ($option_range ne "")
1221 $description .= weechat
::color
("bar_fg").", values: ".$option_range;
1223 if ($possible_values ne "")
1225 $possible_values =~ s/\|/", "/g; # replace '|' to '", "'
1226 $description .= weechat
::color
("bar_fg").", values: ". "\"" . $possible_values . "\"";
1229 $description .= weechat
::color
("bar_delim")."]";
1231 return $description;
1234 sub iset_check_condition_isetbar_cb
1236 my ($data, $modifier, $modifier_data, $string) = ($_[0], $_[1], $_[2], $_[3]);
1237 my $buffer = weechat
::window_get_pointer
($modifier_data, "buffer");
1240 if ((weechat
::buffer_get_string
($buffer, "plugin") eq $LANG)
1241 && (weechat
::buffer_get_string
($buffer, "name") eq $PRGNAME))
1252 my $barhidden = weechat
::config_get
("weechat.bar.isetbar.hidden");
1257 if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1)
1259 if (weechat
::config_boolean
($barhidden))
1261 weechat
::config_option_set
($barhidden, 0, 1);
1267 if (!weechat
::config_boolean
($barhidden))
1269 weechat
::config_option_set
($barhidden, 1, 1);
1275 sub iset_signal_buffer_switch_cb
1277 my $buffer_pointer = $_[2];
1279 $show_bar = 1 if (weechat
::buffer_get_integer
($iset_buffer, "num_displayed") > 0);
1280 iset_show_bar
($show_bar);
1281 iset_check_line_outside_window
() if ($buffer_pointer eq $iset_buffer);
1282 return weechat
::WEECHAT_RC_OK
;
1287 return iset_get_help
();
1290 sub iset_upgrade_ended
1292 iset_full_refresh
();
1297 # when script is unloaded, we hide bar
1301 # -------------------------------[ mouse support ]-------------------------------------
1303 sub hook_focus_iset_cb
1305 my %info = %{$_[1]};
1306 my $bar_item_line = int($info{"_bar_item_line"});
1308 if (($info{"_buffer_name"} eq $PRGNAME) && $info{"_buffer_plugin"} eq $LANG && ($bar_item_line >= 0) && ($bar_item_line <= $#iset_focus))
1310 $hash = $iset_focus[$bar_item_line];
1315 my $hash_focus = $iset_focus[0];
1316 foreach my $key (keys %$hash_focus)
1318 $hash->{$key} = "?";
1324 # _chat_line_y contains selected line
1325 sub iset_hsignal_mouse_cb
1327 my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
1329 return weechat
::WEECHAT_RC_OK
unless (@options_types);
1331 if ($hash{"_buffer_name"} eq $PRGNAME && ($hash{"_buffer_plugin"} eq $LANG))
1333 if ($hash{"_key"} eq "button1")
1335 iset_set_current_line
($hash{"_chat_line_y"});
1337 elsif ($hash{"_key"} eq "button2")
1339 if ($options_types[$hash{"_chat_line_y"}] eq "boolean")
1341 iset_set_option
($options_names[$hash{"_chat_line_y"}], "toggle");
1342 iset_set_current_line
($hash{"_chat_line_y"});
1344 elsif ($options_types[$hash{"_chat_line_y"}] eq "string")
1346 iset_set_current_line
($hash{"_chat_line_y"});
1347 weechat
::command
("", "/$PRGNAME **set");
1350 elsif ($hash{"_key"} eq "button2-gesture-left" or $hash{"_key"} eq "button2-gesture-left-long")
1352 if ($options_types[$hash{"_chat_line_y"}] eq "integer" or ($options_types[$hash{"_chat_line_y"}] eq "color"))
1354 iset_set_current_line
($hash{"_chat_line_y"});
1355 my $distance = distance
($hash{"_chat_line_x"},$hash{"_chat_line_x2"});
1356 weechat
::command
("", "/repeat $distance /$PRGNAME **decr");
1359 elsif ($hash{"_key"} eq "button2-gesture-right" or $hash{"_key"} eq "button2-gesture-right-long")
1361 if ($options_types[$hash{"_chat_line_y"}] eq "integer" or ($options_types[$hash{"_chat_line_y"}] eq "color"))
1363 iset_set_current_line
($hash{"_chat_line_y"});
1364 my $distance = distance
($hash{"_chat_line_x"},$hash{"_chat_line_x2"});
1365 weechat
::command
("", "/repeat $distance /$PRGNAME **incr");
1374 my $current_window = weechat
::current_window
();
1375 my $dest_window = weechat
::window_search_with_buffer
(weechat
::buffer_search
("perl","iset"));
1376 return 0 if ($dest_window eq "" or $current_window eq $dest_window);
1378 my $infolist = weechat
::infolist_get
("window", $dest_window, "");
1379 weechat
::infolist_next
($infolist);
1380 my $number = weechat
::infolist_integer
($infolist, "number");
1381 weechat
::infolist_free
($infolist);
1382 weechat
::command
("","/window " . $number);
1387 my ($x1,$x2) = ($_[0], $_[1]);
1389 $distance = $x1 - $x2;
1390 $distance = abs($distance);
1394 $distance = $distance / 3;
1395 $distance = 1 if ($distance == 0);
1397 elsif ($distance == 0)
1404 # -----------------------------------[ config ]---------------------------------------
1406 sub iset_config_init
1408 $iset_config_file = weechat
::config_new
($ISET_CONFIG_FILE_NAME,"iset_config_reload_cb","");
1409 return if ($iset_config_file eq "");
1412 my $section_color = weechat
::config_new_section
($iset_config_file,"color", 0, 0, "", "", "", "", "", "", "", "", "", "");
1413 if ($section_color eq "")
1415 weechat
::config_free
($iset_config_file);
1418 $options_iset{"color_option"} = weechat
::config_new_option
(
1419 $iset_config_file, $section_color,
1420 "option", "color", "Color for option name in iset buffer", "", 0, 0,
1421 "default", "default", 0, "", "", "full_refresh_cb", "", "", "");
1422 $options_iset{"color_option_selected"} = weechat
::config_new_option
(
1423 $iset_config_file, $section_color,
1424 "option_selected", "color", "Color for selected option name in iset buffer", "", 0, 0,
1425 "white", "white", 0, "", "", "full_refresh_cb", "", "", "");
1426 $options_iset{"color_type"} = weechat
::config_new_option
(
1427 $iset_config_file, $section_color,
1428 "type", "color", "Color for option type (integer, boolean, string)", "", 0, 0,
1429 "brown", "brown", 0, "", "", "full_refresh_cb", "", "", "");
1430 $options_iset{"color_type_selected"} = weechat
::config_new_option
(
1431 $iset_config_file, $section_color,
1432 "type_selected", "color", "Color for selected option type (integer, boolean, string)", "", 0, 0,
1433 "yellow", "yellow", 0, "", "", "full_refresh_cb", "", "", "");
1434 $options_iset{"color_value"} = weechat
::config_new_option
(
1435 $iset_config_file, $section_color,
1436 "value", "color", "Color for option value", "", 0, 0,
1437 "cyan", "cyan", 0, "", "", "full_refresh_cb", "", "", "");
1438 $options_iset{"color_value_selected"} = weechat
::config_new_option
(
1439 $iset_config_file, $section_color,
1440 "value_selected", "color", "Color for selected option value", "", 0, 0,
1441 "lightcyan", "lightcyan", 0, "", "", "full_refresh_cb", "", "", "");
1442 $options_iset{"color_value_diff"} = weechat
::config_new_option
(
1443 $iset_config_file, $section_color,
1444 "value_diff", "color", "Color for option value different from default", "", 0, 0,
1445 "magenta", "magenta", 0, "", "", "full_refresh_cb", "", "", "");
1446 $options_iset{"color_value_diff_selected"} = weechat
::config_new_option
(
1447 $iset_config_file, $section_color,
1448 "value_diff_selected", "color", "Color for selected option value different from default", "", 0, 0,
1449 "lightmagenta", "lightmagenta", 0, "", "", "full_refresh_cb", "", "", "");
1450 $options_iset{"color_value_undef"} = weechat
::config_new_option
(
1451 $iset_config_file, $section_color,
1452 "value_undef", "color", "Color for option value undef", "", 0, 0,
1453 "green", "green", 0, "", "", "full_refresh_cb", "", "", "");
1454 $options_iset{"color_value_undef_selected"} = weechat
::config_new_option
(
1455 $iset_config_file, $section_color,
1456 "value_undef_selected", "color", "Color for selected option value undef", "", 0, 0,
1457 "lightgreen", "lightgreen", 0, "", "", "full_refresh_cb", "", "", "");
1458 $options_iset{"color_bg_selected"} = weechat
::config_new_option
(
1459 $iset_config_file, $section_color,
1460 "bg_selected", "color", "Background color for current selected option", "", 0, 0,
1461 "red", "red", 0, "", "", "full_refresh_cb", "", "", "");
1462 $options_iset{"color_help_option_name"} = weechat
::config_new_option
(
1463 $iset_config_file, $section_color,
1464 "help_option_name", "color", "Color for option name in help-bar", "", 0, 0,
1465 "white", "white", 0, "", "", "bar_refresh", "", "", "");
1466 $options_iset{"color_help_text"} = weechat
::config_new_option
(
1467 $iset_config_file, $section_color,
1468 "help_text", "color", "Color for option description in help-bar", "", 0, 0,
1469 "default", "default", 0, "", "", "bar_refresh", "", "", "");
1470 $options_iset{"color_help_default_value"} = weechat
::config_new_option
(
1471 $iset_config_file, $section_color,
1472 "help_default_value", "color", "Color for default option value in help-bar", "", 0, 0,
1473 "green", "green", 0, "", "", "bar_refresh", "", "", "");
1476 my $section_help = weechat
::config_new_section
($iset_config_file,"help", 0, 0, "", "", "", "", "", "", "", "", "", "");
1477 if ($section_help eq "")
1479 weechat
::config_free
($iset_config_file);
1482 $options_iset{"show_help_bar"} = weechat
::config_new_option
(
1483 $iset_config_file, $section_help,
1484 "show_help_bar", "boolean", "Show help bar", "", 0, 0,
1485 "on", "on", 0, "", "", "toggle_help_cb", "", "", "");
1486 $options_iset{"show_help_extra_info"} = weechat
::config_new_option
(
1487 $iset_config_file, $section_help,
1488 "show_help_extra_info", "boolean", "Show additional information in help bar (default value, max./min. value) ", "", 0, 0,
1489 "on", "on", 0, "", "", "", "", "", "");
1490 $options_iset{"show_plugin_description"} = weechat
::config_new_option
(
1491 $iset_config_file, $section_help,
1492 "show_plugin_description", "boolean", "Show plugin description in iset buffer", "", 0, 0,
1493 "off", "off", 0, "", "", "full_refresh_cb", "", "", "");
1496 my $section_look = weechat
::config_new_section
($iset_config_file, "look", 0, 0, "", "", "", "", "", "", "", "", "", "");
1497 if ($section_look eq "")
1499 weechat
::config_free
($iset_config_file);
1502 $options_iset{"value_search_char"} = weechat
::config_new_option
(
1503 $iset_config_file, $section_look,
1504 "value_search_char", "string", "Trigger char to tell iset to search for value instead of option (for example: =red)", "", 0, 0,
1505 "=", "=", 0, "", "", "", "", "", "");
1506 $options_iset{"scroll_horiz"} = weechat
::config_new_option
(
1507 $iset_config_file, $section_look,
1508 "scroll_horiz", "integer", "scroll content of iset buffer n%", "", 1, 100,
1509 "10", "10", 0, "", "", "", "", "", "");
1510 $options_iset{"show_current_line"} = weechat
::config_new_option
(
1511 $iset_config_file, $section_look,
1512 "show_current_line", "boolean", "show current line in title bar.", "", 0, 0,
1513 "on", "on", 0, "", "", "", "", "", "");
1514 $options_iset{"use_mute"} = weechat
::config_new_option
(
1515 $iset_config_file, $section_look,
1516 "use_mute", "boolean", "/mute command will be used in input bar", "", 0, 0,
1517 "off", "off", 0, "", "", "", "", "", "");
1518 $options_iset{"use_color"} = weechat
::config_new_option
(
1519 $iset_config_file, $section_look,
1520 "use_color", "boolean", "display the color value in the corresponding color", "", 0, 0,
1521 "off", "off", 0, "", "", "full_refresh_cb", "", "", "");
1524 sub iset_config_reload_cb
1526 my ($data,$config_file) = ($_[0], $_[1]);
1527 return weechat
::config_reload
($config_file)
1530 sub iset_config_read
1532 return weechat
::config_read
($iset_config_file) if ($iset_config_file ne "");
1535 sub iset_config_write
1537 return weechat
::config_write
($iset_config_file) if ($iset_config_file ne "");
1542 iset_full_refresh
();
1543 return weechat
::WEECHAT_RC_OK
;
1549 weechat
::bar_item_update
("isetbar_help") if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1);
1550 return weechat
::WEECHAT_RC_OK
;
1555 my $value = weechat
::config_boolean
($options_iset{"show_help_bar"});
1556 iset_show_bar
($value);
1557 return weechat
::WEECHAT_RC_OK
;
1560 # -----------------------------------[ main ]-----------------------------------------
1562 weechat
::register
($PRGNAME, $AUTHOR, $VERSION, $LICENSE,
1563 $DESCR, "iset_end", "");
1565 $wee_version_number = weechat
::info_get
("version_number", "") || 0;
1570 weechat
::hook_command
($PRGNAME, "Interactive set", "d <text> || f <file> || s <section> || [=][=]<text>",
1571 "d <text> : show only changed options\n".
1572 "f file : show options for a file\n".
1573 "s section: show options for a section\n".
1574 "text : show options with 'text' in name\n".
1575 weechat
::config_string
($options_iset{"value_search_char"})."text : show options with 'text' in value\n".
1576 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".
1577 "Keys for iset buffer:\n".
1578 "f11,f12 : move iset content left/right\n".
1579 "up,down : move one option up/down\n".
1580 "pgup,pdwn : move one page up/down\n".
1581 "home,end : move to first/last option\n".
1582 "ctrl+'L' : refresh options and screen\n".
1583 "alt+space : toggle boolean on/off\n".
1584 "alt+'+' : increase value (for integer or color)\n".
1585 "alt+'-' : decrease value (for integer or color)\n".
1586 "alt+'i',alt+'r': reset value of option\n".
1587 "alt+'i',alt+'u': unset option\n".
1588 "alt+enter : set new value for option (edit it with command line)\n".
1589 "text,enter : set a new filter using command line (use '*' to see all options)\n".
1590 "alt+'v' : toggle help bar on/off\n".
1591 "alt+'p' : toggle option \"show_plugin_description\" on/off\n".
1592 "q : as input in iset buffer to close it\n".
1595 "wheel up/down : move cursor up/down\n".
1596 "left button : select an option from list\n".
1597 "right button : toggle boolean (on/off) or set a new value for option (edit it with command line)\n".
1598 "right button + drag left/right: increase/decrease value (for integer or color)\n".
1601 " show changed options in 'aspell' plugin\n".
1602 " /iset d aspell\n".
1603 " show options for file 'irc'\n".
1605 " show options for section 'look'\n".
1607 " show all options with text 'nicklist' in name\n".
1608 " /iset nicklist\n".
1609 " show all values which contain 'red'. ('" . weechat
::config_string
($options_iset{"value_search_char"}) . "' is a trigger char).\n".
1610 " /iset ". weechat
::config_string
($options_iset{"value_search_char"}) ."red\n".
1611 " 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".
1612 " /iset ". weechat
::config_string
($options_iset{"value_search_char"}) . weechat
::config_string
($options_iset{"value_search_char"}) ."off\n".
1613 " show options for file 'weechat' which contains value 'off'\n".
1614 " /iset f weechat ".weechat
::config_string
($options_iset{"value_search_char"})."off\n".
1616 "", "iset_cmd_cb", "");
1617 weechat
::hook_signal
("upgrade_ended", "iset_upgrade_ended", "");
1618 weechat
::hook_signal
("window_scrolled", "iset_signal_window_scrolled_cb", "");
1619 weechat
::hook_signal
("buffer_switch", "iset_signal_buffer_switch_cb","");
1620 weechat
::bar_item_new
("isetbar_help", "iset_item_cb", "");
1621 weechat
::bar_new
("isetbar", "on", "0", "window", "", "top", "horizontal",
1622 "vertical", "3", "3", "default", "cyan", "default", "1",
1624 weechat
::hook_modifier
("bar_condition_isetbar", "iset_check_condition_isetbar_cb", "");
1625 weechat
::hook_config
("*", "iset_config_cb", "");
1626 $iset_buffer = weechat
::buffer_search
($LANG, $PRGNAME);
1627 iset_init
() if ($iset_buffer ne "");
1629 if ($wee_version_number >= 0x00030600)
1631 weechat
::hook_focus
("chat", "hook_focus_iset_cb", "");
1632 weechat
::hook_hsignal
($PRGNAME."_mouse", "iset_hsignal_mouse_cb", "");
1633 weechat
::key_bind
("mouse", \
%mouse_keys);