Skip to content

Conversation

@jmriego
Copy link

@jmriego jmriego commented Aug 21, 2017

This pull request is for adding the option to reply to stdin requests from the kernel.
With this, it's possible to prompt for users, passwords or even use ipdb to debug a program.

Everytime the kernel asks for input, it will inform of that in the status line and it's possible to answer by going to the vim-ipython buffer and editing the last line, which will show the prompt text. I'm using vim input or inputsecret functions to ask for user input as I think that's more appropiate than just writing text in the buffer

@wilywampa
Copy link
Owner

I like it, but can you think of a way to respond to input requests using the command prompt only without having to open vim-ipython up in the preview window?

@jmriego
Copy link
Author

jmriego commented Aug 22, 2017

Thanks! What about adding a command for answering prompts?
It could be something like this:
You read in the status line that there is a request for input. Then run the command :IPythonInput (and it will show the current prompt).
If going this way, I should also probably add :IPythonInput! just in case you want to reply to input requests coming from another client.

I could also add a mapping to call this command. for input maybe?

I'm not sure whether or not to add parameters to this :IPythonInput command and send the those directly to the kernel. That should be fine most of the time but people should be careful when typing passwords that way

@wilywampa
Copy link
Owner

For some reason I'm getting NameError: name 'EnteredInsertMode' is not defined when I try to respond to an input request.

I'd prefer having :IPythonInput rather than having to enter insert mode in the monitor buffer. That way the autocmds wouldn't be necessary and it will be easier to use if monitor_subchannel is false.

As for having a mapping, I think we already have quite a mess of mappings and it's not hard to just map :<C-u>IPythonInput rather than having a new <Plug> mapping.

I'm also unsure about accepting the input itself as part of the command. It sort of makes sense for a regular input request but we definitely don't want passwords stored in command history. To keep the regular and secret as similar to each other as possible, the command should just bring up the input() or inputsecret() prompt as appropriate.

@jmriego
Copy link
Author

jmriego commented Aug 27, 2017

I have made some changes to the code and created two commands; :IPythonInput and :IPythonInputSecret

:IPythonInput works by checking if there is a pending input request and calling input() or inputsecret() prompt as appropiate. :IPythonInputSecret will always call inputsecret(). I'm not really sure this is needed, but it's probably a nice to have in some situations.
Calling these commands has the advantage that vim keeps a history of the inputs provided (of course not if the input is secret). So it's really easy to repeat last inputs

By calling either of these commands with a bang, e.g. :IPythonInput! you can send an answer to the kernel even if vim-ipython does not detect a pending input request. I have used this when I have a pending input request in Jupyter notebook and close the cell by mistake. As it would be no longer possible to answer in the notebook, you can call :IPythonInput! to save the situation

@jmriego jmriego closed this Aug 27, 2017
@jmriego jmriego reopened this Aug 27, 2017
@jmriego
Copy link
Author

jmriego commented Aug 27, 2017

By the way, what are you doing exactly to get that error? I can't find the reason for it...

@wilywampa
Copy link
Owner

I was running in neovim and the error message was sort of misleading. I now ran it in vim8 and got the error E319: Sorry, the command is not available in this version: :py EnteredInsertMode() because I am compiled with Python 3 and not Python 2. I'd really prefer to get rid of all the insert mode parts of this and just go with the prompt. Is there a good reason you want to enter input by editing the last line instead (noting you can open the command window from an input prompt by pressing <C-f> if the issue is that you want all of vim's editing features)?

@jmriego
Copy link
Author

jmriego commented Aug 27, 2017

To be honest, I found it easy to do so and it felt almost like working with a shell. It's not really needed and it's actually a bit different to other vim plugins so I just removed the insert mode parts. If anyone wants to do this, he can just get my previous commit and do something similar with autocommands in .vimrc

@wilywampa wilywampa merged commit 69f9a52 into wilywampa:master Aug 28, 2017
@wilywampa
Copy link
Owner

Thanks. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants