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