X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/2512c622d1a79a40a95f4d26dda652fc825930fc..f07f9d2d3f47ad933d843129c0d280c1c56ce6a9:/weechat/perl/iset.pl diff --git a/weechat/perl/iset.pl b/weechat/perl/iset.pl index 377b7c3..d6c9364 100644 --- a/weechat/perl/iset.pl +++ b/weechat/perl/iset.pl @@ -1,6 +1,6 @@ # -# Copyright (C) 2008-2013 Sebastien Helleu -# Copyright (C) 2010-2012 Nils Görs +# Copyright (C) 2008-2017 Sebastien Helleu +# Copyright (C) 2010-2017 Nils Görs # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,6 +19,27 @@ # # History: # +# 2017-04-14, nils_2 +# version 4.3: add option "use_color" (https://github.com/weechat/scripts/issues/93) +# 2016-07-08, nils_2 +# version 4.2: add diff function +# 2016-02-06, Sebastien Helleu : +# version 4.1: remove debug print +# 2015-12-24, Sebastien Helleu : +# version 4.0: add support of parent options (inherited values in irc servers) +# with WeeChat >= 1.4 +# 2015-05-16, Sebastien Helleu : +# version 3.9: fix cursor position when editing an option with WeeChat >= 1.2 +# 2015-05-02, arza : +# version 3.8: don't append "null" to /set when setting an undefined setting +# 2015-05-01, nils_2 : +# version 3.7: fix two perl warnings (reported by t3chguy) +# 2014-09-30, arza : +# version 3.6: fix current line counter when options aren't found +# 2014-06-03, nils_2 : +# version 3.5: add new option "use_mute" +# 2014-01-30, stfn : +# version 3.4: add new options "color_value_diff" and "color_value_diff_selected" # 2014-01-16, luz : # version 3.3: fix bug with column alignment in iset buffer when option # name contains unicode characters @@ -111,7 +132,7 @@ use strict; my $PRGNAME = "iset"; -my $VERSION = "3.3"; +my $VERSION = "4.3"; my $DESCR = "Interactive Set for configuration options"; my $AUTHOR = "Sebastien Helleu "; my $LICENSE = "GPL3"; @@ -123,8 +144,11 @@ my $iset_buffer = ""; my $wee_version_number = 0; my @iset_focus = (); my @options_names = (); +my @options_parent_names = (); my @options_types = (); my @options_values = (); +my @options_default_values = (); +my @options_parent_values = (); my @options_is_null = (); my $option_max_length = 0; my $current_line = 0; @@ -132,7 +156,7 @@ my $filter = "*"; my $description = ""; my $options_name_copy = ""; my $iset_filter_title = ""; -# search modes: 0 = index() on value, 1 = grep() on value, 2 = grep() on option, 3 = grep on option & value +# 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 my $search_mode = 2; my $search_value = ""; my $help_text_keys = "alt + space: toggle, +/-: increase/decrease, enter: change, ir: reset, iu: unset, v: toggle help bar"; @@ -150,7 +174,17 @@ sub iset_title if ($iset_buffer ne "") { my $current_line_counter = ""; - $current_line_counter = ($current_line + 1) . "/" if (weechat::config_boolean($options_iset{"show_current_line"}) == 1); + if (weechat::config_boolean($options_iset{"show_current_line"}) == 1) + { + if (@options_names eq 0) + { + $current_line_counter = "0/"; + } + else + { + $current_line_counter = ($current_line + 1) . "/"; + } + } my $show_filter = ""; if ($search_mode eq 0) { @@ -172,6 +206,12 @@ sub iset_title $filter = "*" if ($filter eq ""); $show_filter = $filter; } + elsif ($search_mode == 4 or $search_mode == 5) + { + $iset_filter_title = "diff: "; + $show_filter = "all"; + $show_filter = $search_value if $search_mode == 5; + } elsif ($search_mode eq 3) { $iset_filter_title = "(option) "; @@ -220,6 +260,10 @@ sub iset_create_filter sub iset_buffer_input { my ($data, $buffer, $string) = ($_[0], $_[1], $_[2]); + + # string begins with space? + return weechat::WEECHAT_RC_OK if (substr($string, 0, 1 ) eq " "); + if ($string eq "q") { weechat::buffer_close($buffer); @@ -240,10 +284,27 @@ sub iset_buffer_input weechat::buffer_set($iset_buffer, "localvar_set_iset_search_value", $search_value); } } + # show all diff values + elsif ($string eq "d") + { + $search_mode = 4; +# iset_title(); + iset_create_filter("*"); + iset_get_options("*"); + } + elsif ( $array_count >= 2 and $cmd_array[0] eq "d") + { + $search_mode = 5; + $search_value = substr($cmd_array[1], 0); # cut value_search_char + $search_value = substr($cmd_array[2], 0) if ( $array_count > 2); # cut value_search_char + iset_create_filter($search_value); + iset_get_options($search_value); + + } else { $search_mode = 2; - if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s") + if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s" ) { if ( defined $cmd_array[1] and substr($cmd_array[1], 0, 1) eq weechat::config_string($options_iset{"value_search_char"}) or defined $cmd_array[2] and substr($cmd_array[2], 0, 1) eq weechat::config_string($options_iset{"value_search_char"}) ) @@ -257,7 +318,8 @@ sub iset_buffer_input { iset_create_filter($string); iset_get_options($search_value); - }else + } + else { iset_create_filter($string); iset_get_options(""); @@ -326,8 +388,11 @@ sub iset_get_options $search_value = $var_value; @iset_focus = (); @options_names = (); + @options_parent_names = (); @options_types = (); @options_values = (); + @options_default_values = (); + @options_parent_values = (); @options_is_null = (); $option_max_length = 0; my %options_internal = (); @@ -343,31 +408,61 @@ sub iset_get_options { $key = sprintf("%08d", $i); my $name = weechat::infolist_string($infolist, "full_name"); + my $parent_name = weechat::infolist_string($infolist, "parent_name"); next if (weechat::config_boolean($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1); my $type = weechat::infolist_string($infolist, "type"); my $value = weechat::infolist_string($infolist, "value"); + my $default_value = weechat::infolist_string($infolist, "default_value"); + my $parent_value; + if ($parent_name && (($wee_version_number < 0x00040300) || (weechat::infolist_search_var($infolist, "parent_value")))) + { + $parent_value = weechat::infolist_string($infolist, "parent_value"); + } my $is_null = weechat::infolist_integer($infolist, "value_is_null"); + if ($search_mode == 3) { my $value = weechat::infolist_string($infolist, "value"); if ( grep /\Q$var_value/,lc($value) ) { + $options_internal{$name}{"parent_name"} = $parent_name; $options_internal{$name}{"type"} = $type; $options_internal{$name}{"value"} = $value; + $options_internal{$name}{"default_value"} = $default_value; + $options_internal{$name}{"parent_value"} = $parent_value; $options_internal{$name}{"is_null"} = $is_null; $option_max_length = length($name) if (length($name) > $option_max_length); - $iset_struct{$key} = $options_internal{$name}; - push(@iset_focus, $iset_struct{$key}); + $iset_struct{$key} = $options_internal{$name}; + push(@iset_focus, $iset_struct{$key}); + } + } + # search for diff? + elsif ( $search_mode == 4 or $search_mode == 5) + { + if ($value ne $default_value ) + { + $options_internal{$name}{"parent_name"} = $parent_name; + $options_internal{$name}{"type"} = $type; + $options_internal{$name}{"value"} = $value; + $options_internal{$name}{"default_value"} = $default_value; + $options_internal{$name}{"parent_value"} = $parent_value; + $options_internal{$name}{"is_null"} = $is_null; + $option_max_length = length($name) if (length($name) > $option_max_length); + $iset_struct{$key} = $options_internal{$name}; + push(@iset_focus, $iset_struct{$key}); } } else { + $options_internal{$name}{"parent_name"} = $parent_name; $options_internal{$name}{"type"} = $type; $options_internal{$name}{"value"} = $value; + $options_internal{$name}{"default_value"} = $default_value; + $options_internal{$name}{"parent_value"} = $parent_value; $options_internal{$name}{"is_null"} = $is_null; $option_max_length = length($name) if (length($name) > $option_max_length); - $iset_struct{$key} = $options_internal{$name}; - push(@iset_focus, $iset_struct{$key}); + $iset_struct{$key} = $options_internal{$name}; + push(@iset_focus, $iset_struct{$key}); } $i++; } @@ -376,8 +471,11 @@ sub iset_get_options foreach my $name (sort keys %options_internal) { push(@options_names, $name); + push(@options_parent_names, $options_internal{$name}{"parent_name"}); push(@options_types, $options_internal{$name}{"type"}); push(@options_values, $options_internal{$name}{"value"}); + push(@options_default_values, $options_internal{$name}{"default_value"}); + push(@options_parent_values, $options_internal{$name}{"parent_value"}); push(@options_is_null, $options_internal{$name}{"is_null"}); } } @@ -400,8 +498,11 @@ sub iset_search_values { my ($var_value,$search_mode) = ($_[0],$_[1]); @options_names = (); + @options_parent_names = (); @options_types = (); @options_values = (); + @options_default_values = (); + @options_parent_values = (); @options_is_null = (); $option_max_length = 0; my %options_internal = (); @@ -410,16 +511,26 @@ sub iset_search_values while (weechat::infolist_next($infolist)) { my $name = weechat::infolist_string($infolist, "full_name"); + my $parent_name = weechat::infolist_string($infolist, "parent_name"); next if (weechat::config_boolean($options_iset{"show_plugin_description"}) == 0 and index ($name, "plugins.desc.") != -1); my $type = weechat::infolist_string($infolist, "type"); my $is_null = weechat::infolist_integer($infolist, "value_is_null"); my $value = weechat::infolist_string($infolist, "value"); + my $default_value = weechat::infolist_string($infolist, "default_value"); + my $parent_value; + if ($parent_name && (($wee_version_number < 0x00040300) || (weechat::infolist_search_var($infolist, "parent_value")))) + { + $parent_value = weechat::infolist_string($infolist, "parent_value"); + } if ($search_mode) { if ( grep /\Q$var_value/,lc($value) ) { + $options_internal{$name}{"parent_name"} = $parent_name; $options_internal{$name}{"type"} = $type; $options_internal{$name}{"value"} = $value; + $options_internal{$name}{"default_value"} = $default_value; + $options_internal{$name}{"parent_value"} = $parent_value; $options_internal{$name}{"is_null"} = $is_null; $option_max_length = length($name) if (length($name) > $option_max_length); } @@ -429,8 +540,11 @@ sub iset_search_values # if ($value =~ /\Q$var_value/si) if (lc($value) eq $var_value) { + $options_internal{$name}{"parent_name"} = $parent_name; $options_internal{$name}{"type"} = $type; $options_internal{$name}{"value"} = $value; + $options_internal{$name}{"default_value"} = $default_value; + $options_internal{$name}{"parent_value"} = $parent_value; $options_internal{$name}{"is_null"} = $is_null; $option_max_length = length($name) if (length($name) > $option_max_length); } @@ -441,8 +555,11 @@ sub iset_search_values foreach my $name (sort keys %options_internal) { push(@options_names, $name); + push(@options_parent_names, $options_internal{$name}{"parent_name"}); push(@options_types, $options_internal{$name}{"type"}); push(@options_values, $options_internal{$name}{"value"}); + push(@options_default_values, $options_internal{$name}{"default_value"}); + push(@options_parent_values, $options_internal{$name}{"parent_value"}); push(@options_is_null, $options_internal{$name}{"is_null"}); } } @@ -471,9 +588,15 @@ sub iset_refresh_line my $color1 = weechat::color(weechat::config_color($options_iset{"color_option"})); my $color2 = weechat::color(weechat::config_color($options_iset{"color_type"})); my $color3 = ""; + my $color4 = ""; if ($options_is_null[$y]) { $color3 = weechat::color(weechat::config_color($options_iset{"color_value_undef"})); + $color4 = weechat::color(weechat::config_color($options_iset{"color_value"})); + } + elsif ($options_values[$y] ne $options_default_values[$y]) + { + $color3 = weechat::color(weechat::config_color($options_iset{"color_value_diff"})); } else { @@ -486,6 +609,11 @@ sub iset_refresh_line if ($options_is_null[$y]) { $color3 = weechat::color(weechat::config_color($options_iset{"color_value_undef_selected"}).",".weechat::config_color($options_iset{"color_bg_selected"})); + $color4 = weechat::color(weechat::config_color($options_iset{"color_value_selected"}).",".weechat::config_color($options_iset{"color_bg_selected"})); + } + elsif ($options_values[$y] ne $options_default_values[$y]) + { + $color3 = weechat::color(weechat::config_color($options_iset{"color_value_diff_selected"}).",".weechat::config_color($options_iset{"color_bg_selected"})); } else { @@ -493,7 +621,27 @@ sub iset_refresh_line } } my $value = $options_values[$y]; - $value = "(undef)" if ($options_is_null[$y]); + if (weechat::config_boolean($options_iset{"use_color"}) == 1 and $options_types[$y] eq "color") + { + $value = weechat::color($options_values[$y]) . $options_values[$y]; + } + if ($options_is_null[$y]) + { + $value = "null"; + if ($options_parent_names[$y]) + { + if (defined $options_parent_values[$y]) + { + my $around_parent = ""; + $around_parent = "\"" if ($options_types[$y] eq "string"); + $value .= $color1." -> ".$color4.$around_parent.$options_parent_values[$y].$around_parent; + } + else + { + $value .= $color1." -> ".$color3."null"; + } + } + } my $strline = sprintf($format, $color1, $options_names[$y], $padding, $color2, $options_types[$y], @@ -667,6 +815,39 @@ sub iset_get_option_name_index return -1; } +sub iset_refresh_option +{ + my $option_name = $_[0]; + my $index = $_[1]; + my $infolist = weechat::infolist_get("option", "", $option_name); + if ($infolist) + { + weechat::infolist_next($infolist); + if (weechat::infolist_fields($infolist)) + { + $options_parent_names[$index] = weechat::infolist_string($infolist, "parent_name"); + $options_types[$index] = weechat::infolist_string($infolist, "type"); + $options_values[$index] = weechat::infolist_string($infolist, "value"); + $options_default_values[$index] = weechat::infolist_string($infolist, "default_value"); + $options_is_null[$index] = weechat::infolist_integer($infolist, "value_is_null"); + $options_parent_values[$index] = undef; + if ($options_parent_names[$index] + && (($wee_version_number < 0x00040300) || (weechat::infolist_search_var($infolist, "parent_value")))) + { + $options_parent_values[$index] = weechat::infolist_string($infolist, "parent_value"); + } + iset_refresh_line($index); + iset_title() if ($option_name eq "iset.look.show_current_line"); + } + else + { + iset_full_refresh(1); # if not found, refresh fully without clearing buffer + weechat::print_y($iset_buffer, $#options_names + 1, ""); + } + weechat::infolist_free($infolist); + } +} + sub iset_config_cb { my ($data, $option_name, $value) = ($_[0], $_[1], $_[2]); @@ -679,24 +860,14 @@ sub iset_config_cb if ($index >= 0) { # refresh info about changed option - my $infolist = weechat::infolist_get("option", "", $option_name); - if ($infolist) + iset_refresh_option($option_name, $index); + # refresh any other option having this changed option as parent + foreach my $i (0 .. $#options_names) { - weechat::infolist_next($infolist); - if (weechat::infolist_fields($infolist)) + if ($options_parent_names[$i] eq $option_name) { - $options_types[$index] = weechat::infolist_string($infolist, "type"); - $options_values[$index] = weechat::infolist_string($infolist, "value"); - $options_is_null[$index] = weechat::infolist_integer($infolist, "value_is_null"); - iset_refresh_line($index); - iset_title() if ($option_name eq "iset.look.show_current_line"); + iset_refresh_option($options_names[$i], $i); } - else - { - iset_full_refresh(1); # if not found, refresh fully without clearing buffer - weechat::print_y($iset_buffer, $#options_names + 1, ""); - } - weechat::infolist_free($infolist); } } else @@ -771,20 +942,37 @@ sub iset_cmd_cb { # f/s option =value # option =value - $search_mode = 2; + $search_mode = 2; # grep on option if ( $array_count >= 2 and $cmd_array[0] ne "f" or $cmd_array[0] ne "s") { if ( defined $cmd_array[1] and substr($cmd_array[1], 0, 1) eq weechat::config_string($options_iset{"value_search_char"}) or defined $cmd_array[2] and substr($cmd_array[2], 0, 1) eq weechat::config_string($options_iset{"value_search_char"}) ) { - $search_mode = 3; + $search_mode = 3; # grep on option and value $search_value = substr($cmd_array[1], 1); # cut value_search_char $search_value = substr($cmd_array[2], 1) if ( $array_count > 2); # cut value_search_char } } + + # show all diff values + if ( $args eq "d") + { + $search_mode = 4; + $search_value = "*"; + $args = $search_value; + } + if ( $array_count >= 2 and $cmd_array[0] eq "d") + { + $search_mode = 5; + $search_value = substr($cmd_array[1], 0); # cut value_search_char + $search_value = substr($cmd_array[2], 0) if ( $array_count > 2); # cut value_search_char + $args = $search_value; + } + iset_create_filter($args); $filter_set = 1; my $ptrbuf = weechat::buffer_search($LANG, $PRGNAME); + if ($ptrbuf eq "") { iset_init(); @@ -940,18 +1128,34 @@ sub iset_cmd_cb my $value = $options_values[$current_line]; if ($options_is_null[$current_line]) { - $value = "null"; + $value = ""; } else { $quote = "\"" if ($options_types[$current_line] eq "string"); } - weechat::buffer_set($iset_buffer, "input", "/set ".$options_names[$current_line]." ".$quote.$value.$quote); - weechat::command($iset_buffer, "/input move_beginning_of_line"); - weechat::command($iset_buffer, "/input move_next_word"); - weechat::command($iset_buffer, "/input move_next_word"); - weechat::command($iset_buffer, "/input move_next_char"); - weechat::command($iset_buffer, "/input move_next_char") if ($quote ne ""); + $value = " ".$quote.$value.$quote if ($value ne "" or $quote ne ""); + + my $set_command = "/set"; + my $start_index = 5; + if (weechat::config_boolean($options_iset{"use_mute"}) == 1) + { + $set_command = "/mute ".$set_command; + $start_index += 11; + } + $set_command = $set_command." ".$options_names[$current_line].$value; + my $pos_space = index($set_command, " ", $start_index); + if ($pos_space < 0) + { + $pos_space = 9999; + } + else + { + $pos_space = $pos_space + 1; + $pos_space = $pos_space + 1 if ($quote ne ""); + } + weechat::buffer_set($iset_buffer, "input", $set_command); + weechat::buffer_set($iset_buffer, "input_pos", "".$pos_space); } } weechat::bar_item_update("isetbar_help") if (weechat::config_boolean($options_iset{"show_help_bar"}) == 1); @@ -1122,6 +1326,8 @@ sub iset_hsignal_mouse_cb { my ($data, $signal, %hash) = ($_[0], $_[1], %{$_[2]}); + return weechat::WEECHAT_RC_OK unless (@options_types); + if ($hash{"_buffer_name"} eq $PRGNAME && ($hash{"_buffer_plugin"} eq $LANG)) { if ($hash{"_key"} eq "button1") @@ -1233,6 +1439,14 @@ sub iset_config_init $iset_config_file, $section_color, "value_selected", "color", "Color for selected option value", "", 0, 0, "lightcyan", "lightcyan", 0, "", "", "full_refresh_cb", "", "", ""); + $options_iset{"color_value_diff"} = weechat::config_new_option( + $iset_config_file, $section_color, + "value_diff", "color", "Color for option value different from default", "", 0, 0, + "magenta", "magenta", 0, "", "", "full_refresh_cb", "", "", ""); + $options_iset{"color_value_diff_selected"} = weechat::config_new_option( + $iset_config_file, $section_color, + "value_diff_selected", "color", "Color for selected option value different from default", "", 0, 0, + "lightmagenta", "lightmagenta", 0, "", "", "full_refresh_cb", "", "", ""); $options_iset{"color_value_undef"} = weechat::config_new_option( $iset_config_file, $section_color, "value_undef", "color", "Color for option value undef", "", 0, 0, @@ -1297,6 +1511,14 @@ sub iset_config_init $iset_config_file, $section_look, "show_current_line", "boolean", "show current line in title bar.", "", 0, 0, "on", "on", 0, "", "", "", "", "", ""); + $options_iset{"use_mute"} = weechat::config_new_option( + $iset_config_file, $section_look, + "use_mute", "boolean", "/mute command will be used in input bar", "", 0, 0, + "off", "off", 0, "", "", "", "", "", ""); + $options_iset{"use_color"} = weechat::config_new_option( + $iset_config_file, $section_look, + "use_color", "boolean", "display the color value in the corresponding color", "", 0, 0, + "off", "off", 0, "", "", "full_refresh_cb", "", "", ""); } sub iset_config_reload_cb @@ -1345,7 +1567,8 @@ $wee_version_number = weechat::info_get("version_number", "") || 0; iset_config_init(); iset_config_read(); -weechat::hook_command($PRGNAME, "Interactive set", "f || s
|| [=][=]", +weechat::hook_command($PRGNAME, "Interactive set", "d || f || s
|| [=][=]", + "d : show only changed options\n". "f file : show options for a file\n". "s section: show options for a section\n". "text : show options with 'text' in name\n". @@ -1366,6 +1589,7 @@ weechat::hook_command($PRGNAME, "Interactive set", "f || s
|| [ "text,enter : set a new filter using command line (use '*' to see all options)\n". "alt+'v' : toggle help bar on/off\n". "alt+'p' : toggle option \"show_plugin_description\" on/off\n". + "q : as input in iset buffer to close it\n". "\n". "Mouse actions:\n". "wheel up/down : move cursor up/down\n". @@ -1374,8 +1598,8 @@ weechat::hook_command($PRGNAME, "Interactive set", "f || s
|| [ "right button + drag left/right: increase/decrease value (for integer or color)\n". "\n". "Examples:\n". - " show options for file 'weechat'\n". - " /iset f weechat\n". + " show changed options in 'aspell' plugin\n". + " /iset d aspell\n". " show options for file 'irc'\n". " /iset f irc\n". " show options for section 'look'\n".