From 823e0002921c8e80f6373f271482fc3acc13bdc2 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 15 Jan 2011 04:06:20 +0000 Subject: bindings: added an example of parsing bindings a'la adv_windowlist. needs some attributions and cleanup though --- feature-tests/bindings.pl | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 feature-tests/bindings.pl (limited to 'feature-tests/bindings.pl') diff --git a/feature-tests/bindings.pl b/feature-tests/bindings.pl new file mode 100644 index 0000000..006eaf1 --- /dev/null +++ b/feature-tests/bindings.pl @@ -0,0 +1,77 @@ +use strict; +use warnings; + + +use Irssi; +use Irssi::Irc; +use Irssi::TextUI; + +use Data::Dumper; + + +our $VERSION = '0.1'; +our %IRSSI = ( + authors => 'shabble', + contact => 'shabble+irssi@metavore.org', + name => '', + description => '', + licence => q(GNU GPLv2 or later), + + ); + +# code taken from adv_windowlist + +my $keymap; + +init(); + +sub init { + update_keymap(); + Irssi::command_bind('showbinds', 'cmd_showbinds'); +} + +sub cmd_showbinds { + my ($args, @rest) = @_; + + my $win = Irssi::active_win(); + $win->print("Change window bindings:", Irssi::MSGLEVEL_CLIENTCRAP); + for my $w (sort keys %$keymap) { + my $x = $keymap->{$w}; + $win->print("$w ==> $x", Irssi::MSGLEVEL_CLIENTCRAP); + } + $win->print("Done showing window bindings:", Irssi::MSGLEVEL_CLIENTCRAP); + +} +sub get_keymap { + my ($text_dest, $str, $str_stripped) = @_; + + if ($text_dest->{level} == Irssi::MSGLEVEL_CLIENTCRAP and $text_dest->{target} eq '') { + if (not defined($text_dest->{'server'})) { + if ($str_stripped =~ m/((?:meta-)+)(.)\s+change_window (\d+)/) { + my ($level, $key, $window) = ($1, $2, $3); + #my $numlevel = ($level =~ y/-//) - 1; + my $kk = $level . $key; + $keymap->{$kk} = $window; + } + Irssi::signal_stop(); + } + } +} + +sub update_keymap { + $keymap = {}; + Irssi::signal_remove('command bind' => 'watch_keymap'); + Irssi::signal_add_first('print text' => 'get_keymap'); + Irssi::command('bind'); # stolen from grep + Irssi::signal_remove('print text' => 'get_keymap'); + Irssi::signal_add('command bind' => 'watch_keymap'); + #Irssi::timeout_add_once(100, 'eventChanged', undef); +} + +# watch keymap changes +sub watch_keymap { + Irssi::timeout_add_once(1000, 'update_keymap', undef); +} + + + -- cgit v1.2.3 From 64c4b2fd935c348070e95761724e209b9c88f078 Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Tue, 18 Jan 2011 00:17:56 +0000 Subject: joinforward/joinforward: a first pass at a script which observes redirection messages and automatically overrides /join to point you to the right forwarded channel. --- feature-tests/bindings.pl | 75 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 19 deletions(-) (limited to 'feature-tests/bindings.pl') diff --git a/feature-tests/bindings.pl b/feature-tests/bindings.pl index 006eaf1..ece220d 100644 --- a/feature-tests/bindings.pl +++ b/feature-tests/bindings.pl @@ -23,11 +23,39 @@ our %IRSSI = ( my $keymap; +sub STATE_HEADER () { 0 } +sub STATE_BODY () { 1 } +sub STATE_END () { 2 } +my $parse_state = STATE_HEADER; + +my $binding_formats = {}; + init(); sub init { - update_keymap(); + + $keymap = {}; + Irssi::command_bind('showbinds', 'cmd_showbinds'); + Irssi::signal_add('command bind' => 'watch_keymap'); + + $binding_formats = get_binding_formats(); + + capture_bind_data(); +} + +sub get_binding_formats { + my $theme = Irssi::current_theme(); + my @keys = qw/bind_header bind_list bind_command_list + bind_footer bind_unknown_id/; + + my $ret = {}; + foreach my $key (@keys) { + my $tmp = $theme->get_format('fe-common/core', $key); + #$tmp =~ s/%/%%/g; # escape colour codes? + $ret->{$key} = $tmp; + } + return $ret; } sub cmd_showbinds { @@ -42,35 +70,44 @@ sub cmd_showbinds { $win->print("Done showing window bindings:", Irssi::MSGLEVEL_CLIENTCRAP); } -sub get_keymap { + +sub sig_print_text { my ($text_dest, $str, $str_stripped) = @_; - if ($text_dest->{level} == Irssi::MSGLEVEL_CLIENTCRAP and $text_dest->{target} eq '') { - if (not defined($text_dest->{'server'})) { - if ($str_stripped =~ m/((?:meta-)+)(.)\s+change_window (\d+)/) { - my ($level, $key, $window) = ($1, $2, $3); - #my $numlevel = ($level =~ y/-//) - 1; - my $kk = $level . $key; - $keymap->{$kk} = $window; - } - Irssi::signal_stop(); - } + return unless $text_dest->{level} == Irssi::MSGLEVEL_CLIENTCRAP; + return unless $text_dest->{target} eq ''; + return unless not defined $text_dest->{server}; + + # if ($parse_state = STATE_HEADER) { + # if ($str =~ m/\Q$binding_formats->{bind_header}\E/) { + # $parse_state = STATE_BODY; + # } + # } elsif ($parse_state = STATE_BODY) { + print "Data is: $str_stripped"; + if ($str_stripped =~ m/^.*?(\S{,20})\s+(\S+)\s+(\S+)/) { + $keymap->{$1} = "$2, $3"; + print "Parsed $1 as $2, $3"; } + Irssi::signal_stop(); + # } elsif ($str =~ m/$binding_formats->{bind_footer}\E/) { + # $parse_state = STATE_END; + # } + # } } -sub update_keymap { - $keymap = {}; + +sub capture_bind_data { Irssi::signal_remove('command bind' => 'watch_keymap'); - Irssi::signal_add_first('print text' => 'get_keymap'); + Irssi::signal_add_first('print text' => 'sig_print_text'); Irssi::command('bind'); # stolen from grep - Irssi::signal_remove('print text' => 'get_keymap'); - Irssi::signal_add('command bind' => 'watch_keymap'); - #Irssi::timeout_add_once(100, 'eventChanged', undef); + Irssi::signal_remove('print text' => 'sig_print_text'); + } + # watch keymap changes sub watch_keymap { - Irssi::timeout_add_once(1000, 'update_keymap', undef); + Irssi::timeout_add_once(1000, 'capture_bind_data', undef); } -- cgit v1.2.3