aboutsummaryrefslogtreecommitdiffstats
path: root/weechat/perl/iset.pl
diff options
context:
space:
mode:
Diffstat (limited to 'weechat/perl/iset.pl')
-rw-r--r--weechat/perl/iset.pl198
1 files changed, 168 insertions, 30 deletions
diff --git a/weechat/perl/iset.pl b/weechat/perl/iset.pl
index af74767..163dfb5 100644
--- a/weechat/perl/iset.pl
+++ b/weechat/perl/iset.pl
@@ -19,6 +19,13 @@
#
# History:
#
+# 2016-07-08, nils_2 <weechatter@arcor.de>
+# version 4.2: add diff function
+# 2016-02-06, Sebastien Helleu <flashcode@flashtux.org>:
+# version 4.1: remove debug print
+# 2015-12-24, Sebastien Helleu <flashcode@flashtux.org>:
+# version 4.0: add support of parent options (inherited values in irc servers)
+# with WeeChat >= 1.4
# 2015-05-16, Sebastien Helleu <flashcode@flashtux.org>:
# version 3.9: fix cursor position when editing an option with WeeChat >= 1.2
# 2015-05-02, arza <arza@arza.us>:
@@ -123,7 +130,7 @@
use strict;
my $PRGNAME = "iset";
-my $VERSION = "3.9";
+my $VERSION = "4.2";
my $DESCR = "Interactive Set for configuration options";
my $AUTHOR = "Sebastien Helleu <flashcode\@flashtux.org>";
my $LICENSE = "GPL3";
@@ -135,9 +142,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;
@@ -145,7 +154,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";
@@ -195,6 +204,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) ";
@@ -267,10 +282,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"}) )
@@ -284,7 +316,8 @@ sub iset_buffer_input
{
iset_create_filter($string);
iset_get_options($search_value);
- }else
+ }
+ else
{
iset_create_filter($string);
iset_get_options("");
@@ -353,9 +386,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 = ();
@@ -371,34 +406,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++;
}
@@ -407,9 +469,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"});
}
}
@@ -432,9 +496,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 = ();
@@ -443,18 +509,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);
}
@@ -464,9 +538,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);
}
@@ -477,9 +553,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"});
}
}
@@ -508,9 +586,11 @@ 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])
{
@@ -527,6 +607,7 @@ 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])
{
@@ -538,7 +619,23 @@ sub iset_refresh_line
}
}
my $value = $options_values[$y];
- $value = "(undef)" if ($options_is_null[$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],
@@ -712,6 +809,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]);
@@ -724,25 +854,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))
- {
- $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");
- iset_refresh_line($index);
- iset_title() if ($option_name eq "iset.look.show_current_line");
- }
- else
+ if ($options_parent_names[$i] eq $option_name)
{
- iset_full_refresh(1); # if not found, refresh fully without clearing buffer
- weechat::print_y($iset_buffer, $#options_names + 1, "");
+ iset_refresh_option($options_names[$i], $i);
}
- weechat::infolist_free($infolist);
}
}
else
@@ -817,20 +936,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();
@@ -1421,7 +1557,8 @@ $wee_version_number = weechat::info_get("version_number", "") || 0;
iset_config_init();
iset_config_read();
-weechat::hook_command($PRGNAME, "Interactive set", "f <file> || s <section> || [=][=]<text>",
+weechat::hook_command($PRGNAME, "Interactive set", "d <text> || f <file> || s <section> || [=][=]<text>",
+ "d <text> : 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".
@@ -1442,6 +1579,7 @@ weechat::hook_command($PRGNAME, "Interactive set", "f <file> || s <section> || [
"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".
@@ -1450,8 +1588,8 @@ weechat::hook_command($PRGNAME, "Interactive set", "f <file> || s <section> || [
"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".