aboutsummaryrefslogtreecommitdiffstats
path: root/vimput.pl
diff options
context:
space:
mode:
authorTeddy Wing2017-12-16 11:45:07 +0100
committerTeddy Wing2017-12-16 11:45:07 +0100
commit0cefdb4ac9bfd4ebea557c97bdd4a39dc8ae3b10 (patch)
tree5d823826445df859c6bc753e5c3151af28f87847 /vimput.pl
parent1e782a294d02d74b29f0cfb7d138d41d31c2f106 (diff)
downloadirssi-vimput-0cefdb4ac9bfd4ebea557c97bdd4a39dc8ae3b10.tar.bz2
Get simple forking working without Vim & FIFO nonsense
Add a simple fork that creates a pipe between the parent and child processes so they can communicate with one another, passes a message from the child to the parent, and prints that message to the Irssi window. Thanks to these plugins which I used as invaluable examples: https://github.com/shabble/irssi-scripts/blob/master/feature-tests/pipes.pl https://github.com/irssi/scripts.irssi.org/blob/d62bb05a34ffd6d8d0f719c551d8e454880ef8e1/scripts/chansearch.pl https://github.com/irssi/scripts.irssi.org/blob/d62bb05a34ffd6d8d0f719c551d8e454880ef8e1/scripts/shortenurl.pl https://github.com/irssi/scripts.irssi.org/blob/d62bb05a34ffd6d8d0f719c551d8e454880ef8e1/scripts/dns.pl
Diffstat (limited to 'vimput.pl')
-rw-r--r--vimput.pl77
1 files changed, 52 insertions, 25 deletions
diff --git a/vimput.pl b/vimput.pl
index 35eabc6..3ef0e87 100644
--- a/vimput.pl
+++ b/vimput.pl
@@ -141,39 +141,66 @@ sub update_input_line_when_finished {
# unlink $fuckyoumotherfucker;
-# my $pid = fork();
-# die $! if not defined $pid;
-#
-# if ($pid == 0) {
- my $fuckyoumotherfucker = '/tmp/fucking-fifo';
- unlink $fuckyoumotherfucker;
- open_tmux_split('/tmp/fucking-other-file', $fuckyoumotherfucker);
-
- mkfifo($fuckyoumotherfucker, 0600) or die $!;
- open my $fifo, '<', $fuckyoumotherfucker, or die $!;
- while (<$fifo>) {
- chomp $_;
- Irssi::gui_input_set($_);
+ my ($read_handle, $write_handle);
+
+ pipe($read_handle, $write_handle);
+
+ my $pid = fork();
+
+ if (!defined $pid) {
+ print "Failed to fork: $!"; # TODO: Irssi print
+ close $read_handle;
+ close $write_handle;
+ return;
}
- close $fifo;
- unlink $fuckyoumotherfucker;
- # exit;
-# }
-# else {
-# Irssi::pidwait_add($pid);
-# }
+if ($pid == 0) {
+ # my $fuckyoumotherfucker = '/tmp/fucking-fifo';
+ # unlink $fuckyoumotherfucker;
+ #
+ # # TODO: This needs to be done in the parent
+ # open_tmux_split('/tmp/fucking-other-file', $fuckyoumotherfucker);
+ #
+ # mkfifo($fuckyoumotherfucker, 0600) or die $!;
+ # open my $fifo, '<', $fuckyoumotherfucker, or die $!;
+ # while (<$fifo>) {
+ # chomp $_;
+ # # Irssi::gui_input_set($_);
+ # print $write_handle $_;
+ # }
+ # close $fifo;
+ # unlink $fuckyoumotherfucker;
+
+ print $write_handle 'worked?';
+ close $write_handle;
+
+ POSIX::_exit(0);
+}
+else {
+ close $write_handle;
+
+ Irssi::pidwait_add($pid);
+
+ my $pipe_tag;
+ my @args = ($read_handle, \$pipe_tag);
+ $pipe_tag = Irssi::input_add(
+ fileno $read_handle,
+ Irssi::INPUT_READ,
+ \&pipe_input,
+ \@args,
+ );
+}
}
-sub adljkhadhadfhjkl {
+sub pipe_input {
my ($args) = @_;
- my ($fifo, $tag) = @$args;
+ my ($read_handle, $pipe_tag) = @$args;
- my $input = <$fifo>;
+ my $input = <$read_handle>;
print 'I: ' . $input;
- close $fifo;
- Irssi::input_remove($$tag);
+ close $read_handle;
+ Irssi::input_remove($$pipe_tag);
}