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

Arrow keys don't work in irb #99

Closed
Tyriar opened this issue Jan 27, 2017 · 4 comments
Closed

Arrow keys don't work in irb #99

Tyriar opened this issue Jan 27, 2017 · 4 comments

Comments

@Tyriar
Copy link

Tyriar commented Jan 27, 2017

Steps to reproduce:

  1. Open vscode insiders v1.9.0 (using node-pty@0.6.1 with winpty@0.4.2)
  2. Install ruby (I used this)
  3. Add to settings.json:
"terminal.integrated.shell.windows": "C:\\Ruby23-x64\\bin\\irb.cmd"
  1. Launch terminal ctrl+`
  2. Type something and hit the left arrow key (\e[D) to move the cursor, only the ding sound is made

Downstream issue: microsoft/vscode#14577

@rprichard
Copy link
Owner

I'll look at this next week sometime.

@rprichard
Copy link
Owner

winpty doesn't attempt to set the ENHANCED_KEY flag on keypresses, but apparently it needs to for Ruby to recognize them. I'll try to figure out how to set that flag.

@rprichard
Copy link
Owner

Ruby is using rbreadline.rb to read a command line, which uses the CRT _getch / _kbhit functions. It seems these functions return the scan code bytes, and for certain keys (like functions keys / arrow keys), the byte is preceded by 0xE0 for enhanced and 0x00 otherwise. (The preceding byte might be 0xE1 in some cases too?)

@rprichard
Copy link
Owner

FWIW: I tried entering the alternate terminal mode (DECCKM) without enabling ENABLE_VIRTUAL_TERMINAL_INPUT, and it didn't result in escape sequences used for input. (I expected this result, but I thought I should test it.)

The problem seems confined to the arrow keys and the block of 6 keys (Ins, Del, Home, End, PgUp, PgDn). I'm really only familiar with US keyboards, though, so I'm unsure.

I tested with a full-size US keyboard and noticed that, with the NumLock off, the navigation keys on the keypad do not produce ENHANCED_KEY events (and therefore use a 0x00 getch prefix rather than 0xE0.) Consequently, they don't work with Ruby. I suspect that's a Ruby rbreadline bug. Here's the affected code. (\340 is octal for 0xE0.)

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

2 participants