From 91585163e7f7cd886b2bce4c98dbc3d14b9d3c2e Mon Sep 17 00:00:00 2001 From: Tom Feist Date: Thu, 14 Oct 2010 21:42:31 +0100 Subject: misc: tidying up my working dir --- feature-tests/augment_inputline.pl | 69 ++++++++++++++++++++++++ feature-tests/safe.sub | 4 ++ feature-tests/safescript.pl | 104 +++++++++++++++++++++++++++++++++++++ feature-tests/sbar-crash.pl | 15 ++++++ 4 files changed, 192 insertions(+) create mode 100644 feature-tests/augment_inputline.pl create mode 100644 feature-tests/safe.sub create mode 100644 feature-tests/safescript.pl create mode 100644 feature-tests/sbar-crash.pl (limited to 'feature-tests') diff --git a/feature-tests/augment_inputline.pl b/feature-tests/augment_inputline.pl new file mode 100644 index 0000000..577f756 --- /dev/null +++ b/feature-tests/augment_inputline.pl @@ -0,0 +1,69 @@ +use strict; +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw +use Term::Size; + +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 $buf = ''; + +Irssi::command_bind('dogui', \&print_to_input); +Irssi::signal_add_last('gui key pressed', \&key_pressed); + +sub stuff { + my $win = Irssi::active_win; + my ($w, $h); + $w = $win->{width}; + $h = $win->{height}; + + my ($term_w, $term_h) = Term::Size::chars *STDOUT{IO}; + print "win size is $w,$h, term is $term_w, $term_h"; + print "Prompt len is: ", Irssi::format_get_length("{prompt foo bar}"); +} + +sub key_pressed { + my ($key) = @_; + my $char = chr($key); + $buf .= $char; + my $str = Irssi::parse_special('$L'); + + print_to_input($str); + +} + +sub print_to_input { + my ($str) = @_; + $str = "%8$str%8"; + + my ($term_w, $term_h) = Term::Size::chars *STDOUT{IO}; + + my $prompt_offset = 11; + my $theme = Irssi::current_theme(); + my $prompt = $theme->format_expand('{prompt $itemname $winname}', + Irssi::EXPAND_FLAG_RECURSIVE_MASK); + #print "Prompt is $prompt"; + Irssi::gui_printtext($prompt_offset, $term_h, $str); +} + + +sub parse_theme_file { + my ($file) = @_; + open my $fh, '<', $file or die "Couldn't open $file for reading: $!"; + while (my $line = <$fh>) { + next if $line =~ m/^\s*#/; # comment + if ($line =~ m/^\s*prompt\s*=\s*"([^"]+)";\s*$/) { + my $prompt = $1; + } + } + close $fh or die "Couldn't close fh for $file: $!"; +} diff --git a/feature-tests/safe.sub b/feature-tests/safe.sub new file mode 100644 index 0000000..fcf7ff3 --- /dev/null +++ b/feature-tests/safe.sub @@ -0,0 +1,4 @@ +sub moo { print "Moo" } +sub hello { print join( ", ", @_) } + +bless {}, __PACKAGE__; diff --git a/feature-tests/safescript.pl b/feature-tests/safescript.pl new file mode 100644 index 0000000..2d741e9 --- /dev/null +++ b/feature-tests/safescript.pl @@ -0,0 +1,104 @@ +use strict; +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw +use Safe; + +use vars qw($VERSION %IRSSI); + +$VERSION = "0.1"; + +%IRSSI = ( + authors => "shabble", + contact => 'shabble+irssi@metavore.org, shabble@#irssi/Freenode', + name => "", + description => "", + license => "Public Domain", + changed => "" +); + +my $safe; +my $objs = {}; +init(); + +sub _input { + return int rand 1000; +} + +sub load { + my $file = shift; + my $obj; + if (-f $file) { + $obj = $safe->rdo($file); + } + $objs->{ref $obj} = $obj; + # print "Loading from file: $file"; + # $funcs = do $file; + # } + # if (not defined $funcs) { + # if ($@) { + # print "failed to parse $file: $@"; + + # } elsif ($!) { + # print "failed to read $file: $!"; + + # } + # return; + # } + # my $ref = ref $funcs; + # if ($ref ne 'HASH') { + # print "$file didn't return a hashref: ", defined $ref ? $ref : 'undef'; + # return; + # } + + # foreach my $name (keys %$funcs) { + # my $func = $funcs->{$name}; + # if (exists $functions->{$name}) { + # print "Redefining function $name"; + # } else { + # print "adding function: $name"; + # } + # $functions->{$name} = $func; + # } + + # print "Loaded " . scalar(keys(%$funcs)) . " functions"; +} + +sub init { + Irssi::command_bind('subload', \&cmd_subload); + Irssi::command_bind('sublist', \&cmd_sublist); + Irssi::command_bind('subcall', \&cmd_subcall); + + $safe = new Safe; +} + +sub cmd_subload { + my $args = shift; + print "Going to load: $args"; + load($args); +} + +sub cmd_sublist { + foreach my $name (keys %$functions) { + my $func = $functions->{$name}; + print "Function: $name => $func"; + } +} + +sub cmd_subcall { + my $args = shift; + my ($cmd, $cmdargs); + if ($args =~ m/^(\w+\b)(.*)$/) { + $cmd = $1; $cmdargs = $2; + } else { + print "Couldn't parse $args"; + return; + } + my $fun = $functions->{$cmd}; + + if (ref $fun eq 'CODE') { + print "Calling $cmd with $cmdargs"; + $fun->($cmdargs); + } else { + print "$cmd is not a coderef. cannot run"; + } +} diff --git a/feature-tests/sbar-crash.pl b/feature-tests/sbar-crash.pl new file mode 100644 index 0000000..5547bbd --- /dev/null +++ b/feature-tests/sbar-crash.pl @@ -0,0 +1,15 @@ +use strict; +use warnings; + +use Irssi; +use Irssi::TextUI; # for sbar_items_redraw + +Irssi::statusbar_item_register('uberprompt', 0, 'uberprompt_draw'); +Irssi::command("STATUSBAR prompt add -alignment left -before input -priority '-1' uberprompt"); + +sub uberprompt_draw { + my ($sb_item, $get_size_only) = @_; + print "This is a test"; + return $sb_item->default_handler($get_size_only, '{uberprompt $winname}', '', 0); +} + -- cgit v1.2.3