2 .\" Copyright (c) 1996 Andries Brouwer <aeb@cwi.nl>, Mon Oct 31 22:13:04 1996
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
9 .\" This is combined from many sources.
10 .\" For Linux, the definitive source is of course console.c.
11 .\" About vt100-like escape sequences in general there are
12 .\" the ISO 6429 and ISO 2022 norms, the descriptions of
13 .\" an actual vt100, and the xterm docs (ctlseqs.ms).
14 .\" Substantial portions of this text are derived from a write-up
15 .\" by Eric S. Raymond <esr@thyrsus.com>.
17 .\" Tiny correction, aeb, 961107.
19 .\" 2006-05-27, Several corrections - Thomas E. Dickey
21 .TH CONSOLE_CODES 4 2008-01-01 "Linux" "Linux Programmer's Manual"
23 console_codes \- Linux console escape and control sequences
25 The Linux console implements a large subset of the VT102 and ECMA-48/ISO
26 6429/ANSI X3.64 terminal controls, plus certain private-mode sequences
27 for changing the color palette, character-set mapping, etc.
28 In the tabular descriptions below, the second column gives ECMA-48 or DEC
29 mnemonics (the latter if prefixed with DEC) for the given function.
30 Sequences without a mnemonic are neither ECMA-48 nor VT102.
32 After all the normal output processing has been done, and a
33 stream of characters arrives at the console driver for actual
34 printing, the first thing that happens is a translation from
35 the code used for processing to the code used for printing.
37 If the console is in UTF-8 mode, then the incoming bytes are
38 first assembled into 16-bit Unicode codes.
39 Otherwise each byte is transformed according to the current mapping table
40 (which translates it to a Unicode value).
41 See the \fBCharacter Sets\fP section below for discussion.
43 In the normal case, the Unicode value is converted to a font index,
44 and this is stored in video memory, so that the corresponding glyph
45 (as found in video ROM) appears on the screen.
46 Note that the use of Unicode (and the design of the PC hardware)
47 allows us to use 512 different glyphs simultaneously.
49 If the current Unicode value is a control character, or we are
50 currently processing an escape sequence, the value will treated
52 Instead of being turned into a font index and rendered as
53 a glyph, it may trigger cursor movement or other control functions.
54 See the \fBLinux Console Controls\fP section below for discussion.
56 It is generally not good practice to hard-wire terminal controls into
60 database of terminal capabilities.
61 Rather than emitting console escape sequences by hand, you will almost
62 always want to use a terminfo-aware screen library or utility such as
67 .SS "Linux Console Controls"
68 This section describes all the control characters and escape sequences
69 that invoke special functions (i.e., anything other than writing a
70 glyph at the current cursor location) on the Linux console.
72 .B "Control characters"
74 A character is a control character if (before transformation
75 according to the mapping table) it has one of the 14 codes
76 00 (NUL), 07 (BEL), 08 (BS), 09 (HT), 0a (LF), 0b (VT),
77 0c (FF), 0d (CR), 0e (SO), 0f (SI), 18 (CAN), 1a (SUB),
79 One can set a "display control characters" mode (see below),
80 and allow 07, 09, 0b, 18, 1a, 7f to be displayed as glyphs.
81 On the other hand, in UTF-8 mode all codes 00-1f are regarded
82 as control characters, regardless of any "display control characters"
85 If we have a control character, it is acted upon immediately
86 and then discarded (even in the middle of an escape sequence)
87 and the escape sequence continues with the next character.
88 (However, ESC starts a new escape sequence, possibly aborting a previous
89 unfinished one, and CAN and SUB abort any escape sequence.)
90 The recognized control characters are BEL, BS, HT, LF, VT, FF,
91 CR, SO, SI, CAN, SUB, ESC, DEL, CSI.
92 They do what one would expect:
94 BEL (0x07, \fB^G\fP) beeps;
96 BS (0x08, \fB^H\fP) backspaces one column
97 (but not past the beginning of the line);
99 HT (0x09, \fB^I\fP) goes to the next tab stop or to the end of the line
100 if there is no earlier tab stop;
102 LF (0x0A, \fB^J\fP), VT (0x0B, \fB^K\fP) and
103 FF (0x0C, \fB^L\fP) all give a linefeed,
104 and if LF/NL (new-line mode) is set also a carriage return;
106 CR (0x0D, \fB^M\fP) gives a carriage return;
108 SO (0x0E, \fB^N\fP) activates the G1 character set;
110 SI (0x0F, \fB^O\fP) activates the G0 character set;
112 CAN (0x18, \fB^X\fP) and SUB (0x1A, \fB^Z\fP) interrupt escape sequences;
114 ESC (0x1B, \fB^[\fP) starts an escape sequence;
116 DEL (0x7F) is ignored;
118 CSI (0x9B) is equivalent to ESC [.
120 .B "ESC- but not CSI-sequences"
126 ESC H HTS Set tab stop at current column.
127 ESC M RI Reverse linefeed.
129 DEC private identification. The kernel
130 returns the string ESC [ ? 6 c, claiming
134 Save current state (cursor coordinates,
135 attributes, character sets pointed at by G0, G1).
137 ESC 8 DECRC Restore state most recently saved by ESC 7.
138 ESC [ CSI Control sequence introducer
139 ESC % Start sequence selecting character set
140 ESC % @ \0\0\0Select default (ISO 646 / ISO 8859-1)
141 ESC % G \0\0\0Select UTF-8
142 ESC % 8 \0\0\0Select UTF-8 (obsolete)
143 ESC # 8 DECALN DEC screen alignment test \- fill screen with E's.
144 ESC ( Start sequence defining G0 character set
145 ESC ( B \0\0\0Select default (ISO 8859-1 mapping)
146 ESC ( 0 \0\0\0Select VT100 graphics mapping
147 ESC ( U \0\0\0Select null mapping \- straight to character ROM
148 ESC ( K \0\0\0Select user mapping \- the map that is loaded by
149 \0\0\0the utility \fBmapscrn\fP(8).
150 ESC ) Start sequence defining G1
151 (followed by one of B, 0, U, K, as above).
152 ESC > DECPNM Set numeric keypad mode
153 ESC = DECPAM Set application keypad mode
155 (Should be: Operating system command)
156 ESC ] P \fInrrggbb\fP: set palette, with parameter
157 given in 7 hexadecimal digits after the final P :-(.
158 Here \fIn\fP is the color (0-15), and \fIrrggbb\fP indicates
159 the red/green/blue values (0-255).
160 ESC ] R: reset palette
164 .B "ECMA-48 CSI sequences"
166 CSI (or ESC [) is followed by a sequence of parameters,
167 at most NPAR (16), that are decimal numbers separated by
169 An empty or absent parameter is taken to be 0.
170 The sequence of parameters may be preceded by a single question mark.
172 However, after CSI [ (or ESC [ [) a single character is read
173 and this entire sequence is ignored.
174 (The idea is to ignore an echoed function key.)
176 The action of a CSI sequence is determined by its final character.
179 @ ICH Insert the indicated # of blank characters.
180 A CUU Move cursor up the indicated # of rows.
181 B CUD Move cursor down the indicated # of rows.
182 C CUF Move cursor right the indicated # of columns.
183 D CUB Move cursor left the indicated # of columns.
184 E CNL Move cursor down the indicated # of rows, to column 1.
185 F CPL Move cursor up the indicated # of rows, to column 1.
186 G CHA Move cursor to indicated column in current row.
187 H CUP Move cursor to the indicated row, column (origin at 1,1).
188 J ED Erase display (default: from cursor to end of display).
189 ESC [ 1 J: erase from start to cursor.
190 ESC [ 2 J: erase whole display.
191 K EL Erase line (default: from cursor to end of line).
192 ESC [ 1 K: erase from start of line to cursor.
193 ESC [ 2 K: erase whole line.
194 L IL Insert the indicated # of blank lines.
195 M DL Delete the indicated # of lines.
196 P DCH Delete the indicated # of characters on the current line.
197 X ECH Erase the indicated # of characters on the current line.
198 a HPR Move cursor right the indicated # of columns.
199 c DA Answer ESC [ ? 6 c: "I am a VT102".
200 d VPA Move cursor to the indicated row, current column.
201 e VPR Move cursor down the indicated # of rows.
202 f HVP Move cursor to the indicated row, column.
203 g TBC Without parameter: clear tab stop at the current position.
204 ESC [ 3 g: delete all tab stops.
205 h SM Set Mode (see below).
206 l RM Reset Mode (see below).
207 m SGR Set attributes (see below).
208 n DSR Status report (see below).
209 q DECLL Set keyboard LEDs.
210 ESC [ 0 q: clear all LEDs
211 ESC [ 1 q: set Scroll Lock LED
212 ESC [ 2 q: set Num Lock LED
213 ESC [ 3 q: set Caps Lock LED
214 r DECSTBM Set scrolling region; parameters are top and bottom row.
215 s ? Save cursor location.
216 u ? Restore cursor location.
217 \` HPA Move cursor to indicated column in current row.
220 .B ECMA-48 Set Graphics Rendition
222 The ECMA-48 SGR sequence ESC [ \fIparameters\fP m sets display
224 Several attributes can be set in the same sequence, separated by
226 An empty parameter (between semicolons or string initiator or
227 terminator) is interpreted as a zero.
231 0 reset all attributes to their defaults
233 2 set half-bright (simulated with color on a color display)
235 set underscore (simulated with color on a color display)
236 (the colors used to simulate dim or underline are set
242 reset selected mapping, display control flag,
243 and toggle meta flag (ECMA-48 says "primary font").
246 select null mapping, set display control flag,
247 reset toggle meta flag (ECMA-48 says "first alternate font").
250 select null mapping, set display control flag,
251 set toggle meta flag (ECMA-48 says "second alternate font").
253 causes the high bit of a byte to be toggled
254 before the mapping table translation is done.
256 21 set normal intensity (ECMA-48 says "doubly underlined")
257 22 set normal intensity
261 30 set black foreground
262 31 set red foreground
263 32 set green foreground
264 33 set brown foreground
265 34 set blue foreground
266 35 set magenta foreground
267 36 set cyan foreground
268 37 set white foreground
269 38 set underscore on, set default foreground color
270 39 set underscore off, set default foreground color
271 40 set black background
272 41 set red background
273 42 set green background
274 43 set brown background
275 44 set blue background
276 45 set magenta background
277 46 set cyan background
278 47 set white background
279 49 set default background color
282 .B ECMA-48 Mode Switches
285 DECCRM (default off): Display control chars.
288 DECIM (default off): Set insert mode.
291 LF/NL (default off): Automatically follow echo of LF, VT or FF with CR.
294 .B ECMA-48 Status Report Commands
298 Device status report (DSR): Answer is ESC [ 0 n (Terminal OK).
301 Cursor position report (CPR): Answer is ESC [ \fIy\fP ; \fIx\fP R,
302 where \fIx,y\fP is the cursor location.
305 .B DEC Private Mode (DECSET/DECRST) sequences
308 These are not described in ECMA-48.
309 We list the Set Mode sequences;
310 the Reset Mode sequences are obtained by replacing the final \(aqh\(aq
314 DECCKM (default off): When set, the cursor keys send an ESC O prefix,
318 DECCOLM (default off = 80 columns): 80/132 col mode switch.
319 The driver sources note that this alone does not suffice; some user-mode
322 has to change the hardware registers on the console video card.
325 DECSCNM (default off): Set reverse-video mode.
328 DECOM (default off): When set, cursor addressing is relative to
329 the upper left corner of the scrolling region.
332 DECAWM (default on): Set autowrap on.
333 In this mode, a graphic
334 character emitted after column 80 (or column 132 of DECCOLM is on)
335 forces a wrap to the beginning of the following line first.
338 DECARM (default on): Set keyboard autorepeat on.
341 X10 Mouse Reporting (default off): Set reporting mode to 1 (or reset to
345 DECTECM (default on): Make cursor visible.
348 X11 Mouse Reporting (default off): Set reporting mode to 2 (or reset
349 to 0) \(em see below.
352 .B Linux Console Private CSI Sequences
355 The following sequences are neither ECMA-48 nor native VT102.
356 They are native to the Linux console driver.
357 Colors are in SGR parameters:
358 0 = black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 =
362 ESC [ 1 ; \fIn\fP ] Set color \fIn\fP as the underline color
363 ESC [ 2 ; \fIn\fP ] Set color \fIn\fP as the dim color
364 ESC [ 8 ] Make the current color pair the default attributes.
365 ESC [ 9 ; \fIn\fP ] Set screen blank timeout to \fIn\fP minutes.
366 ESC [ 10 ; \fIn\fP ] Set bell frequency in Hz.
367 ESC [ 11 ; \fIn\fP ] Set bell duration in msec.
368 ESC [ 12 ; \fIn\fP ] Bring specified console to the front.
369 ESC [ 13 ] Unblank the screen.
370 ESC [ 14 ; \fIn\fP ] Set the VESA powerdown interval in minutes.
373 The kernel knows about 4 translations of bytes into console-screen
375 The four tables are: a) Latin1 \-> PC,
376 b) VT100 graphics \-> PC, c) PC \-> PC, d) user-defined.
378 There are two character sets, called G0 and G1, and one of them
379 is the current character set.
381 Typing \fB^N\fP causes G1 to become current,
382 \fB^O\fP causes G0 to become current.
384 These variables G0 and G1 point at a translation table, and can be
386 Initially they point at tables a) and b), respectively.
387 The sequences ESC ( B and ESC ( 0 and ESC ( U and ESC ( K cause G0 to
388 point at translation table a), b), c) and d), respectively.
389 The sequences ESC ) B and ESC ) 0 and ESC ) U and ESC ) K cause G1 to
390 point at translation table a), b), c) and d), respectively.
392 The sequence ESC c causes a terminal reset, which is what you want if the
393 screen is all garbled.
394 The oft-advised "echo ^V^O" will only make G0 current,
395 but there is no guarantee that G0 points at table a).
396 In some distributions there is a program
398 that just does "echo ^[c".
399 If your terminfo entry for the console is correct
400 (and has an entry rs1=\\Ec), then "tput reset" will also work.
402 The user-defined mapping table can be set using
404 The result of the mapping is that if a symbol c is printed, the symbol
405 s = map[c] is sent to the video memory.
406 The bitmap that corresponds to
407 s is found in the character ROM, and can be changed using
410 The mouse tracking facility is intended to return
411 .BR xterm (1)-compatible
412 mouse status reports.
413 Because the console driver has no way to know
414 the device or type of the mouse, these reports are returned in the
415 console input stream only when the virtual terminal driver receives
416 a mouse update ioctl.
417 These ioctls must be generated by a mouse-aware
418 user-mode application such as the
422 The mouse tracking escape sequences generated by
423 \fBxterm\fP(1) encode numeric parameters in a single character as
425 For example, \(aq!\(aq is 1.
426 The screen coordinate system is 1-based.
428 The X10 compatibility mode sends an escape sequence on button press
429 encoding the location and the mouse button pressed.
430 It is enabled by sending ESC [ ? 9 h and disabled with ESC [ ? 9 l.
431 On button press, \fBxterm\fP(1) sends
432 ESC [ M \fIbxy\fP (6 characters).
433 Here \fIb\fP is button\-1,
434 and \fIx\fP and \fIy\fP are the x and y coordinates of the mouse
435 when the button was pressed.
436 This is the same code the kernel also produces.
438 Normal tracking mode (not implemented in Linux 2.0.24) sends an escape
439 sequence on both button press and release.
440 Modifier information is also sent.
441 It is enabled by sending ESC [ ? 1000 h and disabled with
443 On button press or release, \fBxterm\fP(1) sends ESC [ M
445 The low two bits of \fIb\fP encode button information:
446 0=MB1 pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release.
447 The upper bits encode what modifiers were down when the button was
448 pressed and are added together: 4=Shift, 8=Meta, 16=Control.
450 \fIy\fP are the x and y coordinates of the mouse event.
451 The upper left corner is (1,1).
452 .SS "Comparisons With Other Terminals"
453 Many different terminal types are described, like the Linux console,
454 as being "VT100-compatible".
455 Here we discuss differences between the
456 Linux console and the two most important others, the DEC VT102 and
460 .B Control-character handling
462 The VT102 also recognized the following control characters:
464 NUL (0x00) was ignored;
466 ENQ (0x05) triggered an answerback message;
468 DC1 (0x11, \fB^Q\fP, XON) resumed transmission;
470 DC3 (0x13, \fB^S\fP, XOFF) caused VT100 to ignore (and stop transmitting)
471 all codes except XOFF and XON.
473 VT100-like DC1/DC3 processing may be enabled by the tty driver.
477 program (in VT100 mode) recognizes the control characters
478 BEL, BS, HT, LF, VT, FF, CR, SO, SI, ESC.
483 VT100 console sequences not implemented on the Linux console:
486 ESC N SS2 Single shift 2. (Select G2 character set for the next
488 ESC O SS3 Single shift 3. (Select G3 character set for the next
490 ESC P DCS Device control string (ended by ESC \\)
491 ESC X SOS Start of string.
492 ESC ^ PM Privacy message (ended by ESC \\)
493 ESC \\ ST String terminator
494 ESC * ... Designate G2 character set
495 ESC + ... Designate G3 character set
500 (in VT100 mode) recognizes ESC c, ESC # 8, ESC >, ESC =,
501 ESC D, ESC E, ESC H, ESC M, ESC N, ESC O, ESC P ... ESC \\,
502 ESC Z (it answers ESC [ ? 1 ; 2 c, "I am a VT100 with
503 advanced video option")
504 and ESC ^ ... ESC \\ with the same meanings as indicated above.
505 It accepts ESC (, ESC ), ESC *, ESC + followed by 0, A, B for
506 the DEC special character and line drawing set, UK, and US-ASCII,
509 The user can configure \fBxterm\fP(1) to respond to VT220-specific
510 control sequences, and it will identify itself as a VT52, VT100, and
511 up depending on the way it is configured and initialized.
513 It accepts ESC ] (OSC) for the setting of certain resources.
514 In addition to the ECMA-48 string terminator (ST),
515 \fBxterm\fP(1) accepts a BEL to terminate an OSC string.
516 These are a few of the OSC control sequences recognized by \fBxterm\fP(1):
519 ESC ] 0 ; \fItxt\fP ST Set icon name and window title to \fItxt\fP.
520 ESC ] 1 ; \fItxt\fP ST Set icon name to \fItxt\fP.
521 ESC ] 2 ; \fItxt\fP ST Set window title to \fItxt\fP.
522 ESC ] 4 ; \fInum\fP; \fItxt\fP ST Set ANSI color \fInum\fP to \fItxt\fP.
523 ESC ] 10 ; \fItxt\fP ST Set dynamic text color to \fItxt\fP.
524 ESC ] 4 6 ; \fIname\fP ST Change log file to \fIname\fP (normally disabled
525 by a compile-time option)
526 ESC ] 5 0 ; \fIfn\fP ST Set font to \fIfn\fP.
529 It recognizes the following with slightly modified meaning
530 (saving more state, behaving closer to VT100/VT220):
533 ESC 7 DECSC Save cursor
534 ESC 8 DECRC Restore cursor
540 ESC F Cursor to lower left corner of screen (if enabled by
541 \fBxterm\fP(1)'s \fBhpLowerleftBugCompat\fP resource)
542 ESC l Memory lock (per HP terminals).
543 Locks memory above the cursor.
544 ESC m Memory unlock (per HP terminals).
545 ESC n LS2 Invoke the G2 character set.
546 ESC o LS3 Invoke the G3 character set.
547 ESC | LS3R Invoke the G3 character set as GR.
548 ESC } LS2R Invoke the G2 character set as GR.
549 ESC ~ LS1R Invoke the G1 character set as GR.
552 It also recognizes ESC % and provides a more complete UTF-8
553 implementation than Linux console.
558 Old versions of \fBxterm\fP(1), for example, from X11R5,
559 interpret the blink SGR as a bold SGR.
560 Later versions which implemented ANSI colors, for example,
561 XFree86 3.1.2A in 1995, improved this by allowing
562 the blink attribute to be displayed as a color.
563 Modern versions of xterm implement blink SGR as blinking text
564 and still allow colored text as an alternate rendering of SGRs.
565 Stock X11R6 versions did not recognize the color-setting SGRs until
566 the X11R6.8 release, which incorporated XFree86 xterm.
567 All ECMA-48 CSI sequences recognized by Linux are also recognized by
569 however \fBxterm\fP(1) implements several ECMA-48 and DEC control sequences
570 not recognized by Linux.
573 program recognizes all of the DEC Private Mode sequences listed
574 above, but none of the Linux private-mode sequences.
575 For discussion of \fBxterm\fP(1)'s
576 own private-mode sequences, refer to the
577 \fIXterm Control Sequences\fP
582 available with the X distribution.
583 That document, though terse, is much longer than this manual page.
584 For a chronological overview,
587 http://invisible-island.net/xterm/xterm.log.html
590 details changes to xterm.
592 The \fIvttest\fP program
595 http://invisible-island.net/vttest/
598 demonstrates many of these control sequences.
599 The \fBxterm\fP(1) source distribution also contains sample
600 scripts which exercise other features.
602 ESC 8 (DECRC) is not able to restore the character set changed with
605 In 2.0.23, CSI is broken, and NUL is not ignored inside
608 Some older kernel versions (after 2.0) interpret 8-bit control
610 These "C1 controls" use codes between 128 and 159 to replace
611 ESC [, ESC ] and similar two-byte control sequence initiators.
612 There are fragments of that in modern kernels (either overlooked or
613 broken by changes to support UTF-8),
614 but the implementation is incomplete and should be regarded
617 Linux "private mode" sequences do not follow the rules in ECMA-48
618 for private mode control sequences.
619 In particular, those ending with ] do not use a standard terminating
621 The OSC (set palette) sequence is a greater problem,
622 since \fBxterm\fP(1) may interpret this as a control sequence
623 which requires a string terminator (ST).
624 Unlike the \fBsetterm\fP(1) sequences which will be ignored (since
625 they are invalid control sequences), the palette sequence will make
626 \fBxterm\fP(1) appear to hang (though pressing the return-key
628 To accommodate applications which have been hardcoded to use Linux
630 set the \fBxterm\fP(1) resource \fBbrokenLinuxOSC\fP to true.
632 An older version of this document implied that Linux recognizes the
633 ECMA-48 control sequence for invisible text.
637 .BR console_ioctl (4),