diff options
author | Tom Feist <shabble@metavore.org> | 2011-03-01 20:27:13 +0000 |
---|---|---|
committer | Tom Feist <shabble@metavore.org> | 2011-03-01 20:27:13 +0000 |
commit | 6deca692390e63157de0f5682020d65e4e3567f7 (patch) | |
tree | 927bdd3f1bb12620c9a099ac6a70897f8c0f7695 | |
parent | added other tests (diff) | |
download | irssi-scripts-6deca692390e63157de0f5682020d65e4e3567f7.tar.gz irssi-scripts-6deca692390e63157de0f5682020d65e4e3567f7.zip |
uberprompt: updated docs to clarify $uber variable, and polish help stirngs.
-rw-r--r-- | prompt_info/uberprompt.pl | 15 | ||||
-rw-r--r-- | testing/test-shim.pl | 114 |
2 files changed, 124 insertions, 5 deletions
diff --git a/prompt_info/uberprompt.pl b/prompt_info/uberprompt.pl index 0706d29..70d083d 100644 --- a/prompt_info/uberprompt.pl +++ b/prompt_info/uberprompt.pl @@ -25,6 +25,9 @@ # be replaced by the original prompt content. # A parameter corresponding to the UP_* constants listed below # is required, in the format `/prompt set -inner Hello!' +# +# /prompt set [-inner|-pre|-post|only] <msg> +# # /prompt clear - clears the additional data provided to the prompt. # /prompt on - enables the uberprompt (things may get confused if this is used # whilst the prompt is already enabled) @@ -39,7 +42,9 @@ # # /set uberprompt_format <format> # -# The default is [$*], which is the same as the default provided in default.theme. +# The default is [$*$uber], which is the same as the default provided in +# default.theme. $uber is a placeholder variable to contain your additions +# to the prompt when using the -inner mode. # Changing this setting will update the prompt immediately, unlike editing your theme. # # An additional variable available within this format is '$uber', which expands to @@ -198,11 +203,11 @@ sub _print_help { " or a script", "/PROMPT SET changes the contents of the prompt, according to the mode", " and content provided.", - " -inner sets the value of the \$uber psuedo-variable in the", + " { -inner sets the value of the \$uber psuedo-variable in the", " /set uberprompt_format setting.", - " -pre places the content before the current prompt string", - " -post places the content after the prompt string", - " -only replaces the entire prompt contents with the given string", + " | -pre places the content before the current prompt string", + " | -post places the content after the prompt string", + " | -only replaces the entire prompt contents with the given string }", "", "See Also:", '', diff --git a/testing/test-shim.pl b/testing/test-shim.pl new file mode 100644 index 0000000..628f7af --- /dev/null +++ b/testing/test-shim.pl @@ -0,0 +1,114 @@ +use strict; +use warnings; + +use Irssi; +use Irssi::Irc; +use Irssi::TextUI; + +use Data::Dumper; +use POSIX; +use Time::HiRes qw/sleep/; +use JSON::Any; + + +our $VERSION = '0.1'; +our %IRSSI = ( + authors => 'shabble', + contact => 'shabble+irssi@metavore.org', + name => 'test-shim', + description => '', + license => 'Public Domain', + ); + + +my $forked = 0; + +sub pipe_and_fork { + my ($read_handle, $write_handle); + pipe($read_handle, $write_handle); + + my $oldfh = select($write_handle); + $| = 1; + select $oldfh; + + return if $forked; + + my $pid = fork(); + + if (not defined $pid) { + _error("Can't fork: Aborting"); + close($read_handle); + close($write_handle); + return; + } + + $forked = 1; + + if ($pid > 0) { # this is the parent (Irssi) + close ($write_handle); + Irssi::pidwait_add($pid); + my $job = $pid; + my $tag; + my @args = ($read_handle, \$tag, $job); + $tag = Irssi::input_add(fileno($read_handle), + Irssi::INPUT_READ, + \&child_input, + \@args); + + } else { # child + child_process($write_handle); + close $write_handle; + + POSIX::_exit(1); + } +} +sub _cleanup_child { + my ($read_handle, $input_tag_ref) = @_; + close $read_handle; + Irssi::input_remove($$input_tag_ref); + _msg("child finished"); + $forked = 0; +} +sub child_input { + my $args = shift; + my ($read_handle, $input_tag_ref, $job) = @$args; + + my $input = <$read_handle>; + my $data = JSON::Any::jsonToObj($input); + if (ref $data ne 'HASH') { + _error("Invalid data received: $input"); + _cleanup_child($read_handle, $input_tag_ref); + } + + if (exists $data->{connection}) { + if ($data->{connection} eq 'close') { + _cleanup_child($read_handle, $input_tag_ref); + } + } else { + parent_process_response($data); + } +} + +sub parent_process_response { + my ($data) = @_; +} + + +sub child_process { + my ($handle) = @_; + +} + +sub _error { + my ($msg) = @_; + my $win = Irssi::active_win(); + $win->print($msg, Irssi::MSGLEVEL_CLIENTERROR); +} + +sub _msg { + my ($msg) = @_; + my $win = Irssi::active_win(); + $win->print($msg, Irssi::MSGLEVEL_CLIENTCRAP); +} + +Irssi::command_bind("start_pipes", \&pipe_and_fork); |