garybernhardt / selecta

A fuzzy text selector for files and anything else you need to select. Use it from vim, from the command line, or anywhere you can run a shell command.
MIT License
1.34k stars 81 forks source link

Arrow keys type `OA`, `OB`, `OC`, and `OD` #76

Closed jamesgecko closed 9 years ago

jamesgecko commented 9 years ago

In this screenshot I've typed search and pressed the down arrow twice. screenshot 2015-02-03 16 21 59

Using OS X 10.10.2. Happens in both iTerm 2.0.0.20141103 (terminal type is xterm-256color) and Terminal 2.5.1 (343.6) (tried with terminal types xterm, xterm-256color, and rxvt. ansi changes the charcters to [A, [B, [C, and [D).

Is my terminal configured wrong?

jamesgecko commented 9 years ago

Oh, wait. I just saw #48. I noticed esc didn't work anymore and thought that meant that arrow key support was in. Never mind! :-)

garybernhardt commented 9 years ago

We saw this once when arrow key support was added (then quickly removed). I never managed to figure out how to get the OA/OB/etc. codes instead of the normal escape codes.

This made me give it another try, and I found it. There are two cursor modes: "cursor" cursor mode, which sends the usual codes, like [A, and "application" cursor mode, which sends OA etc. The evil one, "application" cursor mode, is enabled by writing ESC + "[?1h" to the terminal. Apparently, something is printing those bytes at some point after your shell starts, putting your terminal into the evil mode. Terminals.

mgedmin commented 9 years ago

The standard terminfo init string tends to enable application keypad mode. Any ncurses-using app will emit the init string during initialization. This mode is turned off via another escape sequence, which is part of the standard finalization string, emitted by ncurses apps when they exit. Well-behaved ncurses apps also restore terminal modes when they are backgrounded or when they shell out to an interactive shell session.