rtfm / Xterm / Escape Sequences
University of California, Berkeley
X Consortium (1994)
XFree86 Project (1996-1999)
This came out of nroff in a mess - this is a best guess reconstruction:
Key Numeric Application Terminfo Termcap Space SP SS3 SP - - Tab TAB SS3 I - - Enter CR SS3 M kent @8 PF1 SS3 P SS3 P kf1 k1 PF2 SS3 Q SS3 Q kf2 k2 PF3 SS3 R SS3 R kf3 k3 PF4 SS3 S SS3 S kf4 k4 * (multiply)* SS3 j - - + (add)+ SS3 k - - , (comma), SS3 l - - - (minus)- SS3 m - - / (divide)/ SS3 o - - 0 (Insert)0 CSI 2 ~ - - 1 (End) 1 CSI 4 ~ kc1 K4 2 (DownArrow)2 CSI B - - 3 (PageDown)3 CSI 5 ~ kc3 K5 4 (LeftArrow)4 CSI D - - 5 (Begin)5 CSI E kb2 K2 6 (RightArrow)6 CSI C - - 7 (Home)7 CSI 1 ~ ka1 K1 8 (UpArrow)8 CSI A - - 9 (PageUp)9 CSI 5 ~ ka3 K3 = (equal)= SS3 X - -
They also provide 12 function keys, as well as a few other special-purpose keys.
Key Escape Sequence F1 SS3 P F2 SS3 Q F3 SS3 R F4 SS3 S F5 CSI 1 5 ~ F6 CSI 1 7 ~ F7 CSI 1 8 ~ F8 CSI 1 9 ~ F9 CSI 2 0 ~ F10 CSI 2 1 ~ F11 CSI 2 3 ~ F12 CSI 2 4 ~
Older versions of xterm implement different escape sequences for F1 through F4. These can be activated by setting the oldXtermFKeys resource. However, since they do not correspond to any hardware termi- nal, they have been deprecated. (The DEC VT220 reserves F1 through F5 for local functions such as Setup).
Key Escape Sequence F1 CSI 1 1 ~ F2 CSI 1 2 ~ F3 CSI 1 3 ~ F4 CSI 1 4 ~
In normal mode, i.e., a Sun/PC keyboard when the sunKeyboard resource is false, xterm recognizes function key modifiers which are parameters appended before the final character of the control sequence.
Code Modifiers 2 Shift 3 Alt 4 Shift + Alt 5 Control 6 Shift + Control 7 Alt + Control 8 Shift + Alt + Control
For example, shift-F5 would be sent as CSI 1 5 ; 2 ~
VT220-Style Function Keys
However, xterm is most useful as a DEC VT102 or VT220 emulator. Set the sunKeyboard resource to true to force a Sun/PC keyboard to act like a VT220 keyboard.
The VT102/VT220 application keypad transmits unique escape sequences in application mode, which are distinct from the cursor and scrolling key- pad:
Key Numeric Application _ Space Space SS3 SP Tab Tab SS3 I Enter CR SS3 M PF1 SS3 P SS3 P PF2 SS3 Q SS3 Q PF3 SS3 R SS3 R PF4 SS3 S SS3 S * (multiply)* SS3 j + (add)+ SS3 k , (comma), SS3 l - (minus)- SS3 m / (divide)/ SS3 o 0 0 SS3 p 1 1 SS3 q 2 2 SS3 r 3 3 SS3 s 4 4 SS3 t 5 5 SS3 u 6 6 SS3 v 7 7 SS3 w 8 8 SS3 x 9 9 SS3 y = (equal)= SS3 X
The VT220 provides 8 additional function keys. With a Sun/PC keyboard, access these keys by Control/F1 for F13, etc.
Key Escape Sequence _ F13 CSI 2 5 ~ F14 CSI 2 6 ~ F15 CSI 2 8 ~ F16 CSI 2 9 ~ F17 CSI 3 1 ~ F18 CSI 3 2 ~ F19 CSI 3 3 ~ F20 CSI 3 4 ~
VT52-Style Function Keys
A VT52 does not have function keys, but it does have a numeric keypad and cursor keys. They differ from the other emulations by the prefix. Also, the cursor keys do not change:
Key Normal/Application Up ESC A Down ESC B Right ESC C Left ESC D
The keypad is similar:
Key Numeric Application _ Space Space ESC ? SP Tab Tab ESC ? I Enter CR ESC ? M PF1 ESC P ESC P PF2 ESC Q ESC Q PF3 ESC R ESC R PF4 ESC S ESC S * (multiply)* ESC ? j + (add)+ ESC ? k , (comma), ESC ? l - (minus)- ESC ? m / (divide)/ ESC ? o 0 0 ESC ? p 1 1 ESC ? q 2 2 ESC ? r 3 3 ESC ? s 4 4 ESC ? t 5 5 ESC ? u 6 6 ESC ? v 7 7 ESC ? w 8 8 ESC ? x 9 9 ESC ? y = (equal)= ESC ? X
Sun-Style Function Keys
The xterm program provides support for Sun keyboards more directly, by a menu toggle that causes it to send Sun-style function key codes rather than VT220. Note, however, that the sun and vt100 emulations are not really compatible. For example, their wrap-margin behavior differs. Only function keys are altered; keypad and cursor keys are the same. The emulation responds identically. See the xterm-sun terminfo entry for details.
HP-Style Function Keys
Similarly, xterm can be compiled to support HP keyboards. See the xterm-hp terminfo entry for details.
The VT widget can be set to send the mouse position and other informa-
tion on button presses. These modes are typically used by editors and
other full-screen applications that want to make use of the mouse.
There are six mutually exclusive modes. One is DEC Locator mode, enabled by the DECELR CSI Ps ; Ps 'z control sequence, and is not described here. The remaining five modes are each enabled (or disabled) by a different parameter in DECSET CSI ? Pm h or DECRST CSI ? Pm l con- trol sequence.
Manifest constants for the parameter values are defined in xcharmouse.h as follows:
The motion reporting modes are strictly xterm extensions, and are not part of any standard, though they are analogous to the DEC VT200 DECELR locator reports.
Parameters (such as pointer position and button number) for all mouse
tracking escape sequences generated by xterm encode numeric parameters
in a single character as value+32. For example, ! specifies the value
1. The upper left character position on the terminal is denoted as 1,1.
X10 compatibility mode sends an escape sequence only on button press,
encoding the location and the mouse button pressed. It is enabled by
specifying parameter 9 to DECSET. On button press, xterm sends CSI M
CbCxCy (6 characters). Cb is button-1. Cx and Cy are the x and y coor-
dinates of the mouse when the button was pressed.
Normal tracking mode sends an escape sequence on both button press and
release. Modifier key (shift, ctrl, meta) information is also sent. It
is enabled by specifying parameter 1000 to DECSET. On button press or
release, xterm sends CSI M CbCxCy. The low two bits of Cb encode button
information: 0=MB1 pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release.
The next three bits encode the modifiers which were down when the button
was pressed and are added together: 4=Shift, 8=Meta, 16=Control. Note
however that the shift and control bits are normally unavailable because
xterm uses the control modifier with mouse for popup menus, and the
shift modifier is used in the default translations for button events.
The Meta modifier recognized by xterm is the mod1 mask, and is not nec-
essarily the "Meta" key (see xmodmap). Cx and Cy are the x and y coor-
dinates of the mouse event, encoded as in X10 mode.
Wheel mice may return buttons 4 and 5. Those buttons are represented by
adding 64 to the event code.
Mouse hilite tracking notifies a program of a button press, receives a
range of lines from the program, highlights the region covered by the
mouse within that range until button release, and then sends the program
the release coordinates. It is enabled by specifying parameter 1001 to
DECSET. Highlighting is performed only for button 1, though other but-
ton events can be received. Warning: use of this mode requires a coop-
erating program or it will hang xterm. On button press, the same infor-
mation as for normal tracking is generated; xterm then waits for the
program to send mouse tracking information. All X events are ignored
until the proper escape sequence is received from the pty: CSI Ps ; Ps ;
Ps ; Ps ; Ps T . The parameters are func, startx, starty, firstrow, and
lastrow. func is non-zero to initiate hilite tracking and zero to
abort. startx and starty give the starting x and y location for the
highlighted region. The ending location tracks the mouse, but will
never be above row firstrow and will always be above row lastrow. (The
top of the screen is row 1.) When the button is released, xterm reports
the ending position one of two ways: if the start and end coordinates
are valid text locations: CSI t CxCy. If either coordinate is past the
end of the line: CSI T CxCyCxCyCxCy. The parameters are startx, starty,
endx, endy, mousex, and mousey. startx, starty, endx, and endy give the
starting and ending character positions of the region. mousex and
mousey give the location of the mouse at button up, which may not be
over a character.
Button-event tracking is essentially the same as normal tracking, but
xterm also reports button-motion events. Motion events are reported
only if the mouse pointer has moved to a different character cell. It
is enabled by specifying parameter 1002 to DECSET. On button press or
release, xterm sends the same codes used by normal tracking mode. On
button-motion events, xterm adds 32 to the event code (the third charac-
ter, Cb). The other bits of the event code specify button and modifier
keys as in normal mode. For example, motion into cell x,y with button 1
down is reported as CSI M @ CxCy. ( @ = 32 + 0 (button 1) + 32 (motion
indicator) ). Similarly, motion with button 3 down is reported as CSI M
B CxCy. ( B = 32 + 2 (button 3) + 32 (motion indicator) ).
Any-event mode is the same as button-event mode, except that all motion
events are reported instead of just those that enter a new character
cell. It is enabled by specifying 1003 to DECSET.
Tektronix 4014 Mode
Most of these sequences are standard Tektronix 4014 control sequences. Graph mode supports the 12-bit addressing of the Tektronix 4014. The major features missing are the write-through and defocused modes. This document does not describe the commands used in the various Tektronix plotting modes but does describe the commands to switch modes.
BEL Bell (Ctrl-G) BS Backspace (Ctrl-H) TAB Horizontal Tab (Ctrl-I) LF Line Feed or New Line (Ctrl-J) VT Cursor up (Ctrl-K) FF Form Feed or New Page (Ctrl-L) CR Carriage Return (Ctrl-M) ESC ETX Switch to VT100 Mode (ESC Ctrl-C) ESC ENQ Return Terminal Status (ESC Ctrl-E) ESC FF PAGE (Clear Screen) (ESC Ctrl-L) ESC SO Begin 4015 APL mode (ignored by xterm) (ESC Ctrl-N) ESC SI End 4015 APL mode (ignored by xterm) (ESC Ctrl-O) ESC ETB COPY (Save Tektronix Codes to file COPYyyyy-mm- dd.hh:mm:ss) (ESC Ctrl-W) ESC CAN Bypass Condition (ESC Ctrl-X) ESC SUB GIN mode (ESC Ctrl-Z) ESC FS Special Point Plot Mode (ESC Ctrl-\) ESC 8 Select Large Character Set ESC 9 Select #2 Character Set ESC : Select #3 Character Set ESC ; Select Small Character Set OSC Ps ; Pt BEL Set Text Parameters of VT window Ps = 0 -> Change Icon Name and Window Title to Pt Ps = 1 -> Change Icon Name to Pt Ps = 2 -> Change Window Title to Pt Ps = 4 6 -> Change Log File to Pt (normally disabled by a compile-time option) ESC ` Normal Z Axis and Normal (solid) Vectors ESC a Normal Z Axis and Dotted Line Vectors ESC b Normal Z Axis and Dot-Dashed Vectors ESC c Normal Z Axis and Short-Dashed Vectors ESC d Normal Z Axis and Long-Dashed Vectors ESC h Defocused Z Axis and Normal (solid) Vectors ESC i Defocused Z Axis and Dotted Line Vectors ESC j Defocused Z Axis and Dot-Dashed Vectors ESC k Defocused Z Axis and Short-Dashed Vectors ESC l Defocused Z Axis and Long-Dashed Vectors ESC p Write-Thru Mode and Normal (solid) Vectors ESC q Write-Thru Mode and Dotted Line Vectors ESC r Write-Thru Mode and Dot-Dashed Vectors ESC s Write-Thru Mode and Short-Dashed Vectors ESC t Write-Thru Mode and Long-Dashed Vectors FS Point Plot Mode (Ctrl-\) GS Graph Mode (Ctrl-]) RS Incremental Plot Mode (Ctrl-^) US Alpha Mode (Ctrl-_)
Parameters for cursor movement are at the end of the ESC Y escape
sequence. Each ordinate is encoded in a single character as value+32.
For example, ! is 1. The screen coodinate system is 0-based.
ESC A Cursor up. ESC B Cursor down. ESC C Cursor right. ESC D Cursor left. ESC F Enter graphics mode. ESC G Exit graphics mode. ESC H Move the cursor to the home position. ESC I Reverse line feed. ESC J Erase from the cursor to the end of the screen. ESC K Erase from the cursor to the end of the line. ESC Y Ps Ps Move the cursor to given row and column. ESC Z Identify -> ESC / Z (``I am a VT52.'') ESC = Enter alternate keypad mode. ESC > Exit alternate keypad mode. ESC < Exit VT52 mode (Enter VT100 mode).