Skip to content
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

Delete key not working in certain shells and terminals #12567

Open
mil-ad opened this issue Sep 30, 2020 · 2 comments
Open

Delete key not working in certain shells and terminals #12567

mil-ad opened this issue Sep 30, 2020 · 2 comments
Milestone

Comments

@mil-ad
Copy link

mil-ad commented Sep 30, 2020

I have noticed that the delete key does bit work (prints [P instead of deleting character) when I use ipython in st terminal with zsh shell. When I use the same terminal but in bash the delete key works fine!

st FAQ suggests adding tput smkx to .bashrc or lines below to .zshrc to fix the issue.

function zle-line-init () { echoti smkx }
function zle-line-finish () { echoti rmkx }
zle -N zle-line-init
zle -N zle-line-finish

Unfortunately this doesn't fix the problem in iPython. I actually had exactly the same problem with vanilla python prompt too but adding set enable-keypad on to my .inputrc fixed it for python. I believe ipython doesn't use readlines anymore.

@mwageringel
Copy link
Contributor

With bash, I have the same problem. Initially, the tput smkx workaround from the st-FAQ seemed to work, but it stops working when less, or a pager in IPython, is used, so is not really workable.

The st terminal is determined to send ^[[P instead of ^[[3~ if enable-keypad is not set in ~/.inputrc.

As IPython uses prompt-toolkit instead of readline and thus ignores ~/.inputrc, it receives the ^[[P sequence regardless. Here is a workaround to bind this to delete (adapted from here):

from IPython import get_ipython
from prompt_toolkit.enums import DEFAULT_BUFFER
from prompt_toolkit.filters import HasFocus

def _delete(event):
    event.current_buffer.delete(count=event.arg)

# Register the shortcut if IPython is using prompt_toolkit
ip = get_ipython()
if getattr(ip, 'pt_app', None):
    ip.pt_app.key_bindings.add('escape', '[', 'P',
                               filter=HasFocus(DEFAULT_BUFFER))(_delete)

Other key combos might be affected as well.

Should this be reported as a prompt-toolkit issue?

@MrMino
Copy link
Member

MrMino commented May 16, 2021

@mwageringel Yes, this is an issue with prompt-toolkit, not IPython. I'll leave this open just in case it turns out that it's just something that IPython needs to tell PT to support, but otherwise I think you guys should take it up to the PT issue tracker first.

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

No branches or pull requests

3 participants