ctrl-^ escape not ideal #215

Closed
pimlott opened this Issue Apr 17, 2012 · 29 comments

Projects

None yet
@pimlott
pimlott commented Apr 17, 2012

This is issue 187 reformulated as a feature request. There are two problems with the current escape mechanism:

  • ctrl-^ is a commonly-used command in vi.
  • Sending a literal ctrl-^ is awkward.

I would suggest using the same escape mechanism as ssh (newline tilde). It has the following good properties:

  • It is already familiar to users.
  • The begin-escape sequence is two characters, thus rarely entered unintentionally.
  • The first character (newline) of the escape gets sent immediately, so the user rarely sees his input swallowed. (The necessity of sending a newline when you want the escape sequence is practically never an issue.)
  • In the rare case that you enter the begin-escape sequence unintentionally, you just hint tilde again to send a literal tilde. If the user is confused because his tilde didn't work, he is likely to do that anyway.

If you are wedded to preserving ctrl-^ . as the quit sequence, I would suggest at least making the behavior a little saner:

  • ctrl-^ ctrl-^ should send a literal ctrl-^ (not two).
  • ctrl-^ should send literal ctrl-^ , except for a fixed set of s. They may as well follow ssh, and you may as well reserve them now even if they are not implemented.

Making the escape key configurable may be considered.

@saurik saurik added a commit to saurik/mosh that referenced this issue Apr 18, 2012
@saurik saurik Use OpenSSH escape sequences, suggested by @pimlott in #215. f8208e4
@saurik
Contributor
saurik commented Apr 18, 2012

I went ahead and implemented the OpenSSH escape sequence behavior (and factored out the character to a variable so it might be able to be set by a configuration option later) in the referenced commit. I believe I implemented the OpenSSH semantics faithfully, but I'd totally be willing to believe I screwed up. (No clue if it will be wanted or merged, obviously, but I personally liked the suggestion, and figured I'd hand it over ;P.)

@pimlott
pimlott commented Apr 18, 2012

You rock! I haven't tried it but it looks right. Things I noticed:

  • I have no idea if '\r' starting an escape sequence is right, but if you copied from ssh I believe it.
  • You left in a literal '~'. :-)

I'll try to take a closer look later.

@saurik
Contributor
saurik commented Apr 18, 2012
  1. It turns out that '\r' was actually /required/: it did not work when I tested it using '\n'. I did not copy the code, however, so I'm willing to believe it should be /only/ '\r', but only checking for '\n' is apparently not right. ;P

  2. Damn. :( :(

@saurik
Contributor
saurik commented Apr 18, 2012

I went ahead and looked at OpenSSH's code to verify that it should be checking for both '\n' and '\r', and in fact that is the correct behavior (you will also note that it calls the variable last_was_cr, as '\r' is apparently the more canonical form).

                /*      
                 * Normal character.  Record whether it was a newline,
                 * and append it to the buffer.
                 */
                last_was_cr = (ch == '\r' || ch == '\n');
                buffer_put_char(bin, ch);
                bytes++;
@saurik saurik added a commit to saurik/mosh that referenced this issue Apr 18, 2012
@saurik saurik As reported by @pimlott in #215: remove literal ~. c371d08
@viric
viric commented Apr 20, 2012

Just an additional note on C-^, C-^ can't be typed on Spanish keyboard layouts, because it's a dead key to make âêîôû. We can type it with ^ + space, but of course that does not work with any ctrl key pressed.

@chneukirchen

Another option would be the telnet escape "^]".

@andersk
Member
andersk commented Apr 21, 2012

FYI, in current mosh, C-^ ^ sends a literal C-^. This is documented in the manpage.

(This is analogous to screen, in which C-a a sends a literal C-a. The reason this is a good idea is so sending the escape character through a stack of n moshes or screens doesn’t take 2^n keystrokes.)

And it’s already the case that C-^ char sends a literal C-^ char, except for a fixed set of chars.

@andersk
Member
andersk commented Apr 21, 2012

viric: in case it helps, C-~ and C-6 are equivalent to C-^.

@viric
viric commented Apr 22, 2012

ah right andersk, C-~ and C-6 work both. Thank you! Then, no concern from my side. But as a preference, I'd go for the openssh escape sequence too. Only because I'm used to it.

@kurtkraut

Also, I'd like to add that the message 'Press Ctrl-^ . to quit' is misleading. The ^ char is not in the same keyboard key for all keyboard layouts. I had to go to IRC and ask how to quit mosh because I was indeed pressing the key for ^ in my keyboard and it wasn't working; Take a look on how the ABNT keyboard layout (default in Brazil) places the ^ char: http://www.verinha.de/teste/lfc03_tec_abnt.jpg

@kmcallister
Contributor

@kurtkraut: We're looking for Ctrl-^, regardless of which keyboard key ^ is on. I believe the problem in your case (as determined on IRC) is that ^ is a dead key used for typing letters like ê.

@The-Compiler
Contributor

Another problem with Ctrl-^ is you can't type it when using rxvt-unicode and an US-layout. rxvt-unicode uses Ctrl+Shift1 for it's weird ISO 14755 text-entry mode (which can only be disabled at compile-time), so you can't type Ctrl+Shift+6

@kmcallister
Contributor

@The-Compiler: You can leave off the Shift. ^6 isn't a character, so rxvt-unicode interprets Ctrl+6 as ^^. We should probably document this better...

@olea
olea commented May 17, 2012

@viric I'm trying those with my ES layout but can get it to work, how do yo do it exactly?

@olea
olea commented May 17, 2012

Damn, now I can see how is it. Forget it. Thanks to @andersk :-)

@andersk
Member
andersk commented Jul 13, 2012

Perhaps what we should do is pop up the overlay bar on Ctrl-^ (or 1 second after that), explaining what Ctrl-^ . and Ctrl-^ ^ do, to help out users who type Ctrl-^ expecting it to do something to the inner application.

@MindTooth

Just wanted to come by to tell that I've using the past two hours almost trying to figure why I couldn't get this to work on my Mountain Lion system :P

Using both iTerm2 and Terminal.app, and a norwegian keyboard, I ended up re-setting iTerm2, and figure out that I need to press only CTRL+6 . And not SHIFT, ^, etc.

One way I do believe helped somewhat, were the CTRL+V (Ref. https://en.wikipedia.org/wiki/Synchronous_idle) feature, to display the escape sequences in raw data. When I found ^^ I had the correct one.

So my conclusion would perhaps be that this combo is a bit hard to get right for everyone without some trial and errors :)

@spitfire

Using Mountain Lion and iTerm using neither CTRL+6, CTRL+SHIFT+6 nor CTRL+1 works...

@andersk
Member
andersk commented Nov 17, 2012

I don’t know why you think C-1 should work. Again, the equivalent sequences are C-^, C-~, and C-6. If none of these work (or even if only some of these work), you should probably report an iTerm bug or an iTerm2 bug.

@spitfire

CTRL-~ ? Great, this is assigned to hiding/showing terminal for me..
Can't mosh use some sane shortcut (or make it configurable on client side)?

@odinho
odinho commented Nov 25, 2012

I also have a dead-key ^ (it needs shift+button+space to write it). CTRL+6 was a total helper. I have indeed used a lot of time on this. Actually saying "CTRL+6" in the wait dialog would help immensely. 6 and ^ is in totally different places on my keyboard, and although a literal C ^ might've worked, it doesn't because ^ is dead here.

@jikuja
jikuja commented Nov 25, 2012

Hello.. I have filed feature request, which is related for ^^ issue with mosh, for mintty. http://code.google.com/p/mintty/issues/detail?id=357 Short version: instead of ^6 for ^^ mintty users need to use ^^.
Please star mintty issue if C0 key combinations are too hard to use or to remember because they aren't compatible with other terminals.

@nhooey
nhooey commented Nov 27, 2012

Can someone merge this change if it's working well enough?

In Mac OS, Ctrl+^ is the default key combo for going to virtual desktop 6. The way SSH quits with "Newline+." is something everyone is familiar with and should be the most familiar among almost all of Mosh's users.

@mdp
mdp commented May 2, 2013

Any progress on getting this merged in, or a plan on how to address the funkiness surround ctrl-^?

This is a pretty handy key inside of vim, which I've had to remap to avoid mosh's use of it. Would be great to move to the OpenSSH standard escape sequence.

@keithw
Member
keithw commented May 2, 2013

I think, honestly, my thinking on this has changed and I would be open to moving to RET ~ . in a future major Mosh version. If somebody wants to prepare a pull request, it would be favorably received.

@keithw keithw added a commit that closed this issue May 17, 2013
@rinne @keithw rinne + keithw mosh-client: Make terminal escape character configurable
Uses environment variable MOSH_ESCAPE_KEY. Defaults to current Ctrl-^
which is somewhat problematic for many non-US keyboards.

Signed-off-by: Timo J. Rinne <tri@iki.fi>

Closes #425. Closes #215.
f960a8b
@keithw keithw closed this in f960a8b May 17, 2013
@deadalnix

Hi all,

I have 2 temrinal locked and telling me i can exit by using ctrl - ^ . I'm not sure what i'm supposed to do, but pressing the control key and the "^" key at the same sure doesn't work.

@keithw I see you made this configurable, however I've been unable to find anyway to configure it - the man pages for instance say nothing. All google search on the subject bring me to that bug report so that's not helpful.

@cgull
Member
cgull commented Jan 9, 2017
  • If you're not using an English keyboard layout, it is sometimes difficult or impossible to generate the initial escape character, and you may have to change it as documented in mosh.1. Try Ctrl-6, though, that may work. It's hard to change this default now because it's so important, though.
  • The full escape sequence is actually Ctrl-^ then ., are you aware of that? When viewed in our documentation, that . unfortunately can be misinterpreted as normal end-of-sentence punctuation or a typo.
@deadalnix

Got it foreign keyboard, ^ is a dead key and it looks like it isn't working.

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