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 2011-09-15 "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 ESC [ 3 J: erase whole display including scroll-back
192 buffer (since Linux 3.0).
193 .\" ESC [ 3 J: commit f8df13e0a901fe55631fed66562369b4dba40f8b
194 K EL Erase line (default: from cursor to end of line).
195 ESC [ 1 K: erase from start of line to cursor.
196 ESC [ 2 K: erase whole line.
197 L IL Insert the indicated # of blank lines.
198 M DL Delete the indicated # of lines.
199 P DCH Delete the indicated # of characters on the current line.
200 X ECH Erase the indicated # of characters on the current line.
201 a HPR Move cursor right the indicated # of columns.
202 c DA Answer ESC [ ? 6 c: "I am a VT102".
203 d VPA Move cursor to the indicated row, current column.
204 e VPR Move cursor down the indicated # of rows.
205 f HVP Move cursor to the indicated row, column.
206 g TBC Without parameter: clear tab stop at the current position.
207 ESC [ 3 g: delete all tab stops.
208 h SM Set Mode (see below).
209 l RM Reset Mode (see below).
210 m SGR Set attributes (see below).
211 n DSR Status report (see below).
212 q DECLL Set keyboard LEDs.
213 ESC [ 0 q: clear all LEDs
214 ESC [ 1 q: set Scroll Lock LED
215 ESC [ 2 q: set Num Lock LED
216 ESC [ 3 q: set Caps Lock LED
217 r DECSTBM Set scrolling region; parameters are top and bottom row.
218 s ? Save cursor location.
219 u ? Restore cursor location.
220 \` HPA Move cursor to indicated column in current row.
223 .B ECMA-48 Set Graphics Rendition
225 The ECMA-48 SGR sequence ESC [ \fIparameters\fP m sets display
227 Several attributes can be set in the same sequence, separated by
229 An empty parameter (between semicolons or string initiator or
230 terminator) is interpreted as a zero.
234 0 reset all attributes to their defaults
236 2 set half-bright (simulated with color on a color display)
238 set underscore (simulated with color on a color display)
239 (the colors used to simulate dim or underline are set
245 reset selected mapping, display control flag,
246 and toggle meta flag (ECMA-48 says "primary font").
249 select null mapping, set display control flag,
250 reset toggle meta flag (ECMA-48 says "first alternate font").
253 select null mapping, set display control flag,
254 set toggle meta flag (ECMA-48 says "second alternate font").
256 causes the high bit of a byte to be toggled
257 before the mapping table translation is done.
259 21 set normal intensity (ECMA-48 says "doubly underlined")
260 22 set normal intensity
264 30 set black foreground
265 31 set red foreground
266 32 set green foreground
267 33 set brown foreground
268 34 set blue foreground
269 35 set magenta foreground
270 36 set cyan foreground
271 37 set white foreground
272 38 set underscore on, set default foreground color
273 39 set underscore off, set default foreground color
274 40 set black background
275 41 set red background
276 42 set green background
277 43 set brown background
278 44 set blue background
279 45 set magenta background
280 46 set cyan background
281 47 set white background
282 49 set default background color
285 .B ECMA-48 Mode Switches
288 DECCRM (default off): Display control chars.
291 DECIM (default off): Set insert mode.
294 LF/NL (default off): Automatically follow echo of LF, VT or FF with CR.
297 .B ECMA-48 Status Report Commands
301 Device status report (DSR): Answer is ESC [ 0 n (Terminal OK).
304 Cursor position report (CPR): Answer is ESC [ \fIy\fP ; \fIx\fP R,
305 where \fIx,y\fP is the cursor location.
308 .B DEC Private Mode (DECSET/DECRST) sequences
311 These are not described in ECMA-48.
312 We list the Set Mode sequences;
313 the Reset Mode sequences are obtained by replacing the final \(aqh\(aq
317 DECCKM (default off): When set, the cursor keys send an ESC O prefix,
321 DECCOLM (default off = 80 columns): 80/132 col mode switch.
322 The driver sources note that this alone does not suffice; some user-mode
325 has to change the hardware registers on the console video card.
328 DECSCNM (default off): Set reverse-video mode.
331 DECOM (default off): When set, cursor addressing is relative to
332 the upper left corner of the scrolling region.
335 DECAWM (default on): Set autowrap on.
336 In this mode, a graphic
337 character emitted after column 80 (or column 132 of DECCOLM is on)
338 forces a wrap to the beginning of the following line first.
341 DECARM (default on): Set keyboard autorepeat on.
344 X10 Mouse Reporting (default off): Set reporting mode to 1 (or reset to
348 DECTECM (default on): Make cursor visible.
351 X11 Mouse Reporting (default off): Set reporting mode to 2 (or reset
352 to 0) \(em see below.
355 .B Linux Console Private CSI Sequences
358 The following sequences are neither ECMA-48 nor native VT102.
359 They are native to the Linux console driver.
360 Colors are in SGR parameters:
361 0 = black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 =
365 ESC [ 1 ; \fIn\fP ] Set color \fIn\fP as the underline color
366 ESC [ 2 ; \fIn\fP ] Set color \fIn\fP as the dim color
367 ESC [ 8 ] Make the current color pair the default attributes.
368 ESC [ 9 ; \fIn\fP ] Set screen blank timeout to \fIn\fP minutes.
369 ESC [ 10 ; \fIn\fP ] Set bell frequency in Hz.
370 ESC [ 11 ; \fIn\fP ] Set bell duration in msec.
371 ESC [ 12 ; \fIn\fP ] Bring specified console to the front.
372 ESC [ 13 ] Unblank the screen.
373 ESC [ 14 ; \fIn\fP ] Set the VESA powerdown interval in minutes.
376 The kernel knows about 4 translations of bytes into console-screen
378 The four tables are: a) Latin1 \-> PC,
379 b) VT100 graphics \-> PC, c) PC \-> PC, d) user-defined.
381 There are two character sets, called G0 and G1, and one of them
382 is the current character set.
384 Typing \fB^N\fP causes G1 to become current,
385 \fB^O\fP causes G0 to become current.
387 These variables G0 and G1 point at a translation table, and can be
389 Initially they point at tables a) and b), respectively.
390 The sequences ESC ( B and ESC ( 0 and ESC ( U and ESC ( K cause G0 to
391 point at translation table a), b), c) and d), respectively.
392 The sequences ESC ) B and ESC ) 0 and ESC ) U and ESC ) K cause G1 to
393 point at translation table a), b), c) and d), respectively.
395 The sequence ESC c causes a terminal reset, which is what you want if the
396 screen is all garbled.
397 The oft-advised "echo ^V^O" will only make G0 current,
398 but there is no guarantee that G0 points at table a).
399 In some distributions there is a program
401 that just does "echo ^[c".
402 If your terminfo entry for the console is correct
403 (and has an entry rs1=\\Ec), then "tput reset" will also work.
405 The user-defined mapping table can be set using
407 The result of the mapping is that if a symbol c is printed, the symbol
408 s = map[c] is sent to the video memory.
409 The bitmap that corresponds to
410 s is found in the character ROM, and can be changed using
413 The mouse tracking facility is intended to return
414 .BR xterm (1)-compatible
415 mouse status reports.
416 Because the console driver has no way to know
417 the device or type of the mouse, these reports are returned in the
418 console input stream only when the virtual terminal driver receives
419 a mouse update ioctl.
420 These ioctls must be generated by a mouse-aware
421 user-mode application such as the
425 The mouse tracking escape sequences generated by
426 \fBxterm\fP(1) encode numeric parameters in a single character as
428 For example, \(aq!\(aq is 1.
429 The screen coordinate system is 1-based.
431 The X10 compatibility mode sends an escape sequence on button press
432 encoding the location and the mouse button pressed.
433 It is enabled by sending ESC [ ? 9 h and disabled with ESC [ ? 9 l.
434 On button press, \fBxterm\fP(1) sends
435 ESC [ M \fIbxy\fP (6 characters).
436 Here \fIb\fP is button\-1,
437 and \fIx\fP and \fIy\fP are the x and y coordinates of the mouse
438 when the button was pressed.
439 This is the same code the kernel also produces.
441 Normal tracking mode (not implemented in Linux 2.0.24) sends an escape
442 sequence on both button press and release.
443 Modifier information is also sent.
444 It is enabled by sending ESC [ ? 1000 h and disabled with
446 On button press or release, \fBxterm\fP(1) sends ESC [ M
448 The low two bits of \fIb\fP encode button information:
449 0=MB1 pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release.
450 The upper bits encode what modifiers were down when the button was
451 pressed and are added together: 4=Shift, 8=Meta, 16=Control.
453 \fIy\fP are the x and y coordinates of the mouse event.
454 The upper left corner is (1,1).
455 .SS "Comparisons With Other Terminals"
456 Many different terminal types are described, like the Linux console,
457 as being "VT100-compatible".
458 Here we discuss differences between the
459 Linux console and the two most important others, the DEC VT102 and
463 .B Control-character handling
465 The VT102 also recognized the following control characters:
467 NUL (0x00) was ignored;
469 ENQ (0x05) triggered an answerback message;
471 DC1 (0x11, \fB^Q\fP, XON) resumed transmission;
473 DC3 (0x13, \fB^S\fP, XOFF) caused VT100 to ignore (and stop transmitting)
474 all codes except XOFF and XON.
476 VT100-like DC1/DC3 processing may be enabled by the tty driver.
480 program (in VT100 mode) recognizes the control characters
481 BEL, BS, HT, LF, VT, FF, CR, SO, SI, ESC.
486 VT100 console sequences not implemented on the Linux console:
489 ESC N SS2 Single shift 2. (Select G2 character set for the next
491 ESC O SS3 Single shift 3. (Select G3 character set for the next
493 ESC P DCS Device control string (ended by ESC \\)
494 ESC X SOS Start of string.
495 ESC ^ PM Privacy message (ended by ESC \\)
496 ESC \\ ST String terminator
497 ESC * ... Designate G2 character set
498 ESC + ... Designate G3 character set
503 (in VT100 mode) recognizes ESC c, ESC # 8, ESC >, ESC =,
504 ESC D, ESC E, ESC H, ESC M, ESC N, ESC O, ESC P ... ESC \\,
505 ESC Z (it answers ESC [ ? 1 ; 2 c, "I am a VT100 with
506 advanced video option")
507 and ESC ^ ... ESC \\ with the same meanings as indicated above.
508 It accepts ESC (, ESC ), ESC *, ESC + followed by 0, A, B for
509 the DEC special character and line drawing set, UK, and US-ASCII,
512 The user can configure \fBxterm\fP(1) to respond to VT220-specific
513 control sequences, and it will identify itself as a VT52, VT100, and
514 up depending on the way it is configured and initialized.
516 It accepts ESC ] (OSC) for the setting of certain resources.
517 In addition to the ECMA-48 string terminator (ST),
518 \fBxterm\fP(1) accepts a BEL to terminate an OSC string.
519 These are a few of the OSC control sequences recognized by \fBxterm\fP(1):
522 ESC ] 0 ; \fItxt\fP ST Set icon name and window title to \fItxt\fP.
523 ESC ] 1 ; \fItxt\fP ST Set icon name to \fItxt\fP.
524 ESC ] 2 ; \fItxt\fP ST Set window title to \fItxt\fP.
525 ESC ] 4 ; \fInum\fP; \fItxt\fP ST Set ANSI color \fInum\fP to \fItxt\fP.
526 ESC ] 10 ; \fItxt\fP ST Set dynamic text color to \fItxt\fP.
527 ESC ] 4 6 ; \fIname\fP ST Change log file to \fIname\fP (normally disabled
528 by a compile-time option)
529 ESC ] 5 0 ; \fIfn\fP ST Set font to \fIfn\fP.
532 It recognizes the following with slightly modified meaning
533 (saving more state, behaving closer to VT100/VT220):
536 ESC 7 DECSC Save cursor
537 ESC 8 DECRC Restore cursor
543 ESC F Cursor to lower left corner of screen (if enabled by
544 \fBxterm\fP(1)'s \fBhpLowerleftBugCompat\fP resource)
545 ESC l Memory lock (per HP terminals).
546 Locks memory above the cursor.
547 ESC m Memory unlock (per HP terminals).
548 ESC n LS2 Invoke the G2 character set.
549 ESC o LS3 Invoke the G3 character set.
550 ESC | LS3R Invoke the G3 character set as GR.
551 ESC } LS2R Invoke the G2 character set as GR.
552 ESC ~ LS1R Invoke the G1 character set as GR.
555 It also recognizes ESC % and provides a more complete UTF-8
556 implementation than Linux console.
561 Old versions of \fBxterm\fP(1), for example, from X11R5,
562 interpret the blink SGR as a bold SGR.
563 Later versions which implemented ANSI colors, for example,
564 XFree86 3.1.2A in 1995, improved this by allowing
565 the blink attribute to be displayed as a color.
566 Modern versions of xterm implement blink SGR as blinking text
567 and still allow colored text as an alternate rendering of SGRs.
568 Stock X11R6 versions did not recognize the color-setting SGRs until
569 the X11R6.8 release, which incorporated XFree86 xterm.
570 All ECMA-48 CSI sequences recognized by Linux are also recognized by
572 however \fBxterm\fP(1) implements several ECMA-48 and DEC control sequences
573 not recognized by Linux.
576 program recognizes all of the DEC Private Mode sequences listed
577 above, but none of the Linux private-mode sequences.
578 For discussion of \fBxterm\fP(1)'s
579 own private-mode sequences, refer to the
580 \fIXterm Control Sequences\fP
585 available with the X distribution.
586 That document, though terse, is much longer than this manual page.
587 For a chronological overview,
590 http://invisible-island.net/xterm/xterm.log.html
593 details changes to xterm.
595 The \fIvttest\fP program
598 http://invisible-island.net/vttest/
601 demonstrates many of these control sequences.
602 The \fBxterm\fP(1) source distribution also contains sample
603 scripts which exercise other features.
605 ESC 8 (DECRC) is not able to restore the character set changed with
608 In 2.0.23, CSI is broken, and NUL is not ignored inside
611 Some older kernel versions (after 2.0) interpret 8-bit control
613 These "C1 controls" use codes between 128 and 159 to replace
614 ESC [, ESC ] and similar two-byte control sequence initiators.
615 There are fragments of that in modern kernels (either overlooked or
616 broken by changes to support UTF-8),
617 but the implementation is incomplete and should be regarded
620 Linux "private mode" sequences do not follow the rules in ECMA-48
621 for private mode control sequences.
622 In particular, those ending with ] do not use a standard terminating
624 The OSC (set palette) sequence is a greater problem,
625 since \fBxterm\fP(1) may interpret this as a control sequence
626 which requires a string terminator (ST).
627 Unlike the \fBsetterm\fP(1) sequences which will be ignored (since
628 they are invalid control sequences), the palette sequence will make
629 \fBxterm\fP(1) appear to hang (though pressing the return-key
631 To accommodate applications which have been hardcoded to use Linux
633 set the \fBxterm\fP(1) resource \fBbrokenLinuxOSC\fP to true.
635 An older version of this document implied that Linux recognizes the
636 ECMA-48 control sequence for invisible text.
640 .BR console_ioctl (4),