diff options
author | Tom Feist <shabble@cowu.be> | 2010-07-24 17:23:13 +0000 |
---|---|---|
committer | Tom Feist <shabble@cowu.be> | 2010-07-24 17:23:13 +0000 |
commit | 91f126ae4c9ea90336bdeb24001fadca79439edc (patch) | |
tree | d21b72a82b67b0979aadfa3f6efbbc2586d962b1 /feature-tests | |
parent | updated script info to add my url and to change contact details to me (diff) | |
download | irssi-scripts-91f126ae4c9ea90336bdeb24001fadca79439edc.tar.gz irssi-scripts-91f126ae4c9ea90336bdeb24001fadca79439edc.zip |
moved most tests to feature-tests/
Diffstat (limited to 'feature-tests')
-rw-r--r-- | feature-tests/complete_test.pl | 27 | ||||
-rw-r--r-- | feature-tests/expando_test.pl | 58 | ||||
-rw-r--r-- | feature-tests/frog_reload.pl | 99 | ||||
-rw-r--r-- | feature-tests/help_a.pl | 15 | ||||
-rw-r--r-- | feature-tests/help_b.pl | 15 | ||||
-rw-r--r-- | feature-tests/key_test.pl | 100 | ||||
-rw-r--r-- | feature-tests/subtest.pl | 76 |
7 files changed, 390 insertions, 0 deletions
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; +# }; |