aboutsummaryrefslogtreecommitdiffstats
path: root/vimput.pl
AgeCommit message (Collapse)Author
2017-12-17Get rid of `$child` variableTeddy Wing
We got rid of the code that used it in dd9e692fcedf220bca2b6981184c6ba2738cb6c3 but forgot to remove it in that commit.
2017-12-17Rename `update_input_line_when_finished`Teddy Wing
Make it even longer! Well, the original name didn't seem to be descriptive enough since we're calling `open_tmux_split` inside it instead of in the signal handler.
2017-12-17pipe_input: Make subroutines for message prefix conditionsTeddy Wing
Make this more readable by giving names to these `index` tests.
2017-12-17update_input_line_when_finished: Send error messages to pipeTeddy Wing
Where we had previously `die`d, instead send those error messages to our pipe so they can be printed by the parent process using: Irssi::print(<error>, MSGLEVEL_CLIENTERROR);
2017-12-17open_tmux_split: Get rid of old commented codeTeddy Wing
2017-12-17Delete the error pipeTeddy Wing
Now that we're passing errors on the main pipe (9c43c1637587e004c4826d79021e4d6164543e1e), we no longer need this one.
2017-12-17Send errors from child process to parent and print to IrssiTeddy Wing
We previously `die`d in the child process when we encountered an error, but this didn't kill the child process. Instead, we needed to `POSIX::_exit(1);` in order to really exit. When `die`ing, the `print` messages in the child would actally get up to the parent, but now that we exit correctly they no longer do. In order to get the messages to the parent so the parent can print them to Irssi, I tried a couple things. First I tried creating a new pipe between the parent and child, but this didn't get me the messages printing. Asked on Freenode#irssi, and Nei suggested using the same pipe I'm already using but with a distinguishing prefix for 'ok' and 'error'. Gave it a try and this time it worked! Yay!
2017-12-16Only permit a single child forkTeddy Wing
Things get really messed up if we fork multiple times. Try pressing C-x, then switching back to the Irssi window and pressing C-x again. Another Vim opens and the pipes get all confused. Prevent that craziness by only ever allowing a single child fork. Following the pattern from: https://github.com/shabble/irssi-scripts/blob/master/feature-tests/pipes.pl https://github.com/irssi/scripts.irssi.org/blob/d62bb05a34ffd6d8d0f719c551d8e454880ef8e1/scripts/chansearch.pl
2017-12-16Move child fork test to a subroutineTeddy Wing
Gives the test a name making it easier to read.
2017-12-16update_input_line_when_finished: ReindentTeddy Wing
2017-12-16Remove second pipeTeddy Wing
We don't need this any more. It was supposed take the tempfile name from the child fork and open a Vim instance with that filename, but we found out we couldn't do that in the parent process, we had to do it in the fork. So we have no need to pass the tempfile name to the parent process and no need for this pipe. Also thankfully gets rid of obscenities.
2017-12-16Get rid of old commented codeTeddy Wing
Now that we have a FIFO that works, we can obliterate the old failed tries, and a few frustration-fueled obscenities.
2017-12-16Set prompt to saved Vim contentsTeddy Wing
Instead of just printing the contents of the FIFO, now that we know that things work, update the prompt input with the newly-edited string.
2017-12-16open_tmux_split: Remove filename first argumentTeddy Wing
The filename isn't useful to us any more since we can't open the FIFO directly from Vim (`vim $fifo`). But, in order to be able to close Vim after writing without it complaining that we haven't written the buffer to a file, we need to appease it by giving it a random filename.
2017-12-16Open Vim instance without blockingTeddy Wing
I tried to open the Vim instance in `pipe_open_tmux_split`, but this gave me the same problems as before with Vim not able to write to the pipe. This was because the main Irssi process was blocked on the `open` and wasn't reading from the pipe. The mistake was opening Vim from the parent Irssi. Instead, open it from the child fork so we don't block the parent and all is good. We can open Vim and correctly save to the pipe. Yeah!
2017-12-16Use separate `Irssi::input_add` handlers for command & inputTeddy Wing
Instead of handling both commands and text input in the same subroutine, use separate ones so we can keep the code more isolated and handle the subseqent actions differently.
2017-12-16Distinguish between commands and input in pipe readerTeddy Wing
Have a way to determine the difference between an input text and a message containing the temp file name.
2017-12-16Put the FIFO back inTeddy Wing
Now that we have two pipes to communicate between our forks, test the FIFO again instead of the socket. The reason why I tried using a socket instead was because I was hoping that would get rid of the pipe blocking, but it didn't. Instead it exhibited the same blocking behaviour as the pipe. Re-enable the FIFO instead of the socket. I'm going to go with this version instead because it seems like a pipe is more light-weight and it works basically the same.
2017-12-16Get rid of the sleep while reading the socketTeddy Wing
We don't need this any more. The socket will block and wait for us to send it a message.
2017-12-16Use two pipe to communicate between forksTeddy Wing
Instead of passing messages (prompt input) and commands (location of temp file) on the same pipe from the child fork to the parent, use separate pipes. This eliminates blocking behaviour and prints the temp file location right away. It is then able to read from the socket, and feed the text up the pipes to be printed too. Stupid error on my part feeding `@args` to the second `Irssi::input_add` instead of `@ar2`. Yay, it works! Suck it Perl!
2017-12-16Try to use Unix domain sockets for inter-process communicationTeddy Wing
Wanted to see if this wouldn't block like named pipes do but they fucking do. How the fuck do I get the temp file name to Vim and listen on the pipe/socket at the same time? Damn it! Refered to https://github.com/irssi/scripts.irssi.org/blob/4c409ee2ed0d1378159cbe08264c77f005c1f412/scripts/adv_windowlist.pl among other resources for help with Unix sockets.
2017-12-16Get simple forking working without Vim & FIFO nonsenseTeddy Wing
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
2017-12-16FIFO sort of worksTeddy Wing
After a ton of trial and error, I have something that kind of works. Couldn't figure out forking for the moment, so this does block Irssi. And if you do something like change the window layout in Tmux with <prefix>-M-1, it messes up and closes the FIFO prematurely. Key points were: * Opening Vim before making the FIFO, otherwise Vim will block and not start. * Opening Vim with a random other file instead of the FIFO because it hasn't been created yet. On write, Vim is set up to write to the FIFO. Luckily chat messages don't get messed up when the interface blocks, but I'd like to fix that urgently.
2017-12-16Try to listen on a FIFO for the updated messageTeddy Wing
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`.
2017-12-15Take note of a possible message level to use for errorsTeddy Wing
2017-12-15Add a TODO to see if we can replace our signal with a commandTeddy Wing
2017-12-15Open a Tmux split with the prompt contentsTeddy Wing
After writing to the file, our keyboard shortcut opens a Tmux pane with a Vim and our input message available for editing. If we're not in Tmux, we should print an error message. Need to rewrite that to print a real Irssi message.
2017-12-15Write input contents on C-xTeddy Wing
Instead of writing the input message to a file on every key press, only write when Ctrl-X is pressed. This will be our command for opening Vim.
2017-12-15Write input contents on key pressTeddy Wing
Now instead of printing the current input to the Irssi window, write it to a script-specific file. The filename is inspired by Git. I figure we'll probably want to remove the file when we're done with it. Debated between creating a real temp file and using this one. We'll decide that later.
2017-12-15Make `$VERSION` and `%IRSSI` `our` variablesTeddy Wing
Learned about the Perl `our` keyword from https://github.com/shabble/irssi-docs/wiki/Guide#preamble which recommends using it. This allows us to eliminate the `use vars` line. Neat.
2017-12-15Print current input contentsTeddy Wing
Yes! Managed to read the current input line contents. Print this out on every key press. Thanks to these resources: Key press signal: https://github.com/shabble/irssi-docs/wiki/Signals#gui-readlinec Getting input line contents: https://github.com/shabble/irssi-docs/wiki/Irssi#getting-the-input-field-contents https://github.com/irssi/scripts.irssi.org/blob/master/scripts/per_window_prompt.pl