2 # Copyright (C) 2008-2012 Sebastien Helleu <flashcode@flashtux.org>
3 # Copyright (C) 2010-2012 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 # 2012-03-17, Sebastien Helleu <flashcode@flashtux.org>:
23 # version 2.5: fix check of sections when creating config file
24 # 2012-03-09, Sebastien Helleu <flashcode@flashtux.org>:
25 # version 2.4: fix reload of config file
26 # 2012-02-02, nils_2 <weechatter@arcor.de>:
27 # version 2.3: fixed: refresh problem with new search results and cursor was outside window.
28 # : add: new option "current_line" in title bar
29 # version 2.2: fixed: refresh error when toggling plugins description
30 # 2011-11-05, nils_2 <weechatter@arcor.de>:
31 # version 2.1: use own config file (iset.conf), fix own help color (used immediately)
32 # 2011-10-16, nils_2 <weechatter@arcor.de>:
33 # version 2.0: add support for left-mouse-button and more sensitive mouse gesture (for integer/color options)
34 # add help text for mouse support
35 # 2011-09-20, Sebastien Helleu <flashcode@flashtux.org>:
36 # version 1.9: add mouse support, fix iset buffer, fix errors on first load under FreeBSD
37 # 2011-07-21, nils_2 <weechatter@arcor.de>:
38 # version 1.8: added: option "show_plugin_description" (alt+p)
39 # fixed: typos in /help iset (lower case for alt+'x' keys)
40 # 2011-05-29, nils_2 <weechatter@arcor.de>:
41 # version 1.7: added: version check for future needs
42 # added: new option (scroll_horiz) and usage of scroll_horiz function (weechat >= 0.3.6 required)
43 # fixed: help_bar did not pop up immediately using key-shortcut
44 # 2011-02-19, nils_2 <weechatter@arcor.de>:
45 # version 1.6: added: display of all possible values in help bar (show_help_extra_info)
46 # fixed: external user options never loaded when starting iset first time
47 # 2011-02-13, Sebastien Helleu <flashcode@flashtux.org>:
48 # version 1.5: use new help format for command arguments
49 # 2011-02-03, nils_2 <weechatter@arcor.de>:
50 # version 1.4: fixed: restore value filter after /upgrade using buffer local variable.
51 # 2011-01-14, nils_2 <weechatter@arcor.de>:
52 # version 1.3: added function to search for values (option value_search_char).
54 # 2010-12-26, Sebastien Helleu <flashcode@flashtux.org>:
55 # version 1.2: improve speed of /upgrade when iset buffer is open,
56 # restore filter used after /upgrade using buffer local variable,
57 # use /iset filter argument if buffer is open.
58 # 2010-11-21, drubin <drubin+weechat@smartcube.co.za>:
59 # version 1.1.1: fix bugs with cursor position
60 # 2010-11-20, nils_2 <weechatter@arcor.de>:
61 # version 1.1: cursor position set to value
62 # 2010-08-03, Sebastien Helleu <flashcode@flashtux.org>:
63 # version 1.0: move misplaced call to infolist_free()
64 # 2010-02-02, rettub <rettub@gmx.net>:
65 # version 0.9: turn all the help stuff off if option 'show_help_bar' is 'off',
66 # new key binding <alt>-<v> to toggle help_bar and help stuff on/off
67 # 2010-01-30, nils_2 <weechatter@arcor.de>:
68 # version 0.8: fix error when option does not exist
69 # 2010-01-24, Sebastien Helleu <flashcode@flashtux.org>:
70 # version 0.7: display iset bar only on iset buffer
71 # 2010-01-22, nils_2 <weechatter@arcor.de> and drubin:
72 # version 0.6: add description in a bar, fix singular/plural bug in title bar,
73 # fix selected line when switching buffer
74 # 2009-06-21, Sebastien Helleu <flashcode@flashtux.org>:
75 # version 0.5: fix bug with iset buffer after /upgrade
76 # 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
77 # version 0.4: sync with last API changes
78 # 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
79 # version 0.3: open iset buffer when /iset command is executed
80 # 2009-01-04, Sebastien Helleu <flashcode@flashtux.org>:
81 # version 0.2: use null values for options, add colors, fix refresh bugs,
82 # use new keys to reset/unset options, sort options by name,
83 # display number of options in buffer's title
84 # 2008-11-05, Sebastien Helleu <flashcode@flashtux.org>:
85 # version 0.1: first official version
86 # 2008-04-19, Sebastien Helleu <flashcode@flashtux.org>:
93 my $DESCR = "Interactive Set for configuration options";
94 my $AUTHOR = "Sebastien Helleu <flashcode\@flashtux.org>";
97 my $ISET_CONFIG_FILE_NAME = "iset";
100 my $iset_buffer = "";
101 my $wee_version_number = 0;
103 my @options_names = ();
104 my @options_types = ();
105 my @options_values = ();
106 my @options_is_null = ();
107 my $option_max_length = 0;
108 my $current_line = 0;
110 my $description = "";
111 my $options_name_copy = "";
112 my $iset_filter_title = "";
116 my %mouse_keys = ("\@chat(perl.$PRGNAME):button1" => "hsignal:iset_mouse",
117 "\@chat(perl.$PRGNAME):button2*" => "hsignal:iset_mouse",
118 "\@chat(perl.$PRGNAME):wheelup" => "/repeat 5 /iset **up",
119 "\@chat(perl.$PRGNAME):wheeldown" => "/repeat 5 /iset **down");
124 if ($iset_buffer ne "")
126 my $current_line_text = "";
127 $current_line_text = ($current_line + 1) . "/" if (weechat
::config_boolean
($options_iset{"show_current_line"}) == 1);
128 $iset_filter_title = "Filter: " if ($iset_filter_title eq "");
129 $filter = "*" if ($filter eq "");
131 my $option_txt = " option";
132 my $opt_txt = $option_txt;
133 $opt_txt = $option_txt.$postfix if (@options_names > 1);
134 my $show_plugin_descr_txt = "";
135 $show_plugin_descr_txt = " (plugins description hidden)" if (weechat
::config_boolean
($options_iset{"show_plugin_description"}) == 0);
136 weechat
::buffer_set
($iset_buffer, "title",
137 "Interactive set (iset.pl v$VERSION) | "
138 .$iset_filter_title.weechat
::color
("yellow").$filter.weechat
::color
("default")." | "
139 .$current_line_text.@options_names.$opt_txt . $show_plugin_descr_txt);
146 $filter = "$1.*" if ($filter =~ /f (.*)/);
147 $filter = "*.$1.*" if ($filter =~ /s (.*)/);
148 if ((substr($filter, 0, 1) ne "*") && (substr($filter, -1, 1) ne "*"))
150 $filter = "*".$filter."*";
152 if ($iset_buffer ne "")
154 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_filter", $filter);
158 sub iset_buffer_input
160 my ($data, $buffer, $string) = ($_[0], $_[1], $_[2]);
162 my $string2 = substr($string, 0, 1);
163 if ($string2 eq weechat
::config_string
($options_iset{"value_search_char"}))
165 $filter = substr($string, 1);
166 iset_get_values
($filter);
167 $iset_filter_title = "Filter (by value): ";
168 if ($iset_buffer ne "")
170 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_filter", $filter);
175 $iset_filter_title = "";
176 iset_filter
($string);
179 weechat
::buffer_clear
($buffer);
180 iset_title
($iset_filter_title);
183 return weechat
::WEECHAT_RC_OK
;
186 sub iset_buffer_close
190 return weechat
::WEECHAT_RC_OK
;
196 $iset_buffer = weechat
::buffer_search
($LANG, $PRGNAME);
197 if ($iset_buffer eq "")
199 $iset_buffer = weechat
::buffer_new
($PRGNAME, "iset_buffer_input", "", "iset_buffer_close", "");
203 my $new_filter = weechat
::buffer_get_string
($iset_buffer, "localvar_iset_filter");
204 $filter = $new_filter if ($new_filter ne "");
206 if ($iset_buffer ne "")
208 weechat
::buffer_set
($iset_buffer, "type", "free");
210 weechat
::buffer_set
($iset_buffer, "key_bind_ctrl-L", "/iset **refresh");
211 weechat
::buffer_set
($iset_buffer, "key_bind_meta2-A", "/iset **up");
212 weechat
::buffer_set
($iset_buffer, "key_bind_meta2-B", "/iset **down");
213 weechat
::buffer_set
($iset_buffer, "key_bind_meta2-23~", "/iset **left");
214 weechat
::buffer_set
($iset_buffer, "key_bind_meta2-24~" , "/iset **right");
215 weechat
::buffer_set
($iset_buffer, "key_bind_meta- ", "/iset **toggle");
216 weechat
::buffer_set
($iset_buffer, "key_bind_meta-+", "/iset **incr");
217 weechat
::buffer_set
($iset_buffer, "key_bind_meta--", "/iset **decr");
218 weechat
::buffer_set
($iset_buffer, "key_bind_meta-imeta-r", "/iset **reset");
219 weechat
::buffer_set
($iset_buffer, "key_bind_meta-imeta-u", "/iset **unset");
220 weechat
::buffer_set
($iset_buffer, "key_bind_meta-ctrl-J", "/iset **set");
221 weechat
::buffer_set
($iset_buffer, "key_bind_meta-ctrl-M", "/iset **set");
222 weechat
::buffer_set
($iset_buffer, "key_bind_meta-meta2-1~", "/iset **scroll_top");
223 weechat
::buffer_set
($iset_buffer, "key_bind_meta-meta2-4~", "/iset **scroll_bottom");
224 weechat
::buffer_set
($iset_buffer, "key_bind_meta-v", "/iset **toggle_help");
225 weechat
::buffer_set
($iset_buffer, "key_bind_meta-p", "/iset **toggle_show_plugin_desc");
226 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_filter", $filter);
236 @options_values = ();
237 @options_is_null = ();
238 $option_max_length = 0;
239 my %options_internal = ();
245 my $infolist = weechat
::infolist_get
("option", "", $filter);
246 while (weechat
::infolist_next
($infolist))
248 $key = sprintf("%08d", $i);
249 my $name = weechat
::infolist_string
($infolist, "full_name");
250 next if (weechat
::config_boolean
($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1);
251 my $type = weechat
::infolist_string
($infolist, "type");
252 my $value = weechat
::infolist_string
($infolist, "value");
253 my $is_null = weechat
::infolist_integer
($infolist, "value_is_null");
255 $options_internal{$name}{"type"} = $type;
256 $options_internal{$name}{"value"} = $value;
257 $options_internal{$name}{"is_null"} = $is_null;
258 $option_max_length = length($name) if (length($name) > $option_max_length);
260 $iset_struct{$key} = $options_internal{$name};
261 push(@iset_focus, $iset_struct{$key});
264 weechat
::infolist_free
($infolist);
266 foreach my $name (sort keys %options_internal)
268 push(@options_names, $name);
269 push(@options_types, $options_internal{$name}{"type"});
270 push(@options_values, $options_internal{$name}{"value"});
271 push(@options_is_null, $options_internal{$name}{"is_null"});
277 my $var_value = $_[0];
280 @options_values = ();
281 @options_is_null = ();
282 $option_max_length = 0;
283 my %options_internal = ();
285 my $infolist = weechat
::infolist_get
("option", "", "*");
286 $var_value =~ tr/[a-z][0-9].=-_!//cd; # kill meta chars
287 $var_value = lc($var_value);
288 while (weechat
::infolist_next
($infolist))
290 my $name = weechat
::infolist_string
($infolist, "full_name");
291 next if (weechat
::config_boolean
($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1);
292 my $type = weechat
::infolist_string
($infolist, "type");
293 my $value = weechat
::infolist_string
($infolist, "value");
294 my $is_null = weechat
::infolist_integer
($infolist, "value_is_null");
295 if (lc($value) =~ m/$var_value/)
297 $options_internal{$name}{"type"} = $type;
298 $options_internal{$name}{"value"} = $value;
299 $options_internal{$name}{"is_null"} = $is_null;
300 $option_max_length = length($name) if (length($name) > $option_max_length);
304 weechat
::infolist_free
($infolist);
305 foreach my $name (sort keys %options_internal)
307 push(@options_names, $name);
308 push(@options_types, $options_internal{$name}{"type"});
309 push(@options_values, $options_internal{$name}{"value"});
310 push(@options_is_null, $options_internal{$name}{"is_null"});
312 weechat
::buffer_set
($iset_buffer, "localvar_set_iset_filter", $var_value);
315 sub iset_refresh_line
317 if ($iset_buffer ne "")
320 if ($y <= $#options_names)
322 return if (! defined($options_types[$y]));
323 my $format = sprintf("%%s%%-%ds %%s %%-7s %%s %%s%%s%%s", $option_max_length);
325 $around = "\"" if ((!$options_is_null[$y]) && ($options_types[$y] eq "string"));
327 my $color1 = weechat
::color
(weechat
::config_color
($options_iset{"color_option"}));
328 my $color2 = weechat
::color
(weechat
::config_color
($options_iset{"color_type"}));
330 if ($options_is_null[$y])
332 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_undef"}));
336 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value"}));
338 if ($y == $current_line)
340 $color1 = weechat
::color
(weechat
::config_color
($options_iset{"color_option_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
341 $color2 = weechat
::color
(weechat
::config_color
($options_iset{"color_type_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
342 if ($options_is_null[$y])
344 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_undef_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
348 $color3 = weechat
::color
(weechat
::config_color
($options_iset{"color_value_selected"}).",".weechat
::config_color
($options_iset{"color_bg_selected"}));
351 my $value = $options_values[$y];
352 $value = "(undef)" if ($options_is_null[$y]);
353 my $strline = sprintf($format,
354 $color1, $options_names[$y],
355 $color2, $options_types[$y],
356 $color3, $around, $value, $around);
357 weechat
::print_y
($iset_buffer, $y, $strline);
365 if (($iset_buffer ne "") && ($#options_names >= 0))
367 foreach my $y (0 .. $#options_names)
369 iset_refresh_line
($y);
373 weechat
::bar_item_update
("isetbar_help") if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1);
376 sub iset_full_refresh
378 $iset_buffer = weechat
::buffer_search
($LANG, $PRGNAME);
379 if ($iset_buffer ne "")
381 weechat
::buffer_clear
($iset_buffer);
382 # search for "*" in $filter.
383 if ($filter =~ m/\*/)
389 iset_get_values
($filter);
390 $iset_filter_title = "Filter (by value): ";
392 if (weechat
::config_boolean
($options_iset{"show_plugin_description"}) == 1)
394 iset_set_current_line
($current_line);
397 $current_line = $#options_names if ($current_line > $#options_names);
400 weechat
::command
($iset_buffer, "/window refresh");
404 sub iset_set_current_line
406 my $new_current_line = $_[0];
407 my $old_current_line = $current_line;
408 $current_line = $new_current_line;
409 $current_line = $#options_names if ($current_line > $#options_names);
410 if ($old_current_line != $current_line)
412 iset_refresh_line
($old_current_line);
413 iset_refresh_line
($current_line);
414 weechat
::bar_item_update
("isetbar_help") if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1);
418 sub iset_signal_window_scrolled_cb
420 my ($data, $signal, $signal_data) = ($_[0], $_[1], $_[2]);
421 if ($iset_buffer ne "")
423 my $infolist = weechat
::infolist_get
("window", $signal_data, "");
424 if (weechat
::infolist_next
($infolist))
426 if (weechat
::infolist_pointer
($infolist, "buffer") eq $iset_buffer)
428 my $old_current_line = $current_line;
429 my $new_current_line = $current_line;
430 my $start_line_y = weechat
::infolist_integer
($infolist, "start_line_y");
431 my $chat_height = weechat
::infolist_integer
($infolist, "chat_height");
432 $new_current_line += $chat_height if ($new_current_line < $start_line_y);
433 $new_current_line -= $chat_height if ($new_current_line >= $start_line_y + $chat_height);
434 $new_current_line = $start_line_y if ($new_current_line < $start_line_y);
435 $new_current_line = $start_line_y + $chat_height - 1 if ($new_current_line >= $start_line_y + $chat_height);
436 iset_set_current_line
($new_current_line);
439 weechat
::infolist_free
($infolist);
442 return weechat
::WEECHAT_RC_OK
;
445 sub iset_get_window_number
447 if ($iset_buffer ne "")
449 my $window = weechat
::window_search_with_buffer
($iset_buffer);
450 return "-window ".weechat
::window_get_integer
($window, "number")." " if ($window ne "");
455 sub iset_check_line_outside_window
457 if ($iset_buffer ne "")
460 if ($wee_version_number >= 0x00030500)
462 my $window = weechat
::window_search_with_buffer
($iset_buffer);
463 $infolist = weechat
::infolist_get
("window", $window, "") if $window;
467 $infolist = weechat
::infolist_get
("window", "", "current");
471 if (weechat
::infolist_next
($infolist))
473 my $start_line_y = weechat
::infolist_integer
($infolist, "start_line_y");
474 my $chat_height = weechat
::infolist_integer
($infolist, "chat_height");
475 my $window_number = "";
476 if ($wee_version_number >= 0x00030500)
478 $window_number = "-window ".weechat
::infolist_integer
($infolist, "number")." ";
480 if ($start_line_y > $current_line)
482 weechat
::command
($iset_buffer, "/window scroll ".$window_number."-".($start_line_y - $current_line));
486 if ($start_line_y <= $current_line - $chat_height)
488 weechat
::command
($iset_buffer, "/window scroll ".$window_number."+".($current_line - $start_line_y - $chat_height + 1));
492 weechat
::infolist_free
($infolist);
497 sub iset_get_option_name_index
499 my $option_name = $_[0];
501 while ($index <= $#options_names)
503 return -1 if ($options_names[$index] gt $option_name);
504 return $index if ($options_names[$index] eq $option_name);
512 my ($data, $option_name, $value) = ($_[0], $_[1], $_[2]);
514 if ($iset_buffer ne "")
516 return weechat
::WEECHAT_RC_OK
if (weechat
::info_get
("weechat_upgrading", "") eq "1");
518 my $index = iset_get_option_name_index
($option_name);
521 # refresh info about changed option
522 my $infolist = weechat
::infolist_get
("option", "", $option_name);
525 weechat
::infolist_next
($infolist);
526 if (weechat
::infolist_fields
($infolist))
528 $options_types[$index] = weechat
::infolist_string
($infolist, "type");
529 $options_values[$index] = weechat
::infolist_string
($infolist, "value");
530 $options_is_null[$index] = weechat
::infolist_integer
($infolist, "value_is_null");
531 iset_refresh_line
($index);
532 iset_title
($iset_filter_title) if ($option_name eq "iset.look.show_current_line");
538 weechat
::infolist_free
($infolist);
543 iset_full_refresh
() if ($option_name ne "weechat.bar.isetbar.hidden");
547 return weechat
::WEECHAT_RC_OK
;
552 my $option = weechat
::config_get
($_[0]);
553 weechat
::config_option_set
($option, $_[1], 1) if ($option ne "");
556 sub iset_reset_option
558 my $option = weechat
::config_get
($_[0]);
559 weechat
::config_option_reset
($option, 1) if ($option ne "");
562 sub iset_unset_option
564 my $option = weechat
::config_get
($_[0]);
565 weechat
::config_option_unset
($option) if ($option ne "");
566 weechat
::buffer_clear
($iset_buffer);
573 my ($data, $buffer, $args) = ($_[0], $_[1], $_[2]);
575 if (($args ne "") && (substr($args, 0, 2) ne "**"))
577 if (substr($args, 0, 1) eq weechat
::config_string
($options_iset{"value_search_char"}))
579 my $var_value = substr($args, 1); # cut value_search_char
580 if ($iset_buffer ne "")
582 weechat
::buffer_clear
($iset_buffer);
583 weechat
::command
($iset_buffer, "/window refresh");
586 iset_get_values
($var_value);
588 weechat
::buffer_set
($iset_buffer, "display", "1");
589 $iset_filter_title = "Filter (by value): ";
590 $filter = $var_value;
591 iset_title
($iset_filter_title);
592 return weechat
::WEECHAT_RC_OK
;
598 my $ptrbuf = weechat
::buffer_search
($LANG, $PRGNAME);
604 weechat
::buffer_set
(weechat
::buffer_search
($LANG, $PRGNAME), "display", "1");
605 return weechat
::WEECHAT_RC_OK
;
610 if ($iset_buffer eq "")
618 iset_full_refresh
() if ($filter_set);
623 weechat
::buffer_set
($iset_buffer, "display", "1");
627 if ($args eq "**refresh")
633 if ($current_line > 0)
636 iset_refresh_line
($current_line + 1);
637 iset_refresh_line
($current_line);
638 iset_check_line_outside_window
();
641 if ($args eq "**down")
643 if ($current_line < $#options_names)
646 iset_refresh_line
($current_line - 1);
647 iset_refresh_line
($current_line);
648 iset_check_line_outside_window
();
651 if ($args eq "**left" && $wee_version_number >= 0x00030600)
653 weechat
::command
($iset_buffer, "/window scroll_horiz ".iset_get_window_number
()."-".weechat
::config_integer
($options_iset{"scroll_horiz"})."%");
655 if ($args eq "**right" && $wee_version_number >= 0x00030600)
657 weechat
::command
($iset_buffer, "/window scroll_horiz ".iset_get_window_number
().weechat
::config_integer
($options_iset{"scroll_horiz"})."%");
659 if ($args eq "**scroll_top")
661 my $old_current_line = $current_line;
663 iset_refresh_line
($old_current_line);
664 iset_refresh_line
($current_line);
665 weechat
::command
($iset_buffer, "/window scroll_top ".iset_get_window_number
());
667 if ($args eq "**scroll_bottom")
669 my $old_current_line = $current_line;
670 $current_line = $#options_names;
671 iset_refresh_line
($old_current_line);
672 iset_refresh_line
($current_line);
673 weechat
::command
($iset_buffer, "/window scroll_bottom ".iset_get_window_number
());
675 if ($args eq "**toggle")
677 if ($options_types[$current_line] eq "boolean")
679 iset_set_option
($options_names[$current_line], "toggle");
682 if ($args eq "**incr")
684 if (($options_types[$current_line] eq "integer")
685 || ($options_types[$current_line] eq "color"))
687 iset_set_option
($options_names[$current_line], "++1");
690 if ($args eq "**decr")
692 if (($options_types[$current_line] eq "integer")
693 || ($options_types[$current_line] eq "color"))
695 iset_set_option
($options_names[$current_line], "--1");
698 if ($args eq "**reset")
700 iset_reset_option
($options_names[$current_line]);
702 if ($args eq "**unset")
704 iset_unset_option
($options_names[$current_line]);
706 if ($args eq "**toggle_help")
708 if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1)
710 weechat
::config_option_set
($options_iset{"show_help_bar"},0,1);
715 weechat
::config_option_set
($options_iset{"show_help_bar"},1,1);
719 if ($args eq "**toggle_show_plugin_desc")
721 if (weechat
::config_boolean
($options_iset{"show_plugin_description"}) == 1)
723 weechat
::config_option_set
($options_iset{"show_plugin_description"},0,1);
725 iset_check_line_outside_window
();
729 weechat
::config_option_set
($options_iset{"show_plugin_description"},1,1);
731 iset_check_line_outside_window
();
734 if ($args eq "**set")
737 my $value = $options_values[$current_line];
738 if ($options_is_null[$current_line])
744 $quote = "\"" if ($options_types[$current_line] eq "string");
746 weechat
::buffer_set
($iset_buffer, "input", "/set ".$options_names[$current_line]." ".$quote.$value.$quote);
747 weechat
::command
($iset_buffer, "/input move_beginning_of_line");
748 weechat
::command
($iset_buffer, "/input move_next_word");
749 weechat
::command
($iset_buffer, "/input move_next_word");
750 weechat
::command
($iset_buffer, "/input move_next_char");
751 weechat
::command
($iset_buffer, "/input move_next_char") if ($quote ne "");
754 weechat
::bar_item_update
("isetbar_help") if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1);
755 return weechat
::WEECHAT_RC_OK
;
760 my ($redraw) = ($_[0]);
762 return '' if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 0);
764 if (not defined $options_names[$current_line])
766 return "No option selected. Set a new filter using command line (use '*' to see all options)";
768 if ($options_name_copy eq $options_names[$current_line] and not defined $redraw)
772 $options_name_copy = $options_names[$current_line];
774 $optionlist = weechat
::infolist_get
("option", "", $options_names[$current_line]);
775 weechat
::infolist_next
($optionlist);
776 my $full_name = weechat
::infolist_string
($optionlist,"full_name");
777 my $option_desc = "";
778 my $option_default_value = "";
779 my $option_range = "";
780 my $possible_values = "";
781 my $re = qq(\Q$full_name);
782 if (grep (/^$re$/,$options_names[$current_line]))
784 $option_desc = weechat
::infolist_string
($optionlist, "description_nls");
785 $option_desc = weechat
::infolist_string
($optionlist, "description") if ($option_desc eq "");
786 $option_desc = "No help found" if ($option_desc eq "");
787 $option_default_value = weechat
::infolist_string
($optionlist, "default_value");
788 $possible_values = weechat
::infolist_string
($optionlist, "string_values") if (weechat
::infolist_string
($optionlist, "string_values") ne "");
789 if ((weechat
::infolist_string
($optionlist, "type") eq "integer") && ($possible_values eq ""))
791 $option_range = weechat
::infolist_integer
($optionlist, "min")
792 ." .. ".weechat
::infolist_integer
($optionlist, "max");
795 weechat
::infolist_free
($optionlist);
798 $description = weechat
::color
(weechat
::config_color
($options_iset{"color_help_option_name"})).$options_names[$current_line]
799 .weechat
::color
("bar_fg").": "
800 .weechat
::color
(weechat
::config_color
($options_iset{"color_help_text"})).$option_desc;
802 # show additional infos like default value and possible values
804 if (weechat
::config_boolean
($options_iset{"show_help_extra_info"}) == 1)
807 weechat
::color
("bar_delim")." ["
808 .weechat
::color
("bar_fg")."default: "
809 .weechat
::color
("bar_delim")."\""
810 .weechat
::color
(weechat
::config_color
($options_iset{"color_help_default_value"})).$option_default_value
811 .weechat
::color
("bar_delim")."\"";
812 if ($option_range ne "")
814 $description .= weechat
::color
("bar_fg").", values: ".$option_range;
816 if ($possible_values ne "")
818 $possible_values =~ s/\|/", "/g; # replace '|' to '", "'
819 $description .= weechat
::color
("bar_fg").", values: ". "\"" . $possible_values . "\"";
822 $description .= weechat
::color
("bar_delim")."]";
827 sub iset_check_condition_isetbar_cb
829 my ($data, $modifier, $modifier_data, $string) = ($_[0], $_[1], $_[2], $_[3]);
830 my $buffer = weechat
::window_get_pointer
($modifier_data, "buffer");
833 if ((weechat
::buffer_get_string
($buffer, "plugin") eq $LANG)
834 && (weechat
::buffer_get_string
($buffer, "name") eq $PRGNAME))
845 my $barhidden = weechat
::config_get
("weechat.bar.isetbar.hidden");
850 if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1)
852 if (weechat
::config_boolean
($barhidden))
854 weechat
::config_option_set
($barhidden, 0, 1);
860 if (!weechat
::config_boolean
($barhidden))
862 weechat
::config_option_set
($barhidden, 1, 1);
868 sub iset_signal_buffer_switch_cb
870 my $buffer_pointer = $_[2];
872 $show_bar = 1 if (weechat
::buffer_get_integer
($iset_buffer, "num_displayed") > 0);
873 iset_show_bar
($show_bar);
874 iset_check_line_outside_window
() if ($buffer_pointer eq $iset_buffer);
875 return weechat
::WEECHAT_RC_OK
;
880 return iset_get_help
();
883 sub iset_upgrade_ended
890 # when script is unloaded, we hide bar
894 # -------------------------------[ mouse support ]-------------------------------------
896 sub hook_focus_iset_cb
899 my $bar_item_line = int($info{"_bar_item_line"});
901 if (($info{"_buffer_name"} eq $PRGNAME) && $info{"_buffer_plugin"} eq $LANG && ($bar_item_line >= 0) && ($bar_item_line <= $#iset_focus))
903 $hash = $iset_focus[$bar_item_line];
908 my $hash_focus = $iset_focus[0];
909 foreach my $key (keys %$hash_focus)
917 # _chat_line_y contains selected line
918 sub iset_hsignal_mouse_cb
920 my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]});
922 if ($hash{"_buffer_name"} eq $PRGNAME && ($hash{"_buffer_plugin"} eq $LANG))
924 if ($hash{"_key"} eq "button1")
926 $current_line = $hash{"_chat_line_y"};
927 iset_refresh_line
($current_line);
930 elsif ($hash{"_key"} eq "button2")
932 if ($options_types[$hash{"_chat_line_y"}] eq "boolean")
934 iset_set_option
($options_names[$hash{"_chat_line_y"}], "toggle");
935 $current_line = $hash{"_chat_line_y"};
936 iset_refresh_line
($current_line);
939 elsif ($options_types[$hash{"_chat_line_y"}] eq "string")
941 $current_line = $hash{"_chat_line_y"};
942 iset_refresh_line
($current_line);
944 weechat
::command
("", "/$PRGNAME **set");
947 elsif ($hash{"_key"} eq "button2-gesture-left" or $hash{"_key"} eq "button2-gesture-left-long")
949 if ($options_types[$hash{"_chat_line_y"}] eq "integer" or ($options_types[$hash{"_chat_line_y"}] eq "color"))
951 $current_line = $hash{"_chat_line_y"};
952 iset_refresh_line
($current_line);
954 my $distance = distance
($hash{"_chat_line_x"},$hash{"_chat_line_x2"});
955 weechat
::command
("", "/repeat $distance /$PRGNAME **decr");
958 elsif ($hash{"_key"} eq "button2-gesture-right" or $hash{"_key"} eq "button2-gesture-right-long")
960 if ($options_types[$hash{"_chat_line_y"}] eq "integer" or ($options_types[$hash{"_chat_line_y"}] eq "color"))
962 $current_line = $hash{"_chat_line_y"};
963 iset_refresh_line
($current_line);
965 my $distance = distance
($hash{"_chat_line_x"},$hash{"_chat_line_x2"});
966 weechat
::command
("", "/repeat $distance /$PRGNAME **incr");
973 my ($x1,$x2) = ($_[0], $_[1]);
975 $distance = $x1 - $x2;
976 $distance = abs($distance);
980 $distance = $distance / 3;
981 $distance = 1 if ($distance == 0);
983 elsif ($distance == 0)
990 # -----------------------------------[ config ]---------------------------------------
994 $iset_config_file = weechat
::config_new
($ISET_CONFIG_FILE_NAME,"iset_config_reload_cb","");
995 return if ($iset_config_file eq "");
998 my $section_color = weechat
::config_new_section
($iset_config_file,"color", 0, 0, "", "", "", "", "", "", "", "", "", "");
999 if ($section_color eq "")
1001 weechat
::config_free
($iset_config_file);
1004 $options_iset{"color_option"} = weechat
::config_new_option
(
1005 $iset_config_file, $section_color,
1006 "option", "color", "Color for option name in iset buffer", "", 0, 0,
1007 "default", "default", 0, "", "", "full_refresh_cb", "", "", "");
1008 $options_iset{"color_option_selected"} = weechat
::config_new_option
(
1009 $iset_config_file, $section_color,
1010 "option_selected", "color", "Color for selected option name in iset buffer", "", 0, 0,
1011 "white", "white", 0, "", "", "full_refresh_cb", "", "", "");
1012 $options_iset{"color_type"} = weechat
::config_new_option
(
1013 $iset_config_file, $section_color,
1014 "type", "color", "Color for option type (integer, boolean, string)", "", 0, 0,
1015 "brown", "brown", 0, "", "", "full_refresh_cb", "", "", "");
1016 $options_iset{"color_type_selected"} = weechat
::config_new_option
(
1017 $iset_config_file, $section_color,
1018 "type_selected", "color", "Color for selected option type (integer, boolean, string)", "", 0, 0,
1019 "yellow", "yellow", 0, "", "", "full_refresh_cb", "", "", "");
1020 $options_iset{"color_value"} = weechat
::config_new_option
(
1021 $iset_config_file, $section_color,
1022 "value", "color", "Color for option value", "", 0, 0,
1023 "cyan", "cyan", 0, "", "", "full_refresh_cb", "", "", "");
1024 $options_iset{"color_value_selected"} = weechat
::config_new_option
(
1025 $iset_config_file, $section_color,
1026 "value_selected", "color", "Color for selected option value", "", 0, 0,
1027 "lightcyan", "lightcyan", 0, "", "", "full_refresh_cb", "", "", "");
1028 $options_iset{"color_value_undef"} = weechat
::config_new_option
(
1029 $iset_config_file, $section_color,
1030 "value_undef", "color", "Color for option value undef", "", 0, 0,
1031 "green", "green", 0, "", "", "full_refresh_cb", "", "", "");
1032 $options_iset{"color_value_undef_selected"} = weechat
::config_new_option
(
1033 $iset_config_file, $section_color,
1034 "value_undef_selected", "color", "Color for selected option value undef", "", 0, 0,
1035 "lightgreen", "lightgreen", 0, "", "", "full_refresh_cb", "", "", "");
1036 $options_iset{"color_bg_selected"} = weechat
::config_new_option
(
1037 $iset_config_file, $section_color,
1038 "bg_selected", "color", "Background color for current selected option", "", 0, 0,
1039 "red", "red", 0, "", "", "full_refresh_cb", "", "", "");
1040 $options_iset{"color_help_option_name"} = weechat
::config_new_option
(
1041 $iset_config_file, $section_color,
1042 "help_option_name", "color", "Color for option name in help-bar", "", 0, 0,
1043 "white", "white", 0, "", "", "bar_refresh", "", "", "");
1044 $options_iset{"color_help_text"} = weechat
::config_new_option
(
1045 $iset_config_file, $section_color,
1046 "help_text", "color", "Color for option description in help-bar", "", 0, 0,
1047 "default", "default", 0, "", "", "bar_refresh", "", "", "");
1048 $options_iset{"color_help_default_value"} = weechat
::config_new_option
(
1049 $iset_config_file, $section_color,
1050 "help_default_value", "color", "Color for default option value in help-bar", "", 0, 0,
1051 "green", "green", 0, "", "", "bar_refresh", "", "", "");
1054 my $section_help = weechat
::config_new_section
($iset_config_file,"help", 0, 0, "", "", "", "", "", "", "", "", "", "");
1055 if ($section_help eq "")
1057 weechat
::config_free
($iset_config_file);
1060 $options_iset{"show_help_bar"} = weechat
::config_new_option
(
1061 $iset_config_file, $section_help,
1062 "show_help_bar", "boolean", "Show help bar", "", 0, 0,
1063 "on", "on", 0, "", "", "toggle_help_cb", "", "", "");
1064 $options_iset{"show_help_extra_info"} = weechat
::config_new_option
(
1065 $iset_config_file, $section_help,
1066 "show_help_extra_info", "boolean", "Show additional information in help bar (default value, max./min. value) ", "", 0, 0,
1067 "on", "on", 0, "", "", "", "", "", "");
1068 $options_iset{"show_plugin_description"} = weechat
::config_new_option
(
1069 $iset_config_file, $section_help,
1070 "show_plugin_description", "boolean", "Show plugin description in iset buffer", "", 0, 0,
1071 "on", "on", 0, "", "", "full_refresh_cb", "", "", "");
1074 my $section_look = weechat
::config_new_section
($iset_config_file, "look", 0, 0, "", "", "", "", "", "", "", "", "", "");
1075 if ($section_look eq "")
1077 weechat
::config_free
($iset_config_file);
1080 $options_iset{"value_search_char"} = weechat
::config_new_option
(
1081 $iset_config_file, $section_look,
1082 "value_search_char", "string", "Trigger char to tell iset to search for value instead of option (for example: =red)", "", 0, 0,
1083 "=", "=", 0, "", "", "", "", "", "");
1084 $options_iset{"scroll_horiz"} = weechat
::config_new_option
(
1085 $iset_config_file, $section_look,
1086 "scroll_horiz", "integer", "scroll content of iset buffer n%", "", 1, 100,
1087 "10", "10", 0, "", "", "", "", "", "");
1088 $options_iset{"show_current_line"} = weechat
::config_new_option
(
1089 $iset_config_file, $section_look,
1090 "show_current_line", "boolean", "show current line in title bar.", "", 0, 0,
1091 "on", "on", 0, "", "", "", "", "", "");
1094 sub iset_config_reload_cb
1096 my ($data,$config_file) = ($_[0], $_[1]);
1097 return weechat
::config_reload
($config_file)
1100 sub iset_config_read
1102 return weechat
::config_read
($iset_config_file) if ($iset_config_file ne "");
1105 sub iset_config_write
1107 return weechat
::config_write
($iset_config_file) if ($iset_config_file ne "");
1112 iset_full_refresh
();
1113 return weechat
::WEECHAT_RC_OK
;
1119 weechat
::bar_item_update
("isetbar_help") if (weechat
::config_boolean
($options_iset{"show_help_bar"}) == 1);
1120 return weechat
::WEECHAT_RC_OK
;
1125 my $value = weechat
::config_boolean
($options_iset{"show_help_bar"});
1126 iset_show_bar
($value);
1127 return weechat
::WEECHAT_RC_OK
;
1130 # -----------------------------------[ main ]-----------------------------------------
1132 weechat
::register
($PRGNAME, $AUTHOR, $VERSION, $LICENSE,
1133 $DESCR, "iset_end", "");
1135 $wee_version_number = weechat
::info_get
("version_number", "") || 0;
1140 weechat
::hook_command
($PRGNAME, "Interactive set", "f <file> || s <section> || [=]<text>",
1141 "f file : show options for a file\n".
1142 "s section : show options for a section\n".
1143 "text : show options with 'text' in name\n".
1144 weechat
::config_string
($options_iset{"value_search_char"})."text : show options with 'text' in value\n\n".
1145 "Keys for iset buffer:\n".
1146 "f11,f12 : move iset content left/right\n".
1147 "up,down : move one option up/down\n".
1148 "pgup,pdwn : move one page up/down\n".
1149 "home,end : move to first/last option\n".
1150 "ctrl+'L' : refresh options and screen\n".
1151 "alt+space : toggle boolean on/off\n".
1152 "alt+'+' : increase value (for integer or color)\n".
1153 "alt+'-' : decrease value (for integer or color)\n".
1154 "alt+'i',alt+'r': reset value of option\n".
1155 "alt+'i',alt+'u': unset option\n".
1156 "alt+enter : set new value for option (edit it with command line)\n".
1157 "text,enter : set a new filter using command line (use '*' to see all options)\n".
1158 "alt+'v' : toggle help bar on/off\n".
1159 "alt+'p' : toggle option \"show_plugin_description\" on/off\n".
1161 "standard mouse actions:\n".
1162 "wheel up / wheel down : move option up/down\n".
1163 "left-mouse-button : select an option from list\n".
1164 "right-mouse-button : toggle boolean (on/off) or set a new value for option (edit it with command line)\n".
1165 "right-mouse-button + gesture left/right: increase/decrease value (for integer or color)\n".
1168 " show options for file 'weechat'\n".
1169 " /iset f weechat\n".
1170 " show options for file 'irc'\n".
1172 " show options for section 'look'\n".
1174 " show all options with text 'nicklist' in name\n".
1175 " /iset nicklist\n".
1176 " show all values which contain 'red'. '" . weechat
::config_string
($options_iset{"value_search_char"}) . "' is a trigger char.\n".
1177 " /iset ". weechat
::config_string
($options_iset{"value_search_char"}) ."red\n",
1178 "", "iset_cmd_cb", "");
1179 weechat
::hook_signal
("upgrade_ended", "iset_upgrade_ended", "");
1180 weechat
::hook_signal
("window_scrolled", "iset_signal_window_scrolled_cb", "");
1181 weechat
::hook_signal
("buffer_switch", "iset_signal_buffer_switch_cb","");
1182 weechat
::bar_item_new
("isetbar_help", "iset_item_cb", "");
1183 weechat
::bar_new
("isetbar", "on", "0", "window", "", "top", "horizontal",
1184 "vertical", "3", "3", "default", "cyan", "default", "1",
1186 weechat
::hook_modifier
("bar_condition_isetbar", "iset_check_condition_isetbar_cb", "");
1187 weechat
::hook_config
("*", "iset_config_cb", "");
1188 $iset_buffer = weechat
::buffer_search
($LANG, $PRGNAME);
1189 iset_init
() if ($iset_buffer ne "");
1191 if ($wee_version_number >= 0x00030600)
1193 weechat
::hook_focus
("chat", "hook_focus_iset_cb", "");
1194 weechat
::hook_hsignal
($PRGNAME."_mouse", "iset_hsignal_mouse_cb", "");
1195 weechat
::key_bind
("mouse", \
%mouse_keys);