New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Readline's history search in ipython console does not clear properly after cancellation with Ctrl+C #2486
Comments
Yes, I experience this as well. Not sure how to fix it yet, but for those joining us the keyboard interrupt is handled in TerminalInteractiveShell.interact. Also this might be a limitation of readline itself, as it doesn't clear the line buffer on CTRL-C and there isn't an exposed Python interface for changing the line buffer. |
Hmm, this seems to be a problem with Python itself too. I don't think there is necessarily anything we can do here in IPython. Can you try out the regular Python interpreter and possibly file a bug report with them upstream? |
The bug could even be in readline itself. |
I don't think this is a bug in GNU readline, but a missing feature in Python's readline module. If we could call I've seen proposals to add these methods to the stdlib going back before Python 2.3, but it hasn't happened. |
Plus, I'm closing this as a duplicate of #1286. |
The previous KeyboardInterrupt handling is dangerous because previous lines or commands can be mistakenly executed. When a user interrupts a readline reverse search (C-r) with C-c, a KeyboardInterrupt is thrown, but the readline buffer still has a line in the buffer from the search attempt. The previous behavior of IPython was to show a blank line instead of the current readline buffer, causing a previous command to be executed if the user presses enter on the seemingly blank line. Additionally, keyboard input was not shown on the blank line because readline was still in reverse search mode. For example, pressing C-k on the blank line would reset readline, but most users would expect the input buffer that IPython displays to be correct because of the prominently displayed KeyboardInterrupt. This modifies how a KeyboardInterrupt is handled in IPython. Under normal circumstances in the operation of readline, a KeyboardInterrupt should never be thrown. IPython now displays a helpful reminder to use default readline keybindings (which might be overridden by ~/.inputrc, but whatever), and then displays the current line buffer on the next line. Another possible solution would be to send C-g (abort reverse search) or C-k to readline through raw_input somehow. However, this solution would require checking ~/.inputrc to figure out what the current "abort reverse search" keybinding is. fixes ipython#1286 fixes ipython#2486
I often use history search (Ctrl+R) in ipython console prompt (classic console, not Qt console or notebook). The problem is, if I cancel the search by typing Ctrl+C, the last found line still exists in the new prompt line, but not shown. If I press Cursor Right or Cursor Left or Ctrl+A, then that old text would show. This is dangerous since I could inadvertently execute a command I don't want. I observe this problem for a long time (since <= 0.10) and even in the newest one (0.13 running under python 2.6) it is still there. Could anyone else verify if this is a problem with their installation? If so we need to have this fixed.
The text was updated successfully, but these errors were encountered: