AlecAivazis / survey

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

Missing support for DECCKM cursor keys #341

Closed wez closed 2 years ago

wez commented 3 years ago

What operating system and terminal are you using?

https://github.com/cli/cli/issues/3071 has more context, but:

What did you expect to see?

The cursor keys should navigate to select one of the login options

What did you see instead?

could not prompt: Unexpected Escape Sequence: ['\x1b' 'O']

Analysis

Due to https://github.com/PowerShell/PowerShell/issues/12268 powershell enables DECCKM which changes the cursor key encoding from CSI A..D to SS3 A..D instead. SS3 is encoded as ESC O in 7-bit encoding.

It is technically a bug that powershell leaves the cursor keys in that mode. However, it should be pretty simple to support this encoding here in survey:

https://github.com/AlecAivazis/survey/blob/dbdb3e56a5e332b0478e0a8e8522e53a49fb7dcd/terminal/runereader_posix.go#L79-L81

by allowing either [ or O

wez commented 3 years ago

Another option here is for survey to explicitly disable DECCKM mode on startup so that they key behave the way it wants!

Sending CSI ? 1 l will reset that mode to produce ANSI encoded cursor keys.

AlecAivazis commented 3 years ago

Hey @wez - thanks for reporting this! I'm not sure I will have the time to add support for DECCKM but if you wanted to take a shot, i would love to support you however I can. Feel free to reach out on the gophers slack :)

That being said, if you could find the time to disable the mode, it would be much appreciated!

wez commented 3 years ago

I don't have time to do that, however: https://github.com/PowerShell/PowerShell/issues/12268#issuecomment-819924104 claims to have resolved the underlying issue in powershell, so it may be OK just to wait for that to become broadly available and do nothing special here.

coryb commented 2 years ago

We had a user with this issue today on macOS, it seems the fish shell enables the DECCKM mode by default as well. This seems like the related fish issue: https://github.com/fish-shell/fish-shell/issues/2139. That issue lead me to the useful tput rmkx command which resets the terminal back to a mode that works with Survey. To reproduce this error with Survey you can use tput smkx.

brantb commented 2 years ago

PowerShell 7.2.0-preview.8 no longer exhibits this issue.