2 # Copyright (C) 2008-2014 Sebastien Helleu <flashcode@flashtux.org>
3 # Copyright (C) 2010-2015 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 # 2016-07-08, nils_2 <weechatter@arcor.de>
23 # version 4.2: add diff function
24 # 2016-02-06, Sebastien Helleu <flashcode@flashtux.org>:
25 # version 4.1: remove debug print
26 # 2015-12-24, Sebastien Helleu <flashcode@flashtux.org>:
27 # version 4.0: add support of parent options (inherited values in irc servers)
29 # 2015-05-16, Sebastien Helleu <flashcode@flashtux.org>:
30 # version 3.9: fix cursor position when editing an option with WeeChat >= 1.2
31 # 2015-05-02, arza <arza@arza.us>:
32 # version 3.8: don't append "null" to /set when setting an undefined setting
33 # 2015-05-01, nils_2 <weechatter@arcor.de>:
34 # version 3.7: fix two perl warnings (reported by t3chguy)
35 # 2014-09-30, arza <arza@arza.us>:
36 # version 3.6: fix current line counter when options aren't found
37 # 2014-06-03, nils_2 <weechatter@arcor.de>:
38 # version 3.5: add new option "use_mute"
39 # 2014-01-30, stfn <stfnmd@gmail.com>:
40 # version 3.4: add new options "color_value_diff" and "color_value_diff_selected"
41 # 2014-01-16, luz <ne.tetewi@gmail.com>:
42 # version 3.3: fix bug with column alignment in iset buffer when option
43 # name contains unicode characters
44 # 2013-08-03, Sebastien Helleu <flashcode@flashtux.org>:
45 # version 3.2: allow "q" as input in iset buffer to close it
46 # 2013-07-14, Sebastien Helleu <flashcode@flashtux.org>:
47 # version 3.1: remove unneeded calls to iset_refresh() in mouse callback
48 # (faster mouse actions when lot of options are displayed),
49 # fix bug when clicking on a line after the last option displayed
50 # 2013-04-30, arza <arza@arza.us>:
51 # version 3.0: simpler title, fix refresh on unset
52 # 2012-12-16, nils_2 <weechatter@arcor.de>:
53 # version 2.9: fix focus window with iset buffer on mouse click
54 # 2012-08-25, nils_2 <weechatter@arcor.de>:
55 # version 2.8: most important key and mouse bindings for iset buffer added to title-bar (idea The-Compiler)
56 # 2012-07-31, nils_2 <weechatter@arcor.de>:
57 # version 2.7: add combined option and value search (see /help iset)
58 # : add exact value search (see /help iset)
59 # : fix problem with metacharacter in value search
60 # : fix use of uninitialized value for unset option and reset value of option
61 # 2012-07-25, nils_2 <weechatter@arcor.de>:
62 # version 2.6: switch to iset buffer (if existing) when command /iset is called with arguments
63 # 2012-03-17, Sebastien Helleu <flashcode@flashtux.org>:
64 # version 2.5: fix check of sections when creating config file
65 # 2012-03-09, Sebastien Helleu <flashcode@flashtux.org>:
66 # version 2.4: fix reload of config file
67 # 2012-02-02, nils_2 <weechatter@arcor.de>:
68 # version 2.3: fixed: refresh problem with new search results and cursor was outside window.
69 # : add: new option "current_line" in title bar
70 # version 2.2: fixed: refresh error when toggling plugins description
71 # 2011-11-05, nils_2 <weechatter@arcor.de>:
72 # version 2.1: use own config file (iset.conf), fix own help color (used immediately)
73 # 2011-10-16, nils_2 <weechatter@arcor.de>:
74 # version 2.0: add support for left-mouse-button and more sensitive mouse gesture (for integer/color options)
75 # add help text for mouse support
76 # 2011-09-20, Sebastien Helleu <flashcode@flashtux.org>:
77 # version 1.9: add mouse support, fix iset buffer, fix errors on first load under FreeBSD
78 # 2011-07-21, nils_2 <weechatter@arcor.de>:
79 # version 1.8: added: option "show_plugin_description" (alt+p)
80 # fixed: typos in /help iset (lower case for alt+'x' keys)
81 # 2011-05-29, nils_2 <weechatter@arcor.de>:
82 # version 1.7: added: version check for future needs
83 # added: new option (scroll_horiz) and usage of scroll_horiz function (weechat >= 0.3.6 required)
84 # fixed: help_bar did not pop up immediately using key-shortcut
85 # 2011-02-19, nils_2 <weechatter@arcor.de>:
86 # version 1.6: added: display of all possible values in help bar (show_help_extra_info)
87 # fixed: external user options never loaded when starting iset first time
88 # 2011-02-13, Sebastien Helleu <flashcode@flashtux.org>:
89 # version 1.5: use new help format for command arguments
90 # 2011-02-03, nils_2 <weechatter@arcor.de>:
91 # version 1.4: fixed: restore value filter after /upgrade using buffer local variable.
92 # 2011-01-14, nils_2 <weechatter@arcor.de>:
93 # version 1.3: added function to search for values (option value_search_char).
95 # 2010-12-26, Sebastien Helleu <flashcode@flashtux.org>:
96 # version 1.2: improve speed of /upgrade when iset buffer is open,
97 # restore filter used after /upgrade using buffer local variable,
98 # use /iset filter argument if buffer is open.
99 # 2010-11-21, drubin <drubin+weechat@smartcube.co.za>:
100 # version 1.1.1: fix bugs with cursor position
101 # 2010-11-20, nils_2 <weechatter@arcor.de>:
102 # version 1.1: cursor position set to value
103 # 2010-08-03, Sebastien Helleu <flashcode@flashtux.org>:
104 # version 1.0: move misplaced call to infolist_free()
105 # 2010-02-02, rettub <rettub@gmx.net>:
106 # version 0.9: turn all the help stuff off if option 'show_help_bar' is 'off',
107 # new key binding <alt>-<v> to toggle help_bar and help stuff on/off
108 # 2010-01-30, nils_2 <weechatter@arcor.de>:
109 # version 0.8: fix error when option does not exist
110 # 2010-01-24, Sebastien Helleu <flashcode@flashtux.org>:
111 # version 0.7: display iset bar only on iset buffer
112 # 2010-01-22, nils_2 <weechatter@arcor.de> and drubin:
113 # version 0.6: add description in a bar, fix singular/plural bug in title bar,
114 # fix selected line when switching buffer
115 # 2009-06-21, Sebastien Helleu <flashcode@flashtux.org>:
116 # version 0.5: fix bug with iset buffer after /upgrade
117 # 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
118 # version 0.4: sync with last API changes
119 # 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
120 # version 0.3: open iset buffer when /iset command is executed
121 # 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
122 # version 0.2: use null values for options, add colors, fix refresh bugs,
123 # use new keys to reset/unset options, sort options by name,
124 # display number of options in buffer's title
125 # 2008-11-05, Sebastien Helleu <flashcode@flashtux.org>:
126 # version 0.1: first official version
127 # 2008-04-19, Sebastien Helleu <flashcode@flashtux.org>:
132 my $PRGNAME = "iset";
134 my $DESCR = "Interactive Set for configuration options";
135 my $AUTHOR = "Sebastien Helleu <flashcode\@flashtux.org>";
136 my $LICENSE = "GPL3";
138 my $ISET_CONFIG_FILE_NAME = "iset";
140 my $iset_config_file;
141 my $iset_buffer = "";
142 my $wee_version_number = 0;
144 my @options_names = ();
145 my @options_parent_names = ();
146 my @options_types = ();
147 my @options_values = ();
148 my @options_default_values = ();
149 my @options_parent_values = ();
150 my @options_is_null = ();
151 my $option_max_length = 0;
152 my $current_line = 0;
154 my $description = "";
155 my $options_name_copy = "";
156 my $iset_filter_title = "";
157 # 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
159 my $search_value = "";
160 my $help_text_keys = "alt + space: toggle, +/-: increase/decrease, enter: change, ir: reset, iu: unset, v: toggle help bar";
161 my $help_text_mouse = "Mouse: left: select, right: toggle/set, right + drag left/right: increase/decrease";
164 my %mouse_keys = ("\@chat(perl.$PRGNAME):button1" => "hsignal:iset_mouse",
165 "\@chat(perl.$PRGNAME):button2*" => "hsignal:iset_mouse",
166 "\@chat(perl.$PRGNAME):wheelup" => "/repeat 5 /iset **up",
167 "\@chat(perl.$PRGNAME):wheeldown" => "/repeat 5 /iset **down");
172 if ($iset_buffer ne "")
174 my $current_line_counter = "";
175 if (weechat
::config_boolean
($options_iset{"show_current_line"}) == 1)
177 if (@options_names eq 0)
179 $current_line_counter = "0/";
183 $current_line_counter = ($current_line + 1) . "/";
186 my $show_filter = "";
187 if ($search_mode eq 0)
189 $iset_filter_title = "(value) ";
190 $show_filter = $search_value;
191 if ( substr($show_filter,0,1) eq weechat
::config_string
($options_iset{"value_search_char"}) )
193 $show_filter = substr($show_filter,1,length($show_filter));
196 elsif ($search_mode eq 1)
198 $iset_filter_title = "(value) ";
199 $show_filter = "*".$search_value."*";
201 elsif ($search_mode eq 2)
203 $iset_filter_title = "";
204 $filter = "*" if ($filter eq "");
205 $show_filter = $filter;
207 elsif ($search_mode == 4 or $search_mode == 5)
209 $iset_filter_title = "diff: ";
210 $show_filter = "all";
211 $show_filter = $search_value if $search_mode == 5;
213 elsif ($search_mode eq 3)
215 $iset_filter_title = "(option) ";
216 $show_filter = $filter
217 .weechat
::color
("default")
219 .weechat
::color
("yellow")
220 ."*".$search_value."*";
222 weechat
::buffer_set
($iset_buffer, "title",
224 .weechat
::color
("yellow")
226 .weechat
::color
("default")." | "
227 .$current_line_counter
236 sub iset_create_filter
239 if ( $search_mode == 3 )
241 my @cmd_array = split(/ /,$filter);
242 my $array_count = @cmd_array;
243 $filter = $cmd_array[0];
244 $filter = $cmd_array[0] . " " . $cmd_array[1] if ( $array_count >2 );
246 $filter = "$1.*" if ($filter =~ /f (.*)/); # search file
247 $filter = "*.$1.*" if ($filter =~ /s (.*)/); # search section
248 if ((substr($filter, 0, 1) ne "*") && (substr($filter, -1, 1) ne "*"))
250 $filter = "*".$filter."*";
252 if ($iset_buffer ne "")
254 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_filter", $filter);
258 sub iset_buffer_input
260 my ($data, $buffer, $string) = ($_[0], $_[1], $_[2]);
262 # string begins with space?
263 return weechat
::WEECHAT_RC_OK
if (substr($string, 0, 1 ) eq " ");
267 weechat
::buffer_close
($buffer);
268 return weechat
::WEECHAT_RC_OK
;
271 my @cmd_array = split(/ /,$string);
272 my $array_count = @cmd_array;
273 my $string2 = substr($string, 0, 1);
274 if ($string2 eq weechat
::config_string
($options_iset{"value_search_char"})
275 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"})) )
278 $search_value = substr($string, 1);
279 iset_get_values
($search_value);
280 if ($iset_buffer ne "")
282 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $search_value);
285 # show all diff values
286 elsif ($string eq "d")
290 iset_create_filter
("*");
291 iset_get_options
("*");
293 elsif ( $array_count >= 2 and $cmd_array[0] eq "d")
296 $search_value = substr($cmd_array[1], 0); # cut value_search_char
297 $search_value = substr($cmd_array[2], 0) if ( $array_count > 2); # cut value_search_char
298 iset_create_filter
($search_value);
299 iset_get_options
($search_value);
305 if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s" )
307 if ( defined $cmd_array[1] and substr($cmd_array[1], 0, 1) eq weechat
::config_string
($options_iset{"value_search_char"})
308 or defined $cmd_array[2] and substr($cmd_array[2], 0, 1) eq weechat
::config_string
($options_iset{"value_search_char"}) )
311 $search_value = substr($cmd_array[1], 1); # cut value_search_char
312 $search_value = substr($cmd_array[2], 1) if ( $array_count > 2); # cut value_search_char
315 if ( $search_mode == 3)
317 iset_create_filter
($string);
318 iset_get_options
($search_value);
322 iset_create_filter
($string);
323 iset_get_options
("");
326 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
327 weechat
::buffer_clear
($buffer);
330 return weechat
::WEECHAT_RC_OK
;
333 sub iset_buffer_close
337 return weechat
::WEECHAT_RC_OK
;
343 $iset_buffer = weechat
::buffer_search
($LANG, $PRGNAME);
344 if ($iset_buffer eq "")
346 $iset_buffer = weechat
::buffer_new
($PRGNAME, "iset_buffer_input", "", "iset_buffer_close", "");
350 my $new_filter = weechat
::buffer_get_string
($iset_buffer, "localvar_iset_filter");
351 $search_mode = weechat
::buffer_get_string
($iset_buffer, "localvar_iset_search_mode");
352 $search_value = weechat
::buffer_get_string
($iset_buffer, "localvar_iset_search_value");
353 $filter = $new_filter if ($new_filter ne "");
355 if ($iset_buffer ne "")
357 weechat
::buffer_set
($iset_buffer, "type", "free");
359 weechat
::buffer_set
($iset_buffer, "key_bind_ctrl-L", "/iset **refresh");
360 weechat
::buffer_set
($iset_buffer, "key_bind_meta2-A", "/iset **up");
361 weechat
::buffer_set
($iset_buffer, "key_bind_meta2-B", "/iset **down");
362 weechat
::buffer_set
($iset_buffer, "key_bind_meta2-23~", "/iset **left");
363 weechat
::buffer_set
($iset_buffer, "key_bind_meta2-24~" , "/iset **right");
364 weechat
::buffer_set
($iset_buffer, "key_bind_meta- ", "/iset **toggle");
365 weechat
::buffer_set
($iset_buffer, "key_bind_meta-+", "/iset **incr");
366 weechat
::buffer_set
($iset_buffer, "key_bind_meta--", "/iset **decr");
367 weechat
::buffer_set
($iset_buffer, "key_bind_meta-imeta-r", "/iset **reset");
368 weechat
::buffer_set
($iset_buffer, "key_bind_meta-imeta-u", "/iset **unset");
369 weechat
::buffer_set
($iset_buffer, "key_bind_meta-ctrl-J", "/iset **set");
370 weechat
::buffer_set
($iset_buffer, "key_bind_meta-ctrl-M", "/iset **set");
371 weechat
::buffer_set
($iset_buffer, "key_bind_meta-meta2-1~", "/iset **scroll_top");
372 weechat
::buffer_set
($iset_buffer, "key_bind_meta-meta2-4~", "/iset **scroll_bottom");
373 weechat
::buffer_set
($iset_buffer, "key_bind_meta-v", "/iset **toggle_help");
374 weechat
::buffer_set
($iset_buffer, "key_bind_meta-p", "/iset **toggle_show_plugin_desc");
375 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_filter", $filter);
376 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
377 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $search_value);
383 my $var_value = $_[0];
384 $var_value = "" if (not defined $var_value);
385 $var_value = lc($var_value);
386 $search_value = $var_value;
389 @options_parent_names = ();
391 @options_values = ();
392 @options_default_values = ();
393 @options_parent_values = ();
394 @options_is_null = ();
395 $option_max_length = 0;
396 my %options_internal = ();
402 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $var_value) if ($search_mode == 3);
404 my $infolist = weechat
::infolist_get
("option", "", $filter);
405 while (weechat
::infolist_next
($infolist))
407 $key = sprintf("%08d", $i);
408 my $name = weechat
::infolist_string
($infolist, "full_name");
409 my $parent_name = weechat
::infolist_string
($infolist, "parent_name");
410 next if (weechat
::config_boolean
($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1);
411 my $type = weechat
::infolist_string
($infolist, "type");
412 my $value = weechat
::infolist_string
($infolist, "value");
413 my $default_value = weechat
::infolist_string
($infolist, "default_value");
415 if ($parent_name && (($wee_version_number < 0x00040300) || (weechat
::infolist_search_var
($infolist, "parent_value"))))
417 $parent_value = weechat
::infolist_string
($infolist, "parent_value");
419 my $is_null = weechat
::infolist_integer
($infolist, "value_is_null");
421 if ($search_mode == 3)
423 my $value = weechat
::infolist_string
($infolist, "value");
424 if ( grep /\Q$var_value/,lc($value) )
426 $options_internal{$name}{"parent_name"} = $parent_name;
427 $options_internal{$name}{"type"} = $type;
428 $options_internal{$name}{"value"} = $value;
429 $options_internal{$name}{"default_value"} = $default_value;
430 $options_internal{$name}{"parent_value"} = $parent_value;
431 $options_internal{$name}{"is_null"} = $is_null;
432 $option_max_length = length($name) if (length($name) > $option_max_length);
433 $iset_struct{$key} = $options_internal{$name};
434 push(@iset_focus, $iset_struct{$key});
438 elsif ( $search_mode == 4 or $search_mode == 5)
440 if ($value ne $default_value )
442 $options_internal{$name}{"parent_name"} = $parent_name;
443 $options_internal{$name}{"type"} = $type;
444 $options_internal{$name}{"value"} = $value;
445 $options_internal{$name}{"default_value"} = $default_value;
446 $options_internal{$name}{"parent_value"} = $parent_value;
447 $options_internal{$name}{"is_null"} = $is_null;
448 $option_max_length = length($name) if (length($name) > $option_max_length);
449 $iset_struct{$key} = $options_internal{$name};
450 push(@iset_focus, $iset_struct{$key});
455 $options_internal{$name}{"parent_name"} = $parent_name;
456 $options_internal{$name}{"type"} = $type;
457 $options_internal{$name}{"value"} = $value;
458 $options_internal{$name}{"default_value"} = $default_value;
459 $options_internal{$name}{"parent_value"} = $parent_value;
460 $options_internal{$name}{"is_null"} = $is_null;
461 $option_max_length = length($name) if (length($name) > $option_max_length);
462 $iset_struct{$key} = $options_internal{$name};
463 push(@iset_focus, $iset_struct{$key});
467 weechat
::infolist_free
($infolist);
469 foreach my $name (sort keys %options_internal)
471 push(@options_names, $name);
472 push(@options_parent_names, $options_internal{$name}{"parent_name"});
473 push(@options_types, $options_internal{$name}{"type"});
474 push(@options_values, $options_internal{$name}{"value"});
475 push(@options_default_values, $options_internal{$name}{"default_value"});
476 push(@options_parent_values, $options_internal{$name}{"parent_value"});
477 push(@options_is_null, $options_internal{$name}{"is_null"});
483 my $var_value = $_[0];
484 $var_value = lc($var_value);
485 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"}))
487 $var_value = substr($var_value,1,length($var_value));
490 iset_search_values
($var_value,$search_mode);
491 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
492 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $var_value);
493 $search_value = $var_value;
495 sub iset_search_values
497 my ($var_value,$search_mode) = ($_[0],$_[1]);
499 @options_parent_names = ();
501 @options_values = ();
502 @options_default_values = ();
503 @options_parent_values = ();
504 @options_is_null = ();
505 $option_max_length = 0;
506 my %options_internal = ();
508 my $infolist = weechat
::infolist_get
("option", "", "*");
509 while (weechat
::infolist_next
($infolist))
511 my $name = weechat
::infolist_string
($infolist, "full_name");
512 my $parent_name = weechat
::infolist_string
($infolist, "parent_name");
513 next if (weechat
::config_boolean
($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1);
514 my $type = weechat
::infolist_string
($infolist, "type");
515 my $is_null = weechat
::infolist_integer
($infolist, "value_is_null");
516 my $value = weechat
::infolist_string
($infolist, "value");
517 my $default_value = weechat
::infolist_string
($infolist, "default_value");
519 if ($parent_name && (($wee_version_number < 0x00040300) || (weechat
::infolist_search_var
($infolist, "parent_value"))))
521 $parent_value = weechat
::infolist_string
($infolist, "parent_value");
525 if ( grep /\Q$var_value/,lc($value) )
527 $options_internal{$name}{"parent_name"} = $parent_name;
528 $options_internal{$name}{"type"} = $type;
529 $options_internal{$name}{"value"} = $value;
530 $options_internal{$name}{"default_value"} = $default_value;
531 $options_internal{$name}{"parent_value"} = $parent_value;
532 $options_internal{$name}{"is_null"} = $is_null;
533 $option_max_length = length($name) if (length($name) > $option_max_length);
538 # if ($value =~ /\Q$var_value/si)
539 if (lc($value) eq $var_value)
541 $options_internal{$name}{"parent_name"} = $parent_name;
542 $options_internal{$name}{"type"} = $type;
543 $options_internal{$name}{"value"} = $value;
544 $options_internal{$name}{"default_value"} = $default_value;
545 $options_internal{$name}{"parent_value"} = $parent_value;
546 $options_internal{$name}{"is_null"} = $is_null;
547 $option_max_length = length($name) if (length($name) > $option_max_length);
552 weechat
::infolist_free
($infolist);
553 foreach my $name (sort keys %options_internal)
555 push(@options_names, $name);
556 push(@options_parent_names, $options_internal{$name}{"parent_name"});
557 push(@options_types, $options_internal{$name}{"type"});
558 push(@options_values, $options_internal{$name}{"value"});
559 push(@options_default_values, $options_internal{$name}{"default_value"});
560 push(@options_parent_values, $options_internal{$name}{"parent_value"});
561 push(@options_is_null, $options_internal{$name}{"is_null"});
565 sub iset_refresh_line
567 if ($iset_buffer ne "")
570 if ($y <= $#options_names)
572 return if (! defined($options_types[$y]));
573 my $format = sprintf("%%s%%s%%s %%s %%-7s %%s %%s%%s%%s");
575 if ($wee_version_number >= 0x00040200)
577 $padding = " " x
($option_max_length - weechat
::strlen_screen
($options_names[$y]));
581 $padding = " " x
($option_max_length - length($options_names[$y]));
584 $around = "\"" if ((!$options_is_null[$y]) && ($options_types[$y] eq "string"));
586 my $color1 = weechat
::color
(weechat
::config_color
($options_iset{"color_option"}));
587 my $color2 = weechat
::color
(weechat
::config_color
($options_iset{"color_type"}));
590 if ($options_is_null[$y])
592 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_undef"}));
593 $color4 = weechat
::color
(weechat
::config_color
($options_iset{"color_value"}));
595 elsif ($options_values[$y] ne $options_default_values[$y])
597 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_diff"}));
601 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value"}));
603 if ($y == $current_line)
605 $color1 = weechat
::color
(weechat
::config_color
($options_iset{"color_option_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
606 $color2 = weechat
::color
(weechat
::config_color
($options_iset{"color_type_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
607 if ($options_is_null[$y])
609 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_undef_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
610 $color4 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
612 elsif ($options_values[$y] ne $options_default_values[$y])
614 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_diff_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
618 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
621 my $value = $options_values[$y];
622 if ($options_is_null[$y])
625 if ($options_parent_names[$y])
627 if (defined $options_parent_values[$y])
629 my $around_parent = "";
630 $around_parent = "\"" if ($options_types[$y] eq "string");
631 $value .= $color1." -> ".$color4.$around_parent.$options_parent_values[$y].$around_parent;
635 $value .= $color1." -> ".$color3."null";
639 my $strline = sprintf($format,
640 $color1, $options_names[$y], $padding,
641 $color2, $options_types[$y],
642 $color3, $around, $value, $around);
643 weechat
::print_y
($iset_buffer, $y, $strline);
651 if (($iset_buffer ne "") && ($#options_names >= 0))
653 foreach my $y (0 .. $#options_names)
655 iset_refresh_line
($y);
659 weechat
::bar_item_update
("isetbar_help") if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1);
662 sub iset_full_refresh
664 $iset_buffer = weechat
::buffer_search
($LANG, $PRGNAME);
665 if ($iset_buffer ne "")
667 weechat
::buffer_clear
($iset_buffer) unless defined $_[0]; # iset_full_refresh(1) does a full refresh without clearing buffer
668 # search for "*" in $filter.
669 if ($filter =~ m/\*/ and $search_mode == 2)
671 iset_get_options
("");
675 if ($search_mode == 0)
677 $search_value = "=" . $search_value;
678 iset_get_values
($search_value);
680 elsif ($search_mode == 1)
682 iset_get_values
($search_value);
684 elsif ($search_mode == 3)
686 iset_create_filter
($filter);
687 iset_get_options
($search_value);
690 if (weechat
::config_boolean
($options_iset{"show_plugin_description"}) == 1)
692 iset_set_current_line
($current_line);
695 $current_line = $#options_names if ($current_line > $#options_names);
698 weechat
::command
($iset_buffer, "/window refresh");
702 sub iset_set_current_line
704 my $new_current_line = $_[0];
705 if ($new_current_line >= 0)
707 my $old_current_line = $current_line;
708 $current_line = $new_current_line;
709 $current_line = $#options_names if ($current_line > $#options_names);
710 if ($old_current_line != $current_line)
712 iset_refresh_line
($old_current_line);
713 iset_refresh_line
($current_line);
714 weechat
::bar_item_update
("isetbar_help") if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1);
719 sub iset_signal_window_scrolled_cb
721 my ($data, $signal, $signal_data) = ($_[0], $_[1], $_[2]);
722 if ($iset_buffer ne "")
724 my $infolist = weechat
::infolist_get
("window", $signal_data, "");
725 if (weechat
::infolist_next
($infolist))
727 if (weechat
::infolist_pointer
($infolist, "buffer") eq $iset_buffer)
729 my $old_current_line = $current_line;
730 my $new_current_line = $current_line;
731 my $start_line_y = weechat
::infolist_integer
($infolist, "start_line_y");
732 my $chat_height = weechat
::infolist_integer
($infolist, "chat_height");
733 $new_current_line += $chat_height if ($new_current_line < $start_line_y);
734 $new_current_line -= $chat_height if ($new_current_line >= $start_line_y + $chat_height);
735 $new_current_line = $start_line_y if ($new_current_line < $start_line_y);
736 $new_current_line = $start_line_y + $chat_height - 1 if ($new_current_line >= $start_line_y + $chat_height);
737 iset_set_current_line
($new_current_line);
740 weechat
::infolist_free
($infolist);
743 return weechat
::WEECHAT_RC_OK
;
746 sub iset_get_window_number
748 if ($iset_buffer ne "")
750 my $window = weechat
::window_search_with_buffer
($iset_buffer);
751 return "-window ".weechat
::window_get_integer
($window, "number")." " if ($window ne "");
756 sub iset_check_line_outside_window
758 if ($iset_buffer ne "")
761 if ($wee_version_number >= 0x00030500)
763 my $window = weechat
::window_search_with_buffer
($iset_buffer);
764 $infolist = weechat
::infolist_get
("window", $window, "") if $window;
768 $infolist = weechat
::infolist_get
("window", "", "current");
772 if (weechat
::infolist_next
($infolist))
774 my $start_line_y = weechat
::infolist_integer
($infolist, "start_line_y");
775 my $chat_height = weechat
::infolist_integer
($infolist, "chat_height");
776 my $window_number = "";
777 if ($wee_version_number >= 0x00030500)
779 $window_number = "-window ".weechat
::infolist_integer
($infolist, "number")." ";
781 if ($start_line_y > $current_line)
783 weechat
::command
($iset_buffer, "/window scroll ".$window_number."-".($start_line_y - $current_line));
787 if ($start_line_y <= $current_line - $chat_height)
789 weechat
::command
($iset_buffer, "/window scroll ".$window_number."+".($current_line - $start_line_y - $chat_height + 1));
794 weechat
::infolist_free
($infolist);
799 sub iset_get_option_name_index
801 my $option_name = $_[0];
803 while ($index <= $#options_names)
805 return -1 if ($options_names[$index] gt $option_name);
806 return $index if ($options_names[$index] eq $option_name);
812 sub iset_refresh_option
814 my $option_name = $_[0];
816 my $infolist = weechat
::infolist_get
("option", "", $option_name);
819 weechat
::infolist_next
($infolist);
820 if (weechat
::infolist_fields
($infolist))
822 $options_parent_names[$index] = weechat
::infolist_string
($infolist, "parent_name");
823 $options_types[$index] = weechat
::infolist_string
($infolist, "type");
824 $options_values[$index] = weechat
::infolist_string
($infolist, "value");
825 $options_default_values[$index] = weechat
::infolist_string
($infolist, "default_value");
826 $options_is_null[$index] = weechat
::infolist_integer
($infolist, "value_is_null");
827 $options_parent_values[$index] = undef;
828 if ($options_parent_names[$index]
829 && (($wee_version_number < 0x00040300) || (weechat
::infolist_search_var
($infolist, "parent_value"))))
831 $options_parent_values[$index] = weechat
::infolist_string
($infolist, "parent_value");
833 iset_refresh_line
($index);
834 iset_title
() if ($option_name eq "iset.look.show_current_line");
838 iset_full_refresh
(1); # if not found, refresh fully without clearing buffer
839 weechat
::print_y
($iset_buffer, $#options_names + 1, "");
841 weechat
::infolist_free
($infolist);
847 my ($data, $option_name, $value) = ($_[0], $_[1], $_[2]);
849 if ($iset_buffer ne "")
851 return weechat
::WEECHAT_RC_OK
if (weechat
::info_get
("weechat_upgrading", "") eq "1");
853 my $index = iset_get_option_name_index
($option_name);
856 # refresh info about changed option
857 iset_refresh_option
($option_name, $index);
858 # refresh any other option having this changed option as parent
859 foreach my $i (0 .. $#options_names)
861 if ($options_parent_names[$i] eq $option_name)
863 iset_refresh_option
($options_names[$i], $i);
869 iset_full_refresh
() if ($option_name ne "weechat.bar.isetbar.hidden");
873 return weechat
::WEECHAT_RC_OK
;
878 my ($option, $value) = ($_[0],$_[1]);
879 if (defined $option and defined $value)
881 $option = weechat
::config_get
($option);
882 weechat
::config_option_set
($option, $value, 1) if ($option ne "");
886 sub iset_reset_option
891 $option = weechat
::config_get
($option);
892 weechat
::config_option_reset
($option, 1) if ($option ne "");
896 sub iset_unset_option
901 $option = weechat
::config_get
($option);
902 weechat
::config_option_unset
($option) if ($option ne "");
909 my ($data, $buffer, $args) = ($_[0], $_[1], $_[2]);
911 # $search_value = "";
912 if (($args ne "") && (substr($args, 0, 2) ne "**"))
914 my @cmd_array = split(/ /,$args);
915 my $array_count = @cmd_array;
916 if (substr($args, 0, 1) eq weechat
::config_string
($options_iset{"value_search_char"})
917 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"})) )
920 my $search_value = substr($args, 1); # cut value_search_char
921 if ($iset_buffer ne "")
923 weechat
::buffer_clear
($iset_buffer);
924 weechat
::command
($iset_buffer, "/window refresh");
926 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
927 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $search_value);
929 iset_get_values
($search_value);
931 weechat
::buffer_set
($iset_buffer, "display", "1");
932 # $filter = $var_value;
933 return weechat
::WEECHAT_RC_OK
;
939 $search_mode = 2; # grep on option
940 if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s")
942 if ( defined $cmd_array[1] and substr($cmd_array[1], 0, 1) eq weechat
::config_string
($options_iset{"value_search_char"})
943 or defined $cmd_array[2] and substr($cmd_array[2], 0, 1) eq weechat
::config_string
($options_iset{"value_search_char"}) )
945 $search_mode = 3; # grep on option and value
946 $search_value = substr($cmd_array[1], 1); # cut value_search_char
947 $search_value = substr($cmd_array[2], 1) if ( $array_count > 2); # cut value_search_char
951 # show all diff values
956 $args = $search_value;
958 if ( $array_count >= 2 and $cmd_array[0] eq "d")
961 $search_value = substr($cmd_array[1], 0); # cut value_search_char
962 $search_value = substr($cmd_array[2], 0) if ( $array_count > 2); # cut value_search_char
963 $args = $search_value;
966 iset_create_filter
($args);
968 my $ptrbuf = weechat
::buffer_search
($LANG, $PRGNAME);
973 iset_get_options
($search_value);
975 weechat
::buffer_set
(weechat
::buffer_search
($LANG, $PRGNAME), "display", "1");
976 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $search_value);
977 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
978 return weechat
::WEECHAT_RC_OK
;
982 iset_get_options
($search_value);
984 weechat
::buffer_set
($ptrbuf, "display", "1");
987 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_mode", $search_mode);
988 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_search_value", $search_value);
990 if ($iset_buffer eq "")
993 iset_get_options
("");
998 # iset_get_options($search_value);
999 iset_full_refresh
() if ($filter_set);
1004 weechat
::buffer_set
($iset_buffer, "display", "1");
1008 if ($args eq "**refresh")
1010 iset_full_refresh
();
1012 if ($args eq "**up")
1014 if ($current_line > 0)
1017 iset_refresh_line
($current_line + 1);
1018 iset_refresh_line
($current_line);
1019 iset_check_line_outside_window
();
1022 if ($args eq "**down")
1024 if ($current_line < $#options_names)
1027 iset_refresh_line
($current_line - 1);
1028 iset_refresh_line
($current_line);
1029 iset_check_line_outside_window
();
1032 if ($args eq "**left" && $wee_version_number >= 0x00030600)
1034 weechat
::command
($iset_buffer, "/window scroll_horiz ".iset_get_window_number
()."-".weechat
::config_integer
($options_iset{"scroll_horiz"})."%");
1036 if ($args eq "**right" && $wee_version_number >= 0x00030600)
1038 weechat
::command
($iset_buffer, "/window scroll_horiz ".iset_get_window_number
().weechat
::config_integer
($options_iset{"scroll_horiz"})."%");
1040 if ($args eq "**scroll_top")
1042 my $old_current_line = $current_line;
1044 iset_refresh_line
($old_current_line);
1045 iset_refresh_line
($current_line);
1047 weechat
::command
($iset_buffer, "/window scroll_top ".iset_get_window_number
());
1049 if ($args eq "**scroll_bottom")
1051 my $old_current_line = $current_line;
1052 $current_line = $#options_names;
1053 iset_refresh_line
($old_current_line);
1054 iset_refresh_line
($current_line);
1056 weechat
::command
($iset_buffer, "/window scroll_bottom ".iset_get_window_number
());
1058 if ($args eq "**toggle")
1060 if ($options_types[$current_line] eq "boolean")
1062 iset_set_option
($options_names[$current_line], "toggle");
1065 if ($args eq "**incr")
1067 if (($options_types[$current_line] eq "integer")
1068 || ($options_types[$current_line] eq "color"))
1070 iset_set_option
($options_names[$current_line], "++1");
1073 if ($args eq "**decr")
1075 if (($options_types[$current_line] eq "integer")
1076 || ($options_types[$current_line] eq "color"))
1078 iset_set_option
($options_names[$current_line], "--1");
1081 if ($args eq "**reset")
1083 iset_reset_option
($options_names[$current_line]);
1085 if ($args eq "**unset")
1087 iset_unset_option
($options_names[$current_line]);
1089 if ($args eq "**toggle_help")
1091 if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1)
1093 weechat
::config_option_set
($options_iset{"show_help_bar"},0,1);
1098 weechat
::config_option_set
($options_iset{"show_help_bar"},1,1);
1102 if ($args eq "**toggle_show_plugin_desc")
1104 if (weechat
::config_boolean
($options_iset{"show_plugin_description"}) == 1)
1106 weechat
::config_option_set
($options_iset{"show_plugin_description"},0,1);
1107 iset_full_refresh
();
1108 iset_check_line_outside_window
();
1113 weechat
::config_option_set
($options_iset{"show_plugin_description"},1,1);
1114 iset_full_refresh
();
1115 iset_check_line_outside_window
();
1119 if ($args eq "**set")
1122 my $value = $options_values[$current_line];
1123 if ($options_is_null[$current_line])
1129 $quote = "\"" if ($options_types[$current_line] eq "string");
1131 $value = " ".$quote.$value.$quote if ($value ne "" or $quote ne "");
1133 my $set_command = "/set";
1134 my $start_index = 5;
1135 if (weechat
::config_boolean
($options_iset{"use_mute"}) == 1)
1137 $set_command = "/mute ".$set_command;
1140 $set_command = $set_command." ".$options_names[$current_line].$value;
1141 my $pos_space = index($set_command, " ", $start_index);
1148 $pos_space = $pos_space + 1;
1149 $pos_space = $pos_space + 1 if ($quote ne "");
1151 weechat
::buffer_set
($iset_buffer, "input", $set_command);
1152 weechat
::buffer_set
($iset_buffer, "input_pos", "".$pos_space);
1155 weechat
::bar_item_update
("isetbar_help") if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1);
1156 return weechat
::WEECHAT_RC_OK
;
1161 my ($redraw) = ($_[0]);
1163 return '' if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 0);
1165 if (not defined $options_names[$current_line])
1167 return "No option selected. Set a new filter using command line (use '*' to see all options)";
1169 if ($options_name_copy eq $options_names[$current_line] and not defined $redraw)
1171 return $description;
1173 $options_name_copy = $options_names[$current_line];
1175 $optionlist = weechat
::infolist_get
("option", "", $options_names[$current_line]);
1176 weechat
::infolist_next
($optionlist);
1177 my $full_name = weechat
::infolist_string
($optionlist,"full_name");
1178 my $option_desc = "";
1179 my $option_default_value = "";
1180 my $option_range = "";
1181 my $possible_values = "";
1182 my $re = qq(\Q$full_name);
1183 if (grep (/^$re$/,$options_names[$current_line]))
1185 $option_desc = weechat
::infolist_string
($optionlist, "description_nls");
1186 $option_desc = weechat
::infolist_string
($optionlist, "description") if ($option_desc eq "");
1187 $option_desc = "No help found" if ($option_desc eq "");
1188 $option_default_value = weechat
::infolist_string
($optionlist, "default_value");
1189 $possible_values = weechat
::infolist_string
($optionlist, "string_values") if (weechat
::infolist_string
($optionlist, "string_values") ne "");
1190 if ((weechat
::infolist_string
($optionlist, "type") eq "integer") && ($possible_values eq ""))
1192 $option_range = weechat
::infolist_integer
($optionlist, "min")
1193 ." .. ".weechat
::infolist_integer
($optionlist, "max");
1196 weechat
::infolist_free
($optionlist);
1199 $description = weechat
::color
(weechat
::config_color
($options_iset{"color_help_option_name"})).$options_names[$current_line]
1200 .weechat
::color
("bar_fg").": "
1201 .weechat
::color
(weechat
::config_color
($options_iset{"color_help_text"})).$option_desc;
1203 # show additional infos like default value and possible values
1205 if (weechat
::config_boolean
($options_iset{"show_help_extra_info"}) == 1)
1208 weechat
::color
("bar_delim")." ["
1209 .weechat
::color
("bar_fg")."default: "
1210 .weechat
::color
("bar_delim")."\""
1211 .weechat
::color
(weechat
::config_color
($options_iset{"color_help_default_value"})).$option_default_value
1212 .weechat
::color
("bar_delim")."\"";
1213 if ($option_range ne "")
1215 $description .= weechat
::color
("bar_fg").", values: ".$option_range;
1217 if ($possible_values ne "")
1219 $possible_values =~ s/\|/", "/g; # replace '|' to '", "'
1220 $description .= weechat
::color
("bar_fg").", values: ". "\"" . $possible_values . "\"";
1223 $description .= weechat
::color
("bar_delim")."]";
1225 return $description;
1228 sub iset_check_condition_isetbar_cb
1230 my ($data, $modifier, $modifier_data, $string) = ($_[0], $_[1], $_[2], $_[3]);
1231 my $buffer = weechat
::window_get_pointer
($modifier_data, "buffer");
1234 if ((weechat
::buffer_get_string
($buffer, "plugin") eq $LANG)
1235 && (weechat
::buffer_get_string
($buffer, "name") eq $PRGNAME))
1246 my $barhidden = weechat
::config_get
("weechat.bar.isetbar.hidden");
1251 if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1)
1253 if (weechat
::config_boolean
($barhidden))
1255 weechat
::config_option_set
($barhidden, 0, 1);
1261 if (!weechat
::config_boolean
($barhidden))
1263 weechat
::config_option_set
($barhidden, 1, 1);
1269 sub iset_signal_buffer_switch_cb
1271 my $buffer_pointer = $_[2];
1273 $show_bar = 1 if (weechat
::buffer_get_integer
($iset_buffer, "num_displayed") > 0);
1274 iset_show_bar
($show_bar);
1275 iset_check_line_outside_window
() if ($buffer_pointer eq $iset_buffer);
1276 return weechat
::WEECHAT_RC_OK
;
1281 return iset_get_help
();
1284 sub iset_upgrade_ended
1286 iset_full_refresh
();
1291 # when script is unloaded, we hide bar
1295 # -------------------------------[ mouse support ]-------------------------------------
1297 sub hook_focus_iset_cb
1299 my %info = %{$_[1]};
1300 my $bar_item_line = int($info{"_bar_item_line"});
1302 if (($info{"_buffer_name"} eq $PRGNAME) && $info{"_buffer_plugin"} eq $LANG && ($bar_item_line >= 0) && ($bar_item_line <= $#iset_focus))
1304 $hash = $iset_focus[$bar_item_line];
1309 my $hash_focus = $iset_focus[0];
1310 foreach my $key (keys %$hash_focus)
1312 $hash->{$key} = "?";
1318 # _chat_line_y contains selected line
1319 sub iset_hsignal_mouse_cb
1321 my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
1323 return weechat
::WEECHAT_RC_OK
unless (@options_types);
1325 if ($hash{"_buffer_name"} eq $PRGNAME && ($hash{"_buffer_plugin"} eq $LANG))
1327 if ($hash{"_key"} eq "button1")
1329 iset_set_current_line
($hash{"_chat_line_y"});
1331 elsif ($hash{"_key"} eq "button2")
1333 if ($options_types[$hash{"_chat_line_y"}] eq "boolean")
1335 iset_set_option
($options_names[$hash{"_chat_line_y"}], "toggle");
1336 iset_set_current_line
($hash{"_chat_line_y"});
1338 elsif ($options_types[$hash{"_chat_line_y"}] eq "string")
1340 iset_set_current_line
($hash{"_chat_line_y"});
1341 weechat
::command
("", "/$PRGNAME **set");
1344 elsif ($hash{"_key"} eq "button2-gesture-left" or $hash{"_key"} eq "button2-gesture-left-long")
1346 if ($options_types[$hash{"_chat_line_y"}] eq "integer" or ($options_types[$hash{"_chat_line_y"}] eq "color"))
1348 iset_set_current_line
($hash{"_chat_line_y"});
1349 my $distance = distance
($hash{"_chat_line_x"},$hash{"_chat_line_x2"});
1350 weechat
::command
("", "/repeat $distance /$PRGNAME **decr");
1353 elsif ($hash{"_key"} eq "button2-gesture-right" or $hash{"_key"} eq "button2-gesture-right-long")
1355 if ($options_types[$hash{"_chat_line_y"}] eq "integer" or ($options_types[$hash{"_chat_line_y"}] eq "color"))
1357 iset_set_current_line
($hash{"_chat_line_y"});
1358 my $distance = distance
($hash{"_chat_line_x"},$hash{"_chat_line_x2"});
1359 weechat
::command
("", "/repeat $distance /$PRGNAME **incr");
1368 my $current_window = weechat
::current_window
();
1369 my $dest_window = weechat
::window_search_with_buffer
(weechat
::buffer_search
("perl","iset"));
1370 return 0 if ($dest_window eq "" or $current_window eq $dest_window);
1372 my $infolist = weechat
::infolist_get
("window", $dest_window, "");
1373 weechat
::infolist_next
($infolist);
1374 my $number = weechat
::infolist_integer
($infolist, "number");
1375 weechat
::infolist_free
($infolist);
1376 weechat
::command
("","/window " . $number);
1381 my ($x1,$x2) = ($_[0], $_[1]);
1383 $distance = $x1 - $x2;
1384 $distance = abs($distance);
1388 $distance = $distance / 3;
1389 $distance = 1 if ($distance == 0);
1391 elsif ($distance == 0)
1398 # -----------------------------------[ config ]---------------------------------------
1400 sub iset_config_init
1402 $iset_config_file = weechat
::config_new
($ISET_CONFIG_FILE_NAME,"iset_config_reload_cb","");
1403 return if ($iset_config_file eq "");
1406 my $section_color = weechat
::config_new_section
($iset_config_file,"color", 0, 0, "", "", "", "", "", "", "", "", "", "");
1407 if ($section_color eq "")
1409 weechat
::config_free
($iset_config_file);
1412 $options_iset{"color_option"} = weechat
::config_new_option
(
1413 $iset_config_file, $section_color,
1414 "option", "color", "Color for option name in iset buffer", "", 0, 0,
1415 "default", "default", 0, "", "", "full_refresh_cb", "", "", "");
1416 $options_iset{"color_option_selected"} = weechat
::config_new_option
(
1417 $iset_config_file, $section_color,
1418 "option_selected", "color", "Color for selected option name in iset buffer", "", 0, 0,
1419 "white", "white", 0, "", "", "full_refresh_cb", "", "", "");
1420 $options_iset{"color_type"} = weechat
::config_new_option
(
1421 $iset_config_file, $section_color,
1422 "type", "color", "Color for option type (integer, boolean, string)", "", 0, 0,
1423 "brown", "brown", 0, "", "", "full_refresh_cb", "", "", "");
1424 $options_iset{"color_type_selected"} = weechat
::config_new_option
(
1425 $iset_config_file, $section_color,
1426 "type_selected", "color", "Color for selected option type (integer, boolean, string)", "", 0, 0,
1427 "yellow", "yellow", 0, "", "", "full_refresh_cb", "", "", "");
1428 $options_iset{"color_value"} = weechat
::config_new_option
(
1429 $iset_config_file, $section_color,
1430 "value", "color", "Color for option value", "", 0, 0,
1431 "cyan", "cyan", 0, "", "", "full_refresh_cb", "", "", "");
1432 $options_iset{"color_value_selected"} = weechat
::config_new_option
(
1433 $iset_config_file, $section_color,
1434 "value_selected", "color", "Color for selected option value", "", 0, 0,
1435 "lightcyan", "lightcyan", 0, "", "", "full_refresh_cb", "", "", "");
1436 $options_iset{"color_value_diff"} = weechat
::config_new_option
(
1437 $iset_config_file, $section_color,
1438 "value_diff", "color", "Color for option value different from default", "", 0, 0,
1439 "magenta", "magenta", 0, "", "", "full_refresh_cb", "", "", "");
1440 $options_iset{"color_value_diff_selected"} = weechat
::config_new_option
(
1441 $iset_config_file, $section_color,
1442 "value_diff_selected", "color", "Color for selected option value different from default", "", 0, 0,
1443 "lightmagenta", "lightmagenta", 0, "", "", "full_refresh_cb", "", "", "");
1444 $options_iset{"color_value_undef"} = weechat
::config_new_option
(
1445 $iset_config_file, $section_color,
1446 "value_undef", "color", "Color for option value undef", "", 0, 0,
1447 "green", "green", 0, "", "", "full_refresh_cb", "", "", "");
1448 $options_iset{"color_value_undef_selected"} = weechat
::config_new_option
(
1449 $iset_config_file, $section_color,
1450 "value_undef_selected", "color", "Color for selected option value undef", "", 0, 0,
1451 "lightgreen", "lightgreen", 0, "", "", "full_refresh_cb", "", "", "");
1452 $options_iset{"color_bg_selected"} = weechat
::config_new_option
(
1453 $iset_config_file, $section_color,
1454 "bg_selected", "color", "Background color for current selected option", "", 0, 0,
1455 "red", "red", 0, "", "", "full_refresh_cb", "", "", "");
1456 $options_iset{"color_help_option_name"} = weechat
::config_new_option
(
1457 $iset_config_file, $section_color,
1458 "help_option_name", "color", "Color for option name in help-bar", "", 0, 0,
1459 "white", "white", 0, "", "", "bar_refresh", "", "", "");
1460 $options_iset{"color_help_text"} = weechat
::config_new_option
(
1461 $iset_config_file, $section_color,
1462 "help_text", "color", "Color for option description in help-bar", "", 0, 0,
1463 "default", "default", 0, "", "", "bar_refresh", "", "", "");
1464 $options_iset{"color_help_default_value"} = weechat
::config_new_option
(
1465 $iset_config_file, $section_color,
1466 "help_default_value", "color", "Color for default option value in help-bar", "", 0, 0,
1467 "green", "green", 0, "", "", "bar_refresh", "", "", "");
1470 my $section_help = weechat
::config_new_section
($iset_config_file,"help", 0, 0, "", "", "", "", "", "", "", "", "", "");
1471 if ($section_help eq "")
1473 weechat
::config_free
($iset_config_file);
1476 $options_iset{"show_help_bar"} = weechat
::config_new_option
(
1477 $iset_config_file, $section_help,
1478 "show_help_bar", "boolean", "Show help bar", "", 0, 0,
1479 "on", "on", 0, "", "", "toggle_help_cb", "", "", "");
1480 $options_iset{"show_help_extra_info"} = weechat
::config_new_option
(
1481 $iset_config_file, $section_help,
1482 "show_help_extra_info", "boolean", "Show additional information in help bar (default value, max./min. value) ", "", 0, 0,
1483 "on", "on", 0, "", "", "", "", "", "");
1484 $options_iset{"show_plugin_description"} = weechat
::config_new_option
(
1485 $iset_config_file, $section_help,
1486 "show_plugin_description", "boolean", "Show plugin description in iset buffer", "", 0, 0,
1487 "off", "off", 0, "", "", "full_refresh_cb", "", "", "");
1490 my $section_look = weechat
::config_new_section
($iset_config_file, "look", 0, 0, "", "", "", "", "", "", "", "", "", "");
1491 if ($section_look eq "")
1493 weechat
::config_free
($iset_config_file);
1496 $options_iset{"value_search_char"} = weechat
::config_new_option
(
1497 $iset_config_file, $section_look,
1498 "value_search_char", "string", "Trigger char to tell iset to search for value instead of option (for example: =red)", "", 0, 0,
1499 "=", "=", 0, "", "", "", "", "", "");
1500 $options_iset{"scroll_horiz"} = weechat
::config_new_option
(
1501 $iset_config_file, $section_look,
1502 "scroll_horiz", "integer", "scroll content of iset buffer n%", "", 1, 100,
1503 "10", "10", 0, "", "", "", "", "", "");
1504 $options_iset{"show_current_line"} = weechat
::config_new_option
(
1505 $iset_config_file, $section_look,
1506 "show_current_line", "boolean", "show current line in title bar.", "", 0, 0,
1507 "on", "on", 0, "", "", "", "", "", "");
1508 $options_iset{"use_mute"} = weechat
::config_new_option
(
1509 $iset_config_file, $section_look,
1510 "use_mute", "boolean", "/mute command will be used in input bar", "", 0, 0,
1511 "off", "off", 0, "", "", "", "", "", "");
1514 sub iset_config_reload_cb
1516 my ($data,$config_file) = ($_[0], $_[1]);
1517 return weechat
::config_reload
($config_file)
1520 sub iset_config_read
1522 return weechat
::config_read
($iset_config_file) if ($iset_config_file ne "");
1525 sub iset_config_write
1527 return weechat
::config_write
($iset_config_file) if ($iset_config_file ne "");
1532 iset_full_refresh
();
1533 return weechat
::WEECHAT_RC_OK
;
1539 weechat
::bar_item_update
("isetbar_help") if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1);
1540 return weechat
::WEECHAT_RC_OK
;
1545 my $value = weechat
::config_boolean
($options_iset{"show_help_bar"});
1546 iset_show_bar
($value);
1547 return weechat
::WEECHAT_RC_OK
;
1550 # -----------------------------------[ main ]-----------------------------------------
1552 weechat
::register
($PRGNAME, $AUTHOR, $VERSION, $LICENSE,
1553 $DESCR, "iset_end", "");
1555 $wee_version_number = weechat
::info_get
("version_number", "") || 0;
1560 weechat
::hook_command
($PRGNAME, "Interactive set", "d <text> || f <file> || s <section> || [=][=]<text>",
1561 "d <text> : show only changed options\n".
1562 "f file : show options for a file\n".
1563 "s section: show options for a section\n".
1564 "text : show options with 'text' in name\n".
1565 weechat
::config_string
($options_iset{"value_search_char"})."text : show options with 'text' in value\n".
1566 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".
1567 "Keys for iset buffer:\n".
1568 "f11,f12 : move iset content left/right\n".
1569 "up,down : move one option up/down\n".
1570 "pgup,pdwn : move one page up/down\n".
1571 "home,end : move to first/last option\n".
1572 "ctrl+'L' : refresh options and screen\n".
1573 "alt+space : toggle boolean on/off\n".
1574 "alt+'+' : increase value (for integer or color)\n".
1575 "alt+'-' : decrease value (for integer or color)\n".
1576 "alt+'i',alt+'r': reset value of option\n".
1577 "alt+'i',alt+'u': unset option\n".
1578 "alt+enter : set new value for option (edit it with command line)\n".
1579 "text,enter : set a new filter using command line (use '*' to see all options)\n".
1580 "alt+'v' : toggle help bar on/off\n".
1581 "alt+'p' : toggle option \"show_plugin_description\" on/off\n".
1582 "q : as input in iset buffer to close it\n".
1585 "wheel up/down : move cursor up/down\n".
1586 "left button : select an option from list\n".
1587 "right button : toggle boolean (on/off) or set a new value for option (edit it with command line)\n".
1588 "right button + drag left/right: increase/decrease value (for integer or color)\n".
1591 " show changed options in 'aspell' plugin\n".
1592 " /iset d aspell\n".
1593 " show options for file 'irc'\n".
1595 " show options for section 'look'\n".
1597 " show all options with text 'nicklist' in name\n".
1598 " /iset nicklist\n".
1599 " show all values which contain 'red'. ('" . weechat
::config_string
($options_iset{"value_search_char"}) . "' is a trigger char).\n".
1600 " /iset ". weechat
::config_string
($options_iset{"value_search_char"}) ."red\n".
1601 " 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".
1602 " /iset ". weechat
::config_string
($options_iset{"value_search_char"}) . weechat
::config_string
($options_iset{"value_search_char"}) ."off\n".
1603 " show options for file 'weechat' which contains value 'off'\n".
1604 " /iset f weechat ".weechat
::config_string
($options_iset{"value_search_char"})."off\n".
1606 "", "iset_cmd_cb", "");
1607 weechat
::hook_signal
("upgrade_ended", "iset_upgrade_ended", "");
1608 weechat
::hook_signal
("window_scrolled", "iset_signal_window_scrolled_cb", "");
1609 weechat
::hook_signal
("buffer_switch", "iset_signal_buffer_switch_cb","");
1610 weechat
::bar_item_new
("isetbar_help", "iset_item_cb", "");
1611 weechat
::bar_new
("isetbar", "on", "0", "window", "", "top", "horizontal",
1612 "vertical", "3", "3", "default", "cyan", "default", "1",
1614 weechat
::hook_modifier
("bar_condition_isetbar", "iset_check_condition_isetbar_cb", "");
1615 weechat
::hook_config
("*", "iset_config_cb", "");
1616 $iset_buffer = weechat
::buffer_search
($LANG, $PRGNAME);
1617 iset_init
() if ($iset_buffer ne "");
1619 if ($wee_version_number >= 0x00030600)
1621 weechat
::hook_focus
("chat", "hook_focus_iset_cb", "");
1622 weechat
::hook_hsignal
($PRGNAME."_mouse", "iset_hsignal_mouse_cb", "");
1623 weechat
::key_bind
("mouse", \
%mouse_keys);