Why is terminfo[kcuu1] = '\EOA'?

北慕城南 提交于 2019-12-02 03:30:36

问题


From what I can tell reading terminfo(5), kcuu1 should be the sequence that the terminal sends when the up arrow is pressed. I have never, ever seen that be anything other than ^[[A (speaking now about cat, messed up terminal settings, etc). So, given that the terminals I've used (rxvt, gnome-terminal, iTerm) all default to TERM=xterm, why isn't kcuu1 \E[A?

I see that cuu1 is \E[A, but (from the man page, again), that's the string that I should send to the terminal to move the cursor, not a string the terminal sends to me.

BTW this is with OS X.


回答1:


Arrow and other special keys (terminfo refers to them as "keypad") send different codes depending on whether the terminal is in "application mode" or not. An application that wants to make use of the various k* keys is supposed to output smkx first (and rmkx at the end to restore the old behavior).

You can try Ctrl+V Up in vi (or a similar terminal application) to see that Up does indeed send \EOA there.

See these links for more details:

  • Terminfo smkx and Application Cursor Keys vs Application keypad
  • http://invisible-island.net/xterm/xterm.faq.html#xterm_arrows


来源:https://stackoverflow.com/questions/31641910/why-is-terminfokcuu1-eoa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!