简体   繁体   中英

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

In terminfo(5):

   Variable String               Capname    TCapCode  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:

[STEP 102] # tput cuu1 | hd -C
00000000  1b 5b 41                                          |.[A|
00000003
[STEP 103] # tput kcuu1 | hd -C
00000000  1b 5b 41                                          |.[A|
00000003
[STEP 104] #

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 Escape O 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM