AlecAivazis / survey

A golang library for building interactive and accessible prompts with full support for windows and posix terminals.
MIT License
4.08k stars 350 forks source link

Arrow keys don't work when terminal is in keypad-transmit mode #228

Closed romkatv closed 3 years ago

romkatv commented 5 years ago

To reproduce:

  1. Start a clean Bash session.
bash --norc
  1. Switch terminal to keypad-transmit mode (smkx).
echo $'\e[?1h\E='
  1. Run countrylist example.
go run examples/countrylist.go
  1. Press down arrow key.

Expected: Country selection moves down.

Actual: Country selection doesn't move and an error message is printed:

Unexpected Escape Sequence: ['\x1b' 'O']

The reason is that in keypad-transmit mode down arrow key sends ^[OB instead of ^[[B that survey expects.

More info:

AlecAivazis commented 5 years ago

Thanks for reporting this @romkatv! I am a bit swamped atm so I don't think I will have time to address this quickly but if you wanted to take a stab at fixing it, I'd be happy to review a PR!

romkatv commented 5 years ago

Oh, this is not urgent at all. In fact, feel free to never fix this issue or close it. I've only opened it to let you know there is likely a bug. I should've mentioned this in the description.

adonovan commented 3 years ago

My team is seeing this from time to time in our survey-based application. I'm not sure what I did to put my terminal in keypad-transmit mode, but thanks for the explanation and for the echo command, which allows me to reproduce the problem. The problem was quite persistent across runs until I reset the terminal, and I expect few of our users will understand the rather obscure cause and remedy, so please do regard this an open problem. I'd be happy to contribute a fix if you could advise on the right approach, e.g.

More useful explanation here: https://github.com/fish-shell/fish-shell/issues/2139#issuecomment-117548585

AlecAivazis commented 3 years ago

Hey @adonovan - sorry to hear its affecting your users. Do you mind giving #367 a test and seeing if it works? I'm struggling to find the time to pull it down myself

mislav commented 3 years ago

@AlecAivazis At GitHub CLI we're also fairly interested in seeing this fixed. The proposed fix in the linked PR looks good to me code-wise, but I haven't yet tested in across different platforms. I could do that soon and report back.

If you are struggling to find time these days and if you are open to giving us maintainer bits so we could ship a fix for this and tag a patch release, feel free to reach out to me! 🙇

adonovan commented 3 years ago

I confirm that the PR fixes the issue seen by me and @mislav; see my comment at https://github.com/AlecAivazis/survey/pull/367/files#r705362421. Thanks!