Arrow keys type `OA`, `OB`, `OC`, and `OD`
Closed this issue · 3 comments
In this screenshot I've typed search
and pressed the down arrow twice.
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?
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! :-)
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.
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.