pynexj
pynexj

Reputation: 20798

What's the difference between cursor_up (cuu1) and key_up (kcuu1) in terminfo(5)?

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

Upvotes: 4

Views: 885

Answers (2)

Thomas Dickey
Thomas Dickey

Reputation: 54583

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:

Upvotes: 5

user149341
user149341

Reputation:

cursor_up is the control sequence sent by the host to the terminal to move the cursor up a line.

key_up is the control sequence sent by the terminal to the host when the up arrow key is pressed.

In VT100-based terminals (which includes all sane modern terminal emulators), these sequences are identical. However, some older terminal hardware may have used different sequences in these two roles, so terminfo keeps them separate.

Upvotes: 1

Related Questions