elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.67k stars 299 forks source link

Alt+Arrow keys seems not to work in Windows Terminal Preview (nor VSCode integrated terminal) #912

Open Xjs opened 4 years ago

Xjs commented 4 years ago

I tried setting shortcuts to Alt-Arrowkeys and nothing seems to happen. I use the Windows Terminal Preview (https://github.com/microsoft/terminal) and the VS Code integrated terminal. I'm not quite sure how we could debug this yet, but I'm a Go developer and I'm happy to debug on my own if you could give me some pointers as to where to look :)

krader1961 commented 4 years ago

@Xjs, What do you mean by "setting shortcuts to Alt-Arrowkeys"? Do you mean creating a key binding such as

edit:insert:binding[Alt-Left] = { echo "WTF" >/dev/tty }

in your ~/.elvish/rc.elv?

What Elvish version were you using? Which MS Windows version? Which version of that third-party "terminal" app?

More importantly, I can't figure out if VS Code is even relevant. You linked to a third-party terminal emulator. Does the problem manifest itself if you run elvish inside that terminal emulator but outside of VS Code?

Xjs commented 4 years ago

@krader1961 thanks for your reply. I'll try to clarify.

I have the following bindings configured in my ~.elvish\rc.elv:

edit:insert:binding[Alt-Left] = $edit:move-dot-left-small-word~
edit:insert:binding[Alt-Right] = $edit:move-dot-right-small-word~

I can reproduce the issue with elvish v0.14.0-143-g5ec11cfe (built from 5ec11cfe2bf91b8b385cd995527e8935ff7180c5 just now).

The issue occurs both in the Windows Terminal and VS Code's Integrated Terminal (which AIUI are two distinct terminal emulators but it could be that they use similar APIs, I don't know a lot about this).

I can reproduce it using the Windows Terminal from the Microsoft store, apparently the version number is 1.3.2651.0.

I can reproduce it as well using VS Code's integrated terminal in VS Code 1.50.0-insider (0580328b).

My Windows version is Windows 10 Pro Insider Preview 2004, build 20221.1000.

All those version numbers are very volatile and it never worked with any version I used ;)

FTR: In the legacy Windows terminal (Conhost.exe) the alt-arrowkey bindings do work. In the two terminals I use, both Ctrl-Arrow and Ctrl-Alt-Arrow work and can be distinguished.

krader1961 commented 4 years ago

Dealing with all the minutiae of legacy terminal emulations is hard. :smile: The core issue is there are multiple, wildly used, terminal emulations that provide a different answer when pressing Alt-arrow-key. I tested Terminal.app and iTerm.app on macOS, and the Msys2 terminal and the command.exe terminal on Windows. Pressing Alt-Left produced one of the following sequences depending on the terminal:

1) \033[B (Terminal on macOS) 2) \033[1;9D (iTerm on macOS) 3) \033[1;3D (Windows)

It seems likely that the "VS Code integrated terminal" emits something other than the sequence I observed on Windows (item three above). On UNIX platforms I run something like od -tx1z to see what sequence a particular key sends. Not sure what to propose as an equivalent inside the VS Code integrated terminal. But it seems likely that Elvish might need some tweaks to recognize multiple sequences that map to each Alt-arrow-key.