From: Vincent Pit Date: Fri, 20 Nov 2015 14:19:28 +0000 (-0200) Subject: Factor the GUI commands into a new utility function X-Git-Url: http://git.vpit.fr/?p=perl%2Fscripts%2Fxchat.git;a=commitdiff_plain;h=532ed2d6f4e5597f1dd76e71f2bd9880c5d779bb Factor the GUI commands into a new utility function --- diff --git a/Xchat/XPI/Utils.pm b/Xchat/XPI/Utils.pm index 8fab3c4..cbd9494 100644 --- a/Xchat/XPI/Utils.pm +++ b/Xchat/XPI/Utils.pm @@ -23,6 +23,17 @@ sub dye_nick { return sprintf "\003%d%s", $rcolors[$col % @rcolors], $nick; } +my %gui_commands = ( + 'clear' => [ 'COLOR 0' ], + 'highlight' => [ 'FLASH' => 'COLOR 3' ], +); + +sub gui { + my $commands = $gui_commands{$_[0] || 'nope'}; + die 'Invalid command' unless defined $commands; + command "GUI $_" for @$commands; +} + sub save_context { my $cur_cxt = get_context; bless \$cur_cxt, 'Xchat::XPI::Utils::ContextGuard'; @@ -73,6 +84,7 @@ use base qw; our @EXPORT = (); our %EXPORT_TAGS = ('funcs' => [ qw< dye_nick + gui save_context local_context called_from_script > ]); diff --git a/hl.pl b/hl.pl index 7e76ba2..0a9fa11 100755 --- a/hl.pl +++ b/hl.pl @@ -8,21 +8,16 @@ use Xchat qw<:all>; use lib get_info 'xchatdir'; use Xchat::XPI; use Xchat::XPI::Events qw; +use Xchat::XPI::Utils qw; our $VERSION = '0.04'; my $ph; -sub guihl { - command 'GUI FLASH'; - command 'GUI COLOR 3'; -} - -sub guiclear { - command 'GUI COLOR 0'; -} - -hook_print 'Private Message to Dialog', sub { guihl; return EAT_NONE }; +hook_print 'Private Message to Dialog', sub { + gui 'highlight'; + return EAT_NONE; +}; my %hl = ( '#cpantesters' => [ qw< @@ -59,7 +54,7 @@ for (keys %hl) { filter 'Channel Action' => sub { my $chan = lc get_info 'channel'; if ($hl{$chan} and $_[1] =~ /$hl{$chan}/) { - guihl; + gui 'highlight'; 1; } else { 0; @@ -80,7 +75,7 @@ for (keys %skip) { filter 'Channel Action Hilight' => sub { my $chan = lc get_info 'channel'; if ($skip{$chan} and $_[1] =~ /$skip{$chan}/) { - guiclear; + gui 'clear'; 1; } else { 0; diff --git a/tools.pl b/tools.pl index f7e5c4e..f7b1606 100755 --- a/tools.pl +++ b/tools.pl @@ -10,7 +10,7 @@ use Xchat qw<:all>; use lib get_info 'xchatdir'; use Xchat::XPI; -use Xchat::XPI::Utils qw; +use Xchat::XPI::Utils qw; use constant MAX_MATCHES => 10; @@ -27,7 +27,7 @@ hook_command 'TC', sub { my $guard = save_context; for (get_list 'channels') { set_context $_->{context}; - command 'GUI COLOR 0'; + gui 'clear'; } return EAT_ALL; }, {