prompt-toolkit / pymux

A terminal multiplexer (like tmux) in Python
BSD 3-Clause "New" or "Revised" License
1.44k stars 82 forks source link

C-j as prefix causes <Enter> key to be treated as prefix #49

Closed haridsv closed 8 years ago

haridsv commented 8 years ago

In tmux, you can set C-j as the prefix, e.g.:

set-option prefix C-j
unbind C-b
bind C-j send-prefix

Somehow tmux is able to distinguish Ctrl+j and <Enter>, but pymux is unable to. In tmux, <Enter> continues to work just fine and Ctrl+j immediately gets recognized as prefix. In pymux, both are treated equally, so to enter a new line, I have to press Ctrl+j or <Enter> twice.

haridsv commented 8 years ago

Actually, I forgot that <Enter> is Ctrl+m, but this SO thread could be useful here: http://stackoverflow.com/a/14619214/95750

Perhaps pymux needs to do something equivalent of nonl in curses to avoid translating Ctrl+m to Ctrl+j? I am not familiar with python-prompt-toolkit but I didn't find anything by skimming through its documentation.

haridsv commented 8 years ago

I tried this, but it didn't make a difference :(

https://github.com/haridsv/python-prompt-toolkit/commit/d39743cf4db7605806d363a746a2865deb1a91e9

haridsv commented 8 years ago

I took another look and found that prompt-toolkit doesn't actually support treating C-M and C-J separately. In vt100_input.py, I noticed the below:

                    # Replace \r by \n. (Some clients send \r instead of \n
                    # when enter is pressed. E.g. telnet and some other
                    # terminals.) It's also too complicated to handle \r and \n
                    # separetely in the key bindings.
                    if c == '\r':
                        c = '\n'
                    self._input_parser.send(c)

This means, the issue is with prompt-toolkit, not with pymux.

jonathanslenders commented 8 years ago

Hi @haridsv,

I noticed that indeed we are replacing \r with \n. However this is not correct, and it needs to be fixed in prompt-toolkit. The hard part is that the enter key is supposed to send \r, not \n in most terminals. (If I recall correctly.) But some applications, like IPython bind a custom key to \n, for custom handling of the enter key. Changing this is a breaking change and unfortunately I think, it's impossible to do before prompt-toolkit 2.0.0... But I'd like to fix it at some point.

Thanks for creating this issue! Jonathan

haridsv commented 6 years ago

@jonathanslenders With the latest fix in prompt-toolkit, I checked out 2.0 branch and the latest master from pymux and notice that the original issue is still there, i.e., every other Enter gets consumed. Is there anything else I am supposed to do? I am using the same config that I originally posted above.