aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-12-16 00:47:01 +0100
committerTeddy Wing2017-12-16 00:47:01 +0100
commitd5a68da75fad329cdd63882ebcc4b580f4a3afee (patch)
tree96b3635747e943b259f5eefefb906baa3387ab92
parent676ce93f641fbbe8424627b1ea411b5ddbcf4ded (diff)
downloadirssi-vimput-d5a68da75fad329cdd63882ebcc4b580f4a3afee.tar.bz2
Try to listen on a FIFO for the updated message
All kinds of things wrong with this, I'm just fiddling to try to see if I can get something to work. This blocks Irssi, which is bad. * Rename `tempfile` to `vimput_file` so as not to collide with the `tempfile()` function that creates a temporary file. * Add a new sub that ostensibly is supposed to read from a file handle and print the message received. Read https://github.com/shabble/irssi-docs/wiki/Guide#Dealing-with-Blocking-IO and https://github.com/shabble/irssi-scripts/blob/master/feature-tests/pipes.pl I feel like I have a better idea of how to deal with this using `fork`.
-rw-r--r--vimput.pl35
1 files changed, 30 insertions, 5 deletions
diff --git a/vimput.pl b/vimput.pl
index abf3da4..de9e04d 100644
--- a/vimput.pl
+++ b/vimput.pl
@@ -1,5 +1,7 @@
use strict;
+use File::Temp qw(tempfile);
+
use Irssi;
our $VERSION = '1.00';
@@ -16,22 +18,22 @@ use constant CTRL_X => 24;
# The location of the temporary file where prompt contents are written.
-sub tempfile {
+sub vimput_file {
Irssi::get_irssi_dir() . '/VIMPUT_MSG';
}
-# Write the given string to our tempfile.
+# Write the given string to our vimput_file.
sub write_input {
my ($message) = @_;
- open my $handle, '>', tempfile or die $!;
+ open my $handle, '>', vimput_file or die $!;
print $handle $message;
close $handle;
}
-# Open a Tmux split containing a Vim instance editing the tempfile.
+# Open a Tmux split containing a Vim instance editing the vimput_file.
sub open_tmux_split {
if (!$ENV{TMUX}) {
print 'no tmux'; # TODO: Replace with Irssi print
@@ -39,11 +41,33 @@ sub open_tmux_split {
return;
}
- my $command = "vim ${\tempfile}";
+ my $command = "vim ${\vimput_file}";
system('tmux', 'split-window', $command);
}
+sub update_input_line_when_finished {
+ my ($handle, $filename) = tempfile();
+ print $filename;
+
+ open $handle, '<', $filename or die $!;
+ # my $x = 0;
+ while (<$handle>) {
+ print $_;
+ if ($_) {
+ print $_;
+ Irssi::gui_input_set($_);
+
+ close $handle;
+ last;
+ }
+ # print $_;
+ # sleep 2;
+ # $x++;
+ }
+}
+
+
# TODO: Find out if it's possible to do this is a command
Irssi::signal_add_last 'gui key pressed' => sub {
my ($key) = @_;
@@ -51,5 +75,6 @@ Irssi::signal_add_last 'gui key pressed' => sub {
if ($key eq CTRL_X) {
write_input(Irssi::parse_special('$L', undef, 0));
open_tmux_split();
+ update_input_line_when_finished();
}
};