Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1645 lines
66 KiB

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