]> git.rmz.io Git - dotfiles.git/blobdiff - weechat/perl/iset.pl
xdg: add user-dirs.dirs
[dotfiles.git] / weechat / perl / iset.pl
index 7d7284735764ad8965ba29721960788a9c5ec372..f179022b3645ac63e7f8c6158e23a169dd0b2817 100644 (file)
@@ -1,6 +1,6 @@
 #
-# Copyright (C) 2008-2013 Sebastien Helleu <flashcode@flashtux.org>
-# Copyright (C) 2010-2012 Nils Görs <weechatter@arcor.de>
+# Copyright (C) 2008-2014 Sebastien Helleu <flashcode@flashtux.org>
+# Copyright (C) 2010-2014 Nils Görs <weechatter@arcor.de>
 #
 # 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
 #
 # History:
 #
+# 2014-09-30, arza <arza@arza.us>:
+#     version 3.6: fix current line counter when options aren't found
+# 2014-06-03, nils_2 <weechatter@arcor.de>:
+#     version 3.5: add new option "use_mute"
+# 2014-01-30, stfn <stfnmd@gmail.com>:
+#     version 3.4: add new options "color_value_diff" and "color_value_diff_selected"
+# 2014-01-16, luz <ne.tetewi@gmail.com>:
+#     version 3.3: fix bug with column alignment in iset buffer when option
+#                  name contains unicode characters
 # 2013-08-03, Sebastien Helleu <flashcode@flashtux.org>:
 #     version 3.2: allow "q" as input in iset buffer to close it
 # 2013-07-14, Sebastien Helleu <flashcode@flashtux.org>:
 use strict;
 
 my $PRGNAME = "iset";
-my $VERSION = "3.2";
+my $VERSION = "3.6";
 my $DESCR   = "Interactive Set for configuration options";
 my $AUTHOR  = "Sebastien Helleu <flashcode\@flashtux.org>";
 my $LICENSE = "GPL3";
@@ -122,6 +131,7 @@ my @iset_focus = ();
 my @options_names = ();
 my @options_types = ();
 my @options_values = ();
+my @options_default_values = ();
 my @options_is_null = ();
 my $option_max_length = 0;
 my $current_line = 0;
@@ -147,7 +157,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)
         {
@@ -325,6 +345,7 @@ sub iset_get_options
     @options_names = ();
     @options_types = ();
     @options_values = ();
+    @options_default_values = ();
     @options_is_null = ();
     $option_max_length = 0;
     my %options_internal = ();
@@ -343,6 +364,7 @@ sub iset_get_options
         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 $is_null = weechat::infolist_integer($infolist, "value_is_null");
         if ($search_mode == 3)
         {
@@ -351,6 +373,7 @@ sub iset_get_options
             {
                 $options_internal{$name}{"type"} = $type;
                 $options_internal{$name}{"value"} = $value;
+                $options_internal{$name}{"default_value"} = $default_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};
@@ -361,6 +384,7 @@ sub iset_get_options
         {
             $options_internal{$name}{"type"} = $type;
             $options_internal{$name}{"value"} = $value;
+            $options_internal{$name}{"default_value"} = $default_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};
@@ -375,6 +399,7 @@ sub iset_get_options
         push(@options_names, $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_is_null, $options_internal{$name}{"is_null"});
     }
 }
@@ -399,6 +424,7 @@ sub iset_search_values
     @options_names = ();
     @options_types = ();
     @options_values = ();
+    @options_default_values = ();
     @options_is_null = ();
     $option_max_length = 0;
     my %options_internal = ();
@@ -411,12 +437,14 @@ sub iset_search_values
         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");
         if ($search_mode)
         {
             if ( grep /\Q$var_value/,lc($value) )
             {
                 $options_internal{$name}{"type"} = $type;
                 $options_internal{$name}{"value"} = $value;
+                $options_internal{$name}{"default_value"} = $default_value;
                 $options_internal{$name}{"is_null"} = $is_null;
                 $option_max_length = length($name) if (length($name) > $option_max_length);
             }
@@ -428,6 +456,7 @@ sub iset_search_values
             {
                 $options_internal{$name}{"type"} = $type;
                 $options_internal{$name}{"value"} = $value;
+                $options_internal{$name}{"default_value"} = $default_value;
                 $options_internal{$name}{"is_null"} = $is_null;
                 $option_max_length = length($name) if (length($name) > $option_max_length);
             }
@@ -440,6 +469,7 @@ sub iset_search_values
         push(@options_names, $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_is_null, $options_internal{$name}{"is_null"});
     }
 }
@@ -452,7 +482,16 @@ sub iset_refresh_line
         if ($y <= $#options_names)
         {
             return if (! defined($options_types[$y]));
-            my $format = sprintf("%%s%%-%ds %%s %%-7s %%s %%s%%s%%s", $option_max_length);
+            my $format = sprintf("%%s%%s%%s %%s %%-7s %%s %%s%%s%%s");
+            my $padding;
+            if ($wee_version_number >= 0x00040200)
+            {
+                $padding = " " x ($option_max_length - weechat::strlen_screen($options_names[$y]));
+            }
+            else
+            {
+                $padding = " " x ($option_max_length - length($options_names[$y]));
+            }
             my $around = "";
             $around = "\"" if ((!$options_is_null[$y]) && ($options_types[$y] eq "string"));
 
@@ -463,6 +502,10 @@ sub iset_refresh_line
             {
                 $color3 = weechat::color(weechat::config_color($options_iset{"color_value_undef"}));
             }
+            elsif ($options_values[$y] ne $options_default_values[$y])
+            {
+                $color3 = weechat::color(weechat::config_color($options_iset{"color_value_diff"}));
+            }
             else
             {
                 $color3 = weechat::color(weechat::config_color($options_iset{"color_value"}));
@@ -475,6 +518,10 @@ sub iset_refresh_line
                 {
                     $color3 = weechat::color(weechat::config_color($options_iset{"color_value_undef_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
                 {
                     $color3 = weechat::color(weechat::config_color($options_iset{"color_value_selected"}).",".weechat::config_color($options_iset{"color_bg_selected"}));
@@ -483,7 +530,7 @@ sub iset_refresh_line
             my $value = $options_values[$y];
             $value = "(undef)" if ($options_is_null[$y]);
             my $strline = sprintf($format,
-                                  $color1, $options_names[$y],
+                                  $color1, $options_names[$y], $padding,
                                   $color2, $options_types[$y],
                                   $color3, $around, $value, $around);
             weechat::print_y($iset_buffer, $y, $strline);
@@ -675,6 +722,7 @@ sub iset_config_cb
                 {
                     $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");
@@ -934,10 +982,14 @@ sub iset_cmd_cb
             {
                 $quote = "\"" if ($options_types[$current_line] eq "string");
             }
-            weechat::buffer_set($iset_buffer, "input", "/set ".$options_names[$current_line]." ".$quote.$value.$quote);
+            my $set_command = "/set";
+            $set_command = "/mute " . $set_command if (weechat::config_boolean($options_iset{"use_mute"}) == 1);
+
+            weechat::buffer_set($iset_buffer, "input", $set_command." ".$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_word") if (weechat::config_boolean($options_iset{"use_mute"}) == 1);
             weechat::command($iset_buffer, "/input move_next_char");
             weechat::command($iset_buffer, "/input move_next_char") if ($quote ne "");
         }
@@ -1221,6 +1273,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,
@@ -1285,6 +1345,10 @@ 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, "", "", "", "", "", "");
 }
 
 sub iset_config_reload_cb