From 91f126ae4c9ea90336bdeb24001fadca79439edc Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Sat, 24 Jul 2010 18:23:13 +0100 Subject: moved most tests to feature-tests/ --- feature-tests/complete_test.pl | 27 +++++++ feature-tests/expando_test.pl | 58 +++++++++++++++ feature-tests/frog_reload.pl | 99 ++++++++++++++++++++++++++ feature-tests/help_a.pl | 15 ++++ feature-tests/help_b.pl | 15 ++++ feature-tests/key_test.pl | 100 ++++++++++++++++++++++++++ feature-tests/subtest.pl | 76 ++++++++++++++++++++ history-search/complete_test.pl | 27 ------- history-search/expando_test.pl | 58 --------------- history-search/frog_reload.pl | 99 -------------------------- history-search/help_a.pl | 15 ---- history-search/help_b.pl | 15 ---- history-search/history_search.pl | 150 --------------------------------------- history-search/key_test.pl | 100 -------------------------- history-search/subtest.pl | 76 -------------------- 15 files changed, 390 insertions(+), 540 deletions(-) create mode 100644 feature-tests/complete_test.pl create mode 100644 feature-tests/expando_test.pl create mode 100644 feature-tests/frog_reload.pl create mode 100644 feature-tests/help_a.pl create mode 100644 feature-tests/help_b.pl create mode 100644 feature-tests/key_test.pl create mode 100644 feature-tests/subtest.pl delete mode 100644 history-search/complete_test.pl delete mode 100644 history-search/expando_test.pl delete mode 100644 history-search/frog_reload.pl delete mode 100644 history-search/help_a.pl delete mode 100644 history-search/help_b.pl delete mode 100644 history-search/history_search.pl delete mode 100644 history-search/key_test.pl delete mode 100644 history-search/subtest.pl diff --git a/feature-tests/complete_test.pl b/feature-tests/complete_test.pl new file mode 100644 index 0000000..a8ae485 --- /dev/null +++ b/feature-tests/complete_test.pl @@ -0,0 +1,27 @@ +use strict; +use vars qw($VERSION %IRSSI); + +use Irssi; +$VERSION = '2.1'; +%IRSSI = ( + authors => 'Daenyth', + contact => 'Daenyth /at/ gmail /dot/ com', + name => 'Complete Last-Spoke', + description => 'When using tab completion on an empty input buffer, complete to the nick of the person who spoke most recently.', + license => 'GPL2', +); + +sub do_complete { + my ($strings, $window, $word, $linestart, $want_space) = @_; + return unless ($linestart eq '' && $word eq ''); + +# my $suffix = Irssi::settings_get_str('completion_char'); +# @$strings = $last_speaker . $suffix; + push @$strings, qw|/foo /bar /baz /bacon|; + +# $$want_space = 1; +# Irssi::signal_stop(); +} + + Irssi::signal_add_first( 'complete word', \&do_complete); + diff --git a/feature-tests/expando_test.pl b/feature-tests/expando_test.pl new file mode 100644 index 0000000..0d5456a --- /dev/null +++ b/feature-tests/expando_test.pl @@ -0,0 +1,58 @@ +use strict; +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw + +use vars qw($VERSION %IRSSI); +$VERSION = "1.0.1"; +%IRSSI = ( + authors => "shabble", + contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', + name => "", + description => "", + license => "Public Domain", + changed => "" +); + +my $prompt_additional_content = ''; + +Irssi::expando_create('prompt_additional', \&expando_prompt, {}); + +#TODO: necessary? +#Irssi::signal_add_last 'gui print text finished' => \&redraw_prompts; + +sub expando_prompt { + my ($server, $witem, $arg) = @_; + return $prompt_additional_content; +} + +sub redraw_prompts { + Irssi::statusbar_items_redraw ('prompt'); + Irssi::statusbar_items_redraw ('prompt_empty'); +} + +sub handle_change_prompt_sig { + my ($text) = @_; + + print "Got prompt change sig with: $text"; + + my $expanded_text = Irssi::parse_special($text); + my $changed = ($expanded_text ne $prompt_additional_content); + + $prompt_additional_content = $expanded_text; + + if ($changed) { + print "Redrawing prompts"; + redraw_prompts(); + } +} + +sub prompt_additional_cmd { + my ($str) = @_; + print "Setting prompt to: $str"; + Irssi::signal_emit('change prompt', $str); +} + +Irssi::signal_register({'change prompt' => [qw/string/]}); +Irssi::signal_add('change prompt' => \&handle_change_prompt_sig); + +Irssi::command_bind('set_prompt' => \&prompt_additional_cmd); diff --git a/feature-tests/frog_reload.pl b/feature-tests/frog_reload.pl new file mode 100644 index 0000000..678c87d --- /dev/null +++ b/feature-tests/frog_reload.pl @@ -0,0 +1,99 @@ +use strict; +use warnings; + +use Irssi; +use File::ChangeNotify(); +use File::Spec (); +use File::Basename qw(basename); + +#my $THIS_SCRIPT = basename __FILE__; + +my $irssi_dir = Irssi::get_irssi_dir(); +my @watch_dirs = ($irssi_dir, $irssi_dir . '/scripts', + $irssi_dir . '/scripts/autorun'); + +my $watcher = File::ChangeNotify->instantiate_watcher + ( + directories => \@watch_dirs, + filter => qr/\.(?:pl|py)$/, + ); + +my @watchers = File::ChangeNotify->usable_classes(); +print "Started reloader watching: ", join(", ", @watch_dirs), " using $watchers[0]"; + +my %action_for = ( + create => sub { + my ($path) = @_; + Irssi::print ("CREATE: Loading $path"); + load_script($path); + }, + + modify => sub { + my ($path) = @_; + Irssi::print ("MODIFY: reloading $path"); + reload($path); + }, + + delete => sub { + my ($path) = @_; + Irssi::print ("DELETE: Unloading $path"); + unload_script($path); + }, +); + +#TODO: change me back. +Irssi::timeout_add(3000, \&timer_sub, undef); + +sub timer_sub { + print "Timer sub called"; + my @new_events = $watcher->new_events; + for my $event (@new_events) { + + print "Handling event: ", $event->type, " path: ", $event->path; + + if (my $callback = $action_for{$event->type}) { + $callback->($event->path); + } + } +} + +sub reload { + my ($path) = @_; + + unload_script($path); + load_script($path); +} + +sub unload_script { + my ($script_path) = @_; + my $name = filepath_to_script($script_path); + + if (script_is_loaded($name)) { + Irssi::print ("unloading $name..."); + Irssi::command("script unload $name"); + } +} + +sub load_script { + my ($script_path) = @_; + Irssi::command("script load \"$script_path\""); +} + +sub filepath_to_script { + my ($path) = @_; + + my $name = basename $path; + $name =~ s/\.pl$//i; + + return $name; +} + +sub script_is_loaded { + my $name = shift; + print "Checking if $name is loaded"; + no strict 'refs'; + my $retval = defined %{ "Irssi::Script::${name}::" }; + use strict 'refs'; + + return $retval; +} diff --git a/feature-tests/help_a.pl b/feature-tests/help_a.pl new file mode 100644 index 0000000..53d902c --- /dev/null +++ b/feature-tests/help_a.pl @@ -0,0 +1,15 @@ +use strict; +use warnings; + +use Irssi; + +our $help = "this is help for a"; + +Irssi::command_bind('help', sub { + if ($_[0] eq 'test_a') { + Irssi::print($help, MSGLEVEL_CLIENTCRAP); + Irssi::signal_stop(); + return; + } + } +); diff --git a/feature-tests/help_b.pl b/feature-tests/help_b.pl new file mode 100644 index 0000000..8b57a45 --- /dev/null +++ b/feature-tests/help_b.pl @@ -0,0 +1,15 @@ +use strict; +use warnings; + +use Irssi; + +our $help = "this is help for b"; + +Irssi::command_bind('help', sub { + if ($_[0] eq 'test_b') { + Irssi::print($help, MSGLEVEL_CLIENTCRAP); + Irssi::signal_stop(); + return; + } + } +); diff --git a/feature-tests/key_test.pl b/feature-tests/key_test.pl new file mode 100644 index 0000000..b16ff00 --- /dev/null +++ b/feature-tests/key_test.pl @@ -0,0 +1,100 @@ +use strict; +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw + +use vars qw($VERSION %IRSSI); +$VERSION = "1.0.1"; +%IRSSI = ( + authors => "shabble", + contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', + name => "", + description => "", + license => "Public Domain", + changed => "" +); + + +Irssi::signal_add_last 'gui key pressed' => \&got_key; + +my $buf = ''; + +sub got_key { + my ($key) = @_; + $buf .= " $key"; + my $res = decode_keypress($key); + if (defined $res) { + print "codes: $buf"; + print "Keypress: $res"; + $buf = ''; + } +} + +# 1 means we've seen an esc, 2 means we've +# seen an esc,[. 0 is normal. + +my $decoder_state = 0; + +sub decode_keypress { + my ($code) = @_; + + if ($decoder_state == 1) { + + # seen esc/meta. + if ($code == ord('[')) { + $decoder_state = 2; + return undef; + } else { + $decoder_state = 0; + return 'meta-' . chr($code); + } + + } elsif ($decoder_state == 2) { + + if ($code == ord('A')) { + $decoder_state = 0; + return 'up-arrow'; + } elsif ($code == ord('B')) { + $decoder_state = 0; + return 'dn-arrow' + } elsif ($code == ord('C')) { + $decoder_state = 0; + return 'right-arrow' + } elsif ($code == ord('D')) { + $decoder_state = 0; + return 'left-arrow' + } + + $decoder_state = 0; + return undef; + + } else { + + if ($code < 27) { + + if ($code == 9) { + return 'tab'; + } + + return 'ctrl-' . chr($code + ord('a') -1); + } + + if ($code > 32 && $code < 127) { + return chr($code); + } + + if ($code == 32) { + return 'space'; + } + + if ($code == 127) { + return 'backspace'; + } + + if ($code == 27) { + $decoder_state = 1; + return undef; + } + + return 'unknown ' . $code; + } +} diff --git a/feature-tests/subtest.pl b/feature-tests/subtest.pl new file mode 100644 index 0000000..fd5a9cc --- /dev/null +++ b/feature-tests/subtest.pl @@ -0,0 +1,76 @@ +use strict; +use Irssi; +use Irssi::TextUI; +use Data::Dumper; + +use vars qw($VERSION %IRSSI); +$VERSION = '1.0'; +%IRSSI = ( + authors => 'Wouter Coekaerts', + contact => 'coekie@irssi.org', + name => 'history_search', + description => 'Search within your typed history as you type (like ctrl-R in bash)', + license => 'GPLv2 or later', + url => 'http://wouter.coekaerts.be/irssi/', + changed => '04/08/07' +); + + +Irssi::command_bind("foo bar", \&subcmd_bar); +Irssi::command_bind("foo", \&subcmd_handler); + +sub subcmd_handler { + my ($data, $server, $item) = @_; + $data =~ s/\s+$//g; + Irssi::command_runsub('foo', $data, $server, $item); +} + +sub subcmd_bar { + my ($args) = @_; + print "subcommand called with: $args"; +} + +# my $prev_typed; +# my $prev_startpos; +# my $enabled = 0; + +# Irssi::command_bind('history_search', sub { +# $enabled = ! $enabled; +# if ($enabled) { +# $prev_typed = ''; +# $prev_startpos = 0; +# } +# }); + +# Irssi::signal_add_last 'gui key pressed' => sub { +# my ($key) = @_; + +# if ($key == 10) { # enter +# $enabled = 0; +# } + +# return unless $enabled; + +# my $prompt = Irssi::parse_special('$L'); +# my $pos = Irssi::gui_input_get_pos(); + +# if ($pos < $prev_startpos) { +# $enabled = 0; +# return; +# } + +# my $typed = substr($prompt, $prev_startpos, ($pos-$prev_startpos)); + +# my $history = ($typed eq '') ? '' : Irssi::parse_special('$!' . $typed . '!'); +# if ($history eq '') { +# $history = $typed; +# } + +# my $startpos = index(lc($history), lc($typed)); + +# Irssi::gui_input_set($history); +# Irssi::gui_input_set_pos($startpos + length($typed)); + +# $prev_typed = $typed; +# $prev_startpos = $startpos; +# }; diff --git a/history-search/complete_test.pl b/history-search/complete_test.pl deleted file mode 100644 index a8ae485..0000000 --- a/history-search/complete_test.pl +++ /dev/null @@ -1,27 +0,0 @@ -use strict; -use vars qw($VERSION %IRSSI); - -use Irssi; -$VERSION = '2.1'; -%IRSSI = ( - authors => 'Daenyth', - contact => 'Daenyth /at/ gmail /dot/ com', - name => 'Complete Last-Spoke', - description => 'When using tab completion on an empty input buffer, complete to the nick of the person who spoke most recently.', - license => 'GPL2', -); - -sub do_complete { - my ($strings, $window, $word, $linestart, $want_space) = @_; - return unless ($linestart eq '' && $word eq ''); - -# my $suffix = Irssi::settings_get_str('completion_char'); -# @$strings = $last_speaker . $suffix; - push @$strings, qw|/foo /bar /baz /bacon|; - -# $$want_space = 1; -# Irssi::signal_stop(); -} - - Irssi::signal_add_first( 'complete word', \&do_complete); - diff --git a/history-search/expando_test.pl b/history-search/expando_test.pl deleted file mode 100644 index 0d5456a..0000000 --- a/history-search/expando_test.pl +++ /dev/null @@ -1,58 +0,0 @@ -use strict; -use Irssi; -use Irssi::TextUI; # for sbar_items_redraw - -use vars qw($VERSION %IRSSI); -$VERSION = "1.0.1"; -%IRSSI = ( - authors => "shabble", - contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', - name => "", - description => "", - license => "Public Domain", - changed => "" -); - -my $prompt_additional_content = ''; - -Irssi::expando_create('prompt_additional', \&expando_prompt, {}); - -#TODO: necessary? -#Irssi::signal_add_last 'gui print text finished' => \&redraw_prompts; - -sub expando_prompt { - my ($server, $witem, $arg) = @_; - return $prompt_additional_content; -} - -sub redraw_prompts { - Irssi::statusbar_items_redraw ('prompt'); - Irssi::statusbar_items_redraw ('prompt_empty'); -} - -sub handle_change_prompt_sig { - my ($text) = @_; - - print "Got prompt change sig with: $text"; - - my $expanded_text = Irssi::parse_special($text); - my $changed = ($expanded_text ne $prompt_additional_content); - - $prompt_additional_content = $expanded_text; - - if ($changed) { - print "Redrawing prompts"; - redraw_prompts(); - } -} - -sub prompt_additional_cmd { - my ($str) = @_; - print "Setting prompt to: $str"; - Irssi::signal_emit('change prompt', $str); -} - -Irssi::signal_register({'change prompt' => [qw/string/]}); -Irssi::signal_add('change prompt' => \&handle_change_prompt_sig); - -Irssi::command_bind('set_prompt' => \&prompt_additional_cmd); diff --git a/history-search/frog_reload.pl b/history-search/frog_reload.pl deleted file mode 100644 index 678c87d..0000000 --- a/history-search/frog_reload.pl +++ /dev/null @@ -1,99 +0,0 @@ -use strict; -use warnings; - -use Irssi; -use File::ChangeNotify(); -use File::Spec (); -use File::Basename qw(basename); - -#my $THIS_SCRIPT = basename __FILE__; - -my $irssi_dir = Irssi::get_irssi_dir(); -my @watch_dirs = ($irssi_dir, $irssi_dir . '/scripts', - $irssi_dir . '/scripts/autorun'); - -my $watcher = File::ChangeNotify->instantiate_watcher - ( - directories => \@watch_dirs, - filter => qr/\.(?:pl|py)$/, - ); - -my @watchers = File::ChangeNotify->usable_classes(); -print "Started reloader watching: ", join(", ", @watch_dirs), " using $watchers[0]"; - -my %action_for = ( - create => sub { - my ($path) = @_; - Irssi::print ("CREATE: Loading $path"); - load_script($path); - }, - - modify => sub { - my ($path) = @_; - Irssi::print ("MODIFY: reloading $path"); - reload($path); - }, - - delete => sub { - my ($path) = @_; - Irssi::print ("DELETE: Unloading $path"); - unload_script($path); - }, -); - -#TODO: change me back. -Irssi::timeout_add(3000, \&timer_sub, undef); - -sub timer_sub { - print "Timer sub called"; - my @new_events = $watcher->new_events; - for my $event (@new_events) { - - print "Handling event: ", $event->type, " path: ", $event->path; - - if (my $callback = $action_for{$event->type}) { - $callback->($event->path); - } - } -} - -sub reload { - my ($path) = @_; - - unload_script($path); - load_script($path); -} - -sub unload_script { - my ($script_path) = @_; - my $name = filepath_to_script($script_path); - - if (script_is_loaded($name)) { - Irssi::print ("unloading $name..."); - Irssi::command("script unload $name"); - } -} - -sub load_script { - my ($script_path) = @_; - Irssi::command("script load \"$script_path\""); -} - -sub filepath_to_script { - my ($path) = @_; - - my $name = basename $path; - $name =~ s/\.pl$//i; - - return $name; -} - -sub script_is_loaded { - my $name = shift; - print "Checking if $name is loaded"; - no strict 'refs'; - my $retval = defined %{ "Irssi::Script::${name}::" }; - use strict 'refs'; - - return $retval; -} diff --git a/history-search/help_a.pl b/history-search/help_a.pl deleted file mode 100644 index 53d902c..0000000 --- a/history-search/help_a.pl +++ /dev/null @@ -1,15 +0,0 @@ -use strict; -use warnings; - -use Irssi; - -our $help = "this is help for a"; - -Irssi::command_bind('help', sub { - if ($_[0] eq 'test_a') { - Irssi::print($help, MSGLEVEL_CLIENTCRAP); - Irssi::signal_stop(); - return; - } - } -); diff --git a/history-search/help_b.pl b/history-search/help_b.pl deleted file mode 100644 index 8b57a45..0000000 --- a/history-search/help_b.pl +++ /dev/null @@ -1,15 +0,0 @@ -use strict; -use warnings; - -use Irssi; - -our $help = "this is help for b"; - -Irssi::command_bind('help', sub { - if ($_[0] eq 'test_b') { - Irssi::print($help, MSGLEVEL_CLIENTCRAP); - Irssi::signal_stop(); - return; - } - } -); diff --git a/history-search/history_search.pl b/history-search/history_search.pl deleted file mode 100644 index 0a2282e..0000000 --- a/history-search/history_search.pl +++ /dev/null @@ -1,150 +0,0 @@ -# Search within your typed history as you type (like ctrl-R in bash) -# Usage: -# * First do: /bind ^R /history_search -# * Then type ctrl-R and type what you're searching for - -# Copyright 2007 Wouter Coekaerts -# -# 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 -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -use strict; -use Irssi; -use Irssi::TextUI; -use Data::Dumper; - -use vars qw($VERSION %IRSSI); -$VERSION = '1.0'; -%IRSSI = ( - authors => 'Wouter Coekaerts', - contact => 'coekie@irssi.org', - name => 'history_search', - description => 'Search within your typed history as you type (like ctrl-R in bash)', - license => 'GPLv2 or later', - url => 'http://wouter.coekaerts.be/irssi/', - changed => '04/08/07' -); - -my $prompt_append = 1; -my $prompt_content = ''; - -# create a new statusbar item - -Irssi::statusbar_item_register ( 'custom_prompt', 0, 'custom_prompt' ); - -Irssi::signal_add_last 'gui print text finished' => sub { - Irssi::statusbar_items_redraw ( 'custom_prompt' ); -}; - -Irssi::signal_register({'change prompt' => [qw/string int/]}); -Irssi::signal_add('change prompt' => \&handle_change_prompt_sig); - -sub handle_change_prompt_sig { - my ($text, $append) = @_; - print "sig args: ", Dumper(\@_); - $prompt_content = $text; - $prompt_append = $append; - print "text: $prompt_content, append: $prompt_append"; - - Irssi::statusbar_items_redraw('custom_prompt'); -} - -# TODO: make these work wiht subcommand (runsub) - -Irssi::command_bind('set_prompt' => \&dothing ); -Irssi::command_set_options('set_prompt', '+string @append'); - -Irssi::command_bind('install_prompt' => \&install_prompt); -Irssi::command_bind('uninstall_prompt' => \&uninstall_prompt); - -Irssi::settings_add_bool('custom_prompt', 'autoinstall_custom_prompt', 0); - -if (Irssi::settings_get_bool('autoinstall_custom_prompt')) { - install_prompt(); -} - -sub install_prompt { - Irssi::command("/statusbar prompt add -priority '-5' -alignment left" - . " -before prompt custom_prompt"); - Irssi::command("/statusbar prompt remove prompt"); - Irssi::command("/statusbar prompt remove prompt_empty"); -} - -sub uninstall_prompt { - Irssi::command("/statusbar prompt remove custom_prompt"); - Irssi::command("/statusbar prompt add -priority '-1' " - . "-before input -alignment left prompt"); - Irssi::command("/statusbar prompt add -priority '-2' " - . "-before input -alignment left prompt_empty"); -} - -sub dothing { - #my ($str, $append) = @_; - #Irssi::print("str is $str, append=$append"); - my $parsed = [Irssi::command_parse_options('set_prompt', $_[0])]; - my $args = $parsed->[0] // {}; - my $remainder = $parsed->[1] // ''; - - my ($str, $append) = ('', 1); - print Dumper $args; - if (exists ($args->{string})) { - $str = $args->{string}; - } - - if (exists($args->{append})) { - $append = $args->{append}; - } - print "append in dothing: $append"; - Irssi::signal_emit('change prompt', $str, $append); -} - -sub custom_prompt { - my ($sb_item, $get_size_only) = @_; - - my ($width, $padChar, $padNum, $length); - - #my $prompt_str = '%K[%W$tag%c/%K$cumode%n$*%K]%n '; - - my $theme = Irssi::current_theme; - my $prompt = ''; - - my $var = ''; - if (window_is_empty(Irssi::active_win)) { - $var = 'winname'; - } else { - $var = '[.15]itemname'; - } - - if ($prompt_append) { - $prompt = $theme->format_expand("{prompt \$$var}"); - } - - my $trailing_space = ''; - if ($prompt =~ /(\s*)$/ && length $prompt_content) { - $trailing_space = $1; - } - - $prompt .= $prompt_content . $trailing_space; - $sb_item->default_handler($get_size_only, $prompt, undef, 1); -} - -sub window_is_empty { - my $window = shift; - return $window->{name} eq $window->get_active_name; -} - -sub UNLOAD { - print Dumper(\@_); - uninstall_prompt(); -} diff --git a/history-search/key_test.pl b/history-search/key_test.pl deleted file mode 100644 index b16ff00..0000000 --- a/history-search/key_test.pl +++ /dev/null @@ -1,100 +0,0 @@ -use strict; -use Irssi; -use Irssi::TextUI; # for sbar_items_redraw - -use vars qw($VERSION %IRSSI); -$VERSION = "1.0.1"; -%IRSSI = ( - authors => "shabble", - contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', - name => "", - description => "", - license => "Public Domain", - changed => "" -); - - -Irssi::signal_add_last 'gui key pressed' => \&got_key; - -my $buf = ''; - -sub got_key { - my ($key) = @_; - $buf .= " $key"; - my $res = decode_keypress($key); - if (defined $res) { - print "codes: $buf"; - print "Keypress: $res"; - $buf = ''; - } -} - -# 1 means we've seen an esc, 2 means we've -# seen an esc,[. 0 is normal. - -my $decoder_state = 0; - -sub decode_keypress { - my ($code) = @_; - - if ($decoder_state == 1) { - - # seen esc/meta. - if ($code == ord('[')) { - $decoder_state = 2; - return undef; - } else { - $decoder_state = 0; - return 'meta-' . chr($code); - } - - } elsif ($decoder_state == 2) { - - if ($code == ord('A')) { - $decoder_state = 0; - return 'up-arrow'; - } elsif ($code == ord('B')) { - $decoder_state = 0; - return 'dn-arrow' - } elsif ($code == ord('C')) { - $decoder_state = 0; - return 'right-arrow' - } elsif ($code == ord('D')) { - $decoder_state = 0; - return 'left-arrow' - } - - $decoder_state = 0; - return undef; - - } else { - - if ($code < 27) { - - if ($code == 9) { - return 'tab'; - } - - return 'ctrl-' . chr($code + ord('a') -1); - } - - if ($code > 32 && $code < 127) { - return chr($code); - } - - if ($code == 32) { - return 'space'; - } - - if ($code == 127) { - return 'backspace'; - } - - if ($code == 27) { - $decoder_state = 1; - return undef; - } - - return 'unknown ' . $code; - } -} diff --git a/history-search/subtest.pl b/history-search/subtest.pl deleted file mode 100644 index fd5a9cc..0000000 --- a/history-search/subtest.pl +++ /dev/null @@ -1,76 +0,0 @@ -use strict; -use Irssi; -use Irssi::TextUI; -use Data::Dumper; - -use vars qw($VERSION %IRSSI); -$VERSION = '1.0'; -%IRSSI = ( - authors => 'Wouter Coekaerts', - contact => 'coekie@irssi.org', - name => 'history_search', - description => 'Search within your typed history as you type (like ctrl-R in bash)', - license => 'GPLv2 or later', - url => 'http://wouter.coekaerts.be/irssi/', - changed => '04/08/07' -); - - -Irssi::command_bind("foo bar", \&subcmd_bar); -Irssi::command_bind("foo", \&subcmd_handler); - -sub subcmd_handler { - my ($data, $server, $item) = @_; - $data =~ s/\s+$//g; - Irssi::command_runsub('foo', $data, $server, $item); -} - -sub subcmd_bar { - my ($args) = @_; - print "subcommand called with: $args"; -} - -# my $prev_typed; -# my $prev_startpos; -# my $enabled = 0; - -# Irssi::command_bind('history_search', sub { -# $enabled = ! $enabled; -# if ($enabled) { -# $prev_typed = ''; -# $prev_startpos = 0; -# } -# }); - -# Irssi::signal_add_last 'gui key pressed' => sub { -# my ($key) = @_; - -# if ($key == 10) { # enter -# $enabled = 0; -# } - -# return unless $enabled; - -# my $prompt = Irssi::parse_special('$L'); -# my $pos = Irssi::gui_input_get_pos(); - -# if ($pos < $prev_startpos) { -# $enabled = 0; -# return; -# } - -# my $typed = substr($prompt, $prev_startpos, ($pos-$prev_startpos)); - -# my $history = ($typed eq '') ? '' : Irssi::parse_special('$!' . $typed . '!'); -# if ($history eq '') { -# $history = $typed; -# } - -# my $startpos = index(lc($history), lc($typed)); - -# Irssi::gui_input_set($history); -# Irssi::gui_input_set_pos($startpos + length($typed)); - -# $prev_typed = $typed; -# $prev_startpos = $startpos; -# }; -- cgit v1.2.3