In terminfo(5):
Variable String | Capname | TCap Code | Description |
---|---|---|---|
cursor_up | cuu1 | up | up one line |
key_up | kcuu1 | ku | up-arrow key |
I tried with tput
and they produce the same output:
$ tput cuu1 | hexdump -C
00000000 1b 5b 41 |.[A|
00000003
$ tput kcuu1 | hexdump -C
00000000 1b 5b 41 |.[A|
00000003
In a terminfo description, names beginning with k
denote keys, while other names are used for non-key capabilities. For most keys, there is no readily apparent relationship between the keys and an existing escape sequence, but cursor-keys are the exception.
Whether they are the same or not depends upon the terminal description. For TERM=linux
, they happen to be the same, however a terminal description could be written for the Linux console where they are not.
The distinction is whether the terminal is initialized into application mode or left in the (default/power-up) normal mode. In application mode, the cursor keys would send EscapeO
as a prefix rather than Escape[
.
A little over half (54%) of the terminal descriptions in the ncurses terminal database use application mode, meaning that cuu1
is more often than not different from kcuu1
.
There's another quirk to be aware of: for other cursor movement, such as cud1
, the terminal description may say \n
, while the key for cursor-down would not send that character (see iTerm
for example).
Further reading: