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

alt/meta-backspace is interpreted as esc + backspace #5

Open
lspitzner opened this issue Nov 19, 2017 · 8 comments
Open

alt/meta-backspace is interpreted as esc + backspace #5

lspitzner opened this issue Nov 19, 2017 · 8 comments

Comments

@lspitzner
Copy link

lspitzner commented Nov 19, 2017

I have observed on multiple (but random) times that alt-backspace exits my program without any trace of an error message, instead of it doing what the program is supposed to do on alt-backspace (which is not to halt). Had me confused, but, looking at

specialSupportKeys =
    [ -- special support for ESC
      ("\ESC",EvKey KEsc []), ("\ESC\ESC",EvKey KEsc [MMeta])
    -- Special support for backspace
    , ("\DEL",EvKey KBS []), ("\ESC\DEL",EvKey KBS [MMeta])
    -- Special support for Enter
    , ("\ESC\^J",EvKey KEnter [MMeta]), ("\^J",EvKey KEnter [])
    -- explicit support for tab
    , ("\t", EvKey (KChar '\t') [])
    ]

This makes a good amount of sense - if the input buffer for some reason contains only \ESC (part of a \ESC\DEL) then the input sequence is interpreted as the sequence of \ESC (and \DEL once the next part is read). This depends on where the input is split up due to input-buffering internals, which of course is mildly random.

(A plain Esc is treated by my program to exit cleanly, which explains my initial observation.)

Does this diagnosis make sense so far?

@glguy
Copy link
Contributor

glguy commented Nov 20, 2017

In Terminal.app, The M-BS combination is correctly recognized as EvKey KBS [MMeta]. It will probably help if you specify which application is exhibiting this behavior.

@lspitzner
Copy link
Author

@glguy Perhaps I was unclear. The observed behaviour is random. In like 95% of the input events everything is fine.

What is Terminal.app?

@lspitzner
Copy link
Author

I just tested using the vty-demo executable contained within the package. When i keep alt-backspace pressed, the program exits randomly after, on vague average, 20 input events.

@glguy
Copy link
Contributor

glguy commented Nov 20, 2017

Terminal.app is the default terminal program on macOS. Using vty-demo in this program I get 100% success after a couple minutes of holding down M-BS. Knowing what environment you're testing this in will help with reproducing the problem.

@lspitzner
Copy link
Author

I am running all this on archlinux.

Testing with different terminal emulators gives somewhat differing results:

  • xterm(330)
    detects alt-backspace as EvKey (KChar \136) [] and consequently does not seem to fail at all
  • xfce4-terminal-0.8.6
    ~5% probability to fail
  • LXTerminal-0.3.0
    ~3% probability to fail
  • GNOME Terminal 3.26.1 Using VTE version 0.50.1 +GNUTLS
    ~1% probability to fail (sometimes runs for more than a minute, but i have observed 2 exits)
  • a non-emulator terminal (what software runs that? is it just the kernel? i don't even know..)
    could not reproduce

@lspitzner
Copy link
Author

Oh, and I also see EvKey KBS [MMeta] as the "correct" output. I don't mind the alt-vs-meta swap.

@lspitzner
Copy link
Author

lspitzner commented Nov 20, 2017

I am rather certain that if I modified vty-demo to not exit on <esc> i would be able to observe the separate <esc> and <backspace> events. I have done that test in a different program, but not using a modified vty-demo.

@milesrout
Copy link

milesrout commented Jul 26, 2018

The encoding of <esc> then <backspace> is the same as the encoding of <alt-backspace>. Alt/Meta is encoded as a prefixed . I believe programs usually end up detecting whether it's <Alt-x> vs <Esc>x using a delay: if the ESC and the next key are far enough apart, they're considered separate, otherwise it's an <Alt-x>.

@jtdaugherty jtdaugherty transferred this issue from jtdaugherty/vty Nov 1, 2023
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