2 .\" Copyright (c) 1996 Andries Brouwer <aeb@cwi.nl>, Mon Oct 31 22:13:04 1996
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
6 .\" This is combined from many sources.
7 .\" For Linux, the definitive source is of course console.c.
8 .\" About vt100-like escape sequences in general there are
9 .\" the ISO/IEC 6429 and ISO/IEC 2022 norms, the descriptions of
10 .\" an actual vt100, and the xterm docs (ctlseqs.ms).
11 .\" Substantial portions of this text are derived from a write-up
12 .\" by Eric S. Raymond <esr@thyrsus.com>.
14 .\" Tiny correction, aeb, 961107.
16 .\" 2006-05-27, Several corrections - Thomas E. Dickey
18 .TH console_codes 4 (date) "Linux man-pages (unreleased)"
20 console_codes \- Linux console escape and control sequences
22 The Linux console implements a large subset of
23 the VT102 and ECMA-48 / ISO/IEC\~6429 / ANSI X3.64 terminal controls,
24 plus certain private-mode sequences
25 for changing the color palette, character-set mapping, and so on.
26 In the tabular descriptions below, the second column gives ECMA-48 or DEC
27 mnemonics (the latter if prefixed with DEC) for the given function.
28 Sequences without a mnemonic are neither ECMA-48 nor VT102.
30 After all the normal output processing has been done, and a
31 stream of characters arrives at the console driver for actual
32 printing, the first thing that happens is a translation from
33 the code used for processing to the code used for printing.
35 If the console is in UTF-8 mode, then the incoming bytes are
36 first assembled into 16-bit Unicode codes.
37 Otherwise, each byte is transformed according to the current mapping table
38 (which translates it to a Unicode value).
39 See the \fBCharacter Sets\fP section below for discussion.
41 In the normal case, the Unicode value is converted to a font index,
42 and this is stored in video memory, so that the corresponding glyph
43 (as found in video ROM) appears on the screen.
44 Note that the use of Unicode (and the design of the PC hardware)
45 allows us to use 512 different glyphs simultaneously.
47 If the current Unicode value is a control character, or we are
48 currently processing an escape sequence, the value will treated
50 Instead of being turned into a font index and rendered as
51 a glyph, it may trigger cursor movement or other control functions.
52 See the \fBLinux Console Controls\fP section below for discussion.
54 It is generally not good practice to hard-wire terminal controls into
58 database of terminal capabilities.
59 Rather than emitting console escape sequences by hand, you will almost
60 always want to use a terminfo-aware screen library or utility such as
65 .SS Linux console controls
66 This section describes all the control characters and escape sequences
67 that invoke special functions (i.e., anything other than writing a
68 glyph at the current cursor location) on the Linux console.
70 .B "Control characters"
72 A character is a control character if (before transformation
73 according to the mapping table) it has one of the 14 codes
74 00 (NUL), 07 (BEL), 08 (BS), 09 (HT), 0a (LF), 0b (VT),
75 0c (FF), 0d (CR), 0e (SO), 0f (SI), 18 (CAN), 1a (SUB),
77 One can set a "display control characters" mode (see below),
78 and allow 07, 09, 0b, 18, 1a, 7f to be displayed as glyphs.
79 On the other hand, in UTF-8 mode all codes 00\[en]1f are regarded
80 as control characters, regardless of any "display control characters"
83 If we have a control character, it is acted upon immediately
84 and then discarded (even in the middle of an escape sequence)
85 and the escape sequence continues with the next character.
86 (However, ESC starts a new escape sequence, possibly aborting a previous
87 unfinished one, and CAN and SUB abort any escape sequence.)
88 The recognized control characters are BEL, BS, HT, LF, VT, FF,
89 CR, SO, SI, CAN, SUB, ESC, DEL, CSI.
90 They do what one would expect:
92 BEL (0x07, \fB\[ha]G\fP)
95 BS (0x08, \fB\[ha]H\fP)
97 (but not past the beginning of the line);
99 HT (0x09, \fB\[ha]I\fP)
100 goes to the next tab stop or to the end of the line
101 if there is no earlier tab stop;
103 LF (0x0A, \fB\[ha]J\fP)
105 VT (0x0B, \fB\[ha]K\fP)
107 FF (0x0C, \fB\[ha]L\fP)
109 and if LF/NL (new-line mode) is set also a carriage return;
111 CR (0x0D, \fB\[ha]M\fP)
112 gives a carriage return;
114 SO (0x0E, \fB\[ha]N\fP)
115 activates the G1 character set;
117 SI (0x0F, \fB\[ha]O\fP)
118 activates the G0 character set;
120 CAN (0x18, \fB\[ha]X\fP)
122 SUB (0x1A, \fB\[ha]Z\fP)
123 abort escape sequences;
125 ESC (0x1B, \fB\[ha][\fP)
126 starts an escape sequence;
132 is equivalent to ESC [.
134 .B "ESC- but not CSI-sequences"
141 ESC H HTS Set tab stop at current column.
142 ESC M RI Reverse linefeed.
144 DEC private identification. The kernel
145 returns the string ESC [ ? 6 c, claiming
149 Save current state (cursor coordinates,
150 attributes, character sets pointed at by G0, G1).
153 Restore state most recently saved by ESC 7.
155 ESC % Start sequence selecting character set
156 ESC % @ \0\0\0Select default (ISO/IEC\~646 / ISO/IEC\~8859-1)
157 ESC % G \0\0\0Select UTF-8
158 ESC % 8 \0\0\0Select UTF-8 (obsolete)
160 DEC screen alignment test \- fill screen with E's.
163 Start sequence defining G0 character set
164 (followed by one of B, 0, U, K, as below)
167 Select default (ISO/IEC\~8859-1 mapping).
170 Select VT100 graphics mapping.
173 Select null mapping \- straight to character ROM.
176 Select user mapping \- the map that is loaded by the utility \fBmapscrn\fP(8).
179 Start sequence defining G1 (followed by one of B, 0, U, K, as above).
181 ESC > DECPNM Set numeric keypad mode
182 ESC = DECPAM Set application keypad mode
184 Operating System Command prefix.
186 ESC ] R Reset palette.
188 Set palette, with parameter given in 7 hexadecimal digits \fInrrggbb\fP after
189 the final P. Here \fIn\fP is the color (0\[en]15), and \fIrrggbb\fP indicates
190 the red/green/blue values (0\[en]255).
195 .B "ECMA-48 CSI sequences"
197 CSI (or ESC [) is followed by a sequence of parameters,
198 at most NPAR (16), that are decimal numbers separated by
200 An empty or absent parameter is taken to be 0.
201 The sequence of parameters may be preceded by a single question mark.
203 However, after CSI [ (or ESC [ [) a single character is read
204 and this entire sequence is ignored.
205 (The idea is to ignore an echoed function key.)
207 The action of a CSI sequence is determined by its final character.
212 Insert the indicated # of blank characters.
215 Move cursor up the indicated # of rows.
218 Move cursor down the indicated # of rows.
221 Move cursor right the indicated # of columns.
224 Move cursor left the indicated # of columns.
227 Move cursor down the indicated # of rows, to column 1.
230 Move cursor up the indicated # of rows, to column 1.
233 Move cursor to indicated column in current row.
236 Move cursor to the indicated row, column (origin at 1,1).
239 Erase display (default: from cursor to end of display).
242 ESC [ 1 J: erase from start to cursor.
245 ESC [ 2 J: erase whole display.
248 ESC [ 3 J: erase whole display including scroll-back
249 buffer (since Linux 3.0).
251 .\" ESC [ 3 J: commit f8df13e0a901fe55631fed66562369b4dba40f8b
253 Erase line (default: from cursor to end of line).
256 ESC [ 1 K: erase from start of line to cursor.
259 ESC [ 2 K: erase whole line.
262 Insert the indicated # of blank lines.
265 Delete the indicated # of lines.
268 Delete the indicated # of characters on current line.
271 Erase the indicated # of characters on current line.
274 Move cursor right the indicated # of columns.
277 Answer ESC [ ? 6 c: "I am a VT102".
280 Move cursor to the indicated row, current column.
283 Move cursor down the indicated # of rows.
286 Move cursor to the indicated row, column.
289 Without parameter: clear tab stop at current position.
292 ESC [ 3 g: delete all tab stops.
294 h SM Set Mode (see below).
295 l RM Reset Mode (see below).
296 m SGR Set attributes (see below).
297 n DSR Status report (see below).
298 q DECLL Set keyboard LEDs.
299 ESC [ 0 q: clear all LEDs
300 ESC [ 1 q: set Scroll Lock LED
301 ESC [ 2 q: set Num Lock LED
302 ESC [ 3 q: set Caps Lock LED
304 Set scrolling region; parameters are top and bottom row.
306 s ? Save cursor location.
307 u ? Restore cursor location.
309 Move cursor to indicated column in current row.
314 .B ECMA-48 Select Graphic Rendition
316 The ECMA-48 SGR sequence ESC [ \fIparameters\fP m sets display
318 Several attributes can be set in the same sequence, separated by
320 An empty parameter (between semicolons or string initiator or
321 terminator) is interpreted as a zero.
327 reset all attributes to their defaults
331 set half-bright (simulated with color on a color display)
333 3 set italic (since Linux 2.6.22; simulated with color on a color display)
335 set underscore (simulated with color on a color display)
336 (the colors used to simulate dim or underline are set
342 reset selected mapping, display control flag,
343 and toggle meta flag (ECMA-48 says "primary font").
346 select null mapping, set display control flag,
347 reset toggle meta flag (ECMA-48 says "first alternate font").
350 select null mapping, set display control flag,
351 set toggle meta flag (ECMA-48 says "second alternate font").
353 causes the high bit of a byte to be toggled
354 before the mapping table translation is done.
357 set underline; before Linux 4.17, this value
358 set normal intensity (as is done in many other terminals)
360 22 set normal intensity
361 23 italic off (since Linux 2.6.22)
365 30 set black foreground
366 31 set red foreground
367 32 set green foreground
368 33 set brown foreground
369 34 set blue foreground
370 35 set magenta foreground
371 36 set cyan foreground
372 37 set white foreground
374 256/24-bit foreground color follows, shoehorned into 16 basic colors
375 (before Linux 3.16: set underscore on, set default foreground color)
378 set default foreground color
379 (before Linux 3.16: set underscore off, set default foreground color)
381 40 set black background
382 41 set red background
383 42 set green background
384 43 set brown background
385 44 set blue background
386 45 set magenta background
387 46 set cyan background
388 47 set white background
390 256/24-bit background color follows, shoehorned into 8 basic colors
392 49 set default background color
394 set foreground to bright versions of 30..37
397 set background, same as 40..47 (bright not supported)
402 Commands 38 and 48 require further arguments:
406 256 color: values 0..15 are IBGR (black, red, green, ... white),
407 16..231 a 6x6x6 color cube, 232..255 a grayscale ramp
410 24-bit color, r/g/b components are in the range 0..255
414 .B ECMA-48 Mode Switches
417 DECCRM (default off): Display control chars.
420 DECIM (default off): Set insert mode.
423 LF/NL (default off): Automatically follow echo of LF, VT, or FF with CR.
426 .B ECMA-48 Status Report Commands
430 Device status report (DSR): Answer is ESC [ 0 n (Terminal OK).
433 Cursor position report (CPR): Answer is ESC [ \fIy\fP ; \fIx\fP R,
434 where \fIx,y\fP is the cursor location.
437 .B DEC Private Mode (DECSET/DECRST) sequences
440 These are not described in ECMA-48.
441 We list the Set Mode sequences;
442 the Reset Mode sequences are obtained by replacing the final \[aq]h\[aq]
446 DECCKM (default off): When set, the cursor keys send an ESC O prefix,
450 DECCOLM (default off = 80 columns): 80/132 col mode switch.
451 The driver sources note that this alone does not suffice; some user-mode
454 has to change the hardware registers on the console video card.
457 DECSCNM (default off): Set reverse-video mode.
460 DECOM (default off): When set, cursor addressing is relative to
461 the upper left corner of the scrolling region.
464 DECAWM (default on): Set autowrap on.
465 In this mode, a graphic
466 character emitted after column 80 (or column 132 of DECCOLM is on)
467 forces a wrap to the beginning of the following line first.
470 DECARM (default on): Set keyboard autorepeat on.
473 X10 Mouse Reporting (default off): Set reporting mode to 1 (or reset to
477 DECTECM (default on): Make cursor visible.
480 X11 Mouse Reporting (default off): Set reporting mode to 2 (or reset
484 .B Linux Console Private CSI Sequences
487 The following sequences are neither ECMA-48 nor native VT102.
488 They are native to the Linux console driver.
489 Colors are in SGR parameters:
490 0 = black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 =
491 cyan, 7 = white; 8\[en]15 = bright versions of 0\[en]7.
494 ESC [ 1 ; \fIn\fP ] T{
495 Set color \fIn\fP as the underline color.
497 ESC [ 2 ; \fIn\fP ] T{
498 Set color \fIn\fP as the dim color.
501 Make the current color pair the default attributes.
503 ESC [ 9 ; \fIn\fP ] T{
504 Set screen blank timeout to \fIn\fP minutes.
506 ESC [ 10 ; \fIn\fP ] T{
507 Set bell frequency in Hz.
509 ESC [ 11 ; \fIn\fP ] T{
510 Set bell duration in msec.
512 ESC [ 12 ; \fIn\fP ] T{
513 Bring specified console to the front.
518 ESC [ 14 ; \fIn\fP ] T{
519 Set the VESA powerdown interval in minutes.
522 Bring the previous console to the front
525 ESC [ 16 ; \fIn\fP ] T{
526 Set the cursor blink interval in milliseconds
529 .\" commit bd63364caa8df38bad2b25b11b2a1b849475cce5
532 The kernel knows about 4 translations of bytes into console-screen
534 The four tables are: a) Latin1 \-> PC,
535 b) VT100 graphics \-> PC, c) PC \-> PC, d) user-defined.
537 There are two character sets, called G0 and G1, and one of them
538 is the current character set.
540 Typing \fB\[ha]N\fP causes G1 to become current,
541 \fB\[ha]O\fP causes G0 to become current.
543 These variables G0 and G1 point at a translation table, and can be
545 Initially they point at tables a) and b), respectively.
546 The sequences ESC ( B and ESC ( 0 and ESC ( U and ESC ( K cause G0 to
547 point at translation table a), b), c), and d), respectively.
548 The sequences ESC ) B and ESC ) 0 and ESC ) U and ESC ) K cause G1 to
549 point at translation table a), b), c), and d), respectively.
551 The sequence ESC c causes a terminal reset, which is what you want if the
552 screen is all garbled.
553 The oft-advised "echo \[ha]V\[ha]O" will make only G0 current,
554 but there is no guarantee that G0 points at table a).
555 In some distributions there is a program
557 that just does "echo \[ha][c".
558 If your terminfo entry for the console is correct
559 (and has an entry rs1=\eEc), then "tput reset" will also work.
561 The user-defined mapping table can be set using
563 The result of the mapping is that if a symbol c is printed, the symbol
564 s = map[c] is sent to the video memory.
565 The bitmap that corresponds to
566 s is found in the character ROM, and can be changed using
569 The mouse tracking facility is intended to return
570 .BR xterm (1)-compatible
571 mouse status reports.
572 Because the console driver has no way to know
573 the device or type of the mouse, these reports are returned in the
574 console input stream only when the virtual terminal driver receives
575 a mouse update ioctl.
576 These ioctls must be generated by a mouse-aware
577 user-mode application such as the
581 The mouse tracking escape sequences generated by
582 \fBxterm\fP(1) encode numeric parameters in a single character as
584 For example, \[aq]!\[aq] is 1.
585 The screen coordinate system is 1-based.
587 The X10 compatibility mode sends an escape sequence on button press
588 encoding the location and the mouse button pressed.
589 It is enabled by sending ESC [ ? 9 h and disabled with ESC [ ? 9 l.
590 On button press, \fBxterm\fP(1) sends
591 ESC [ M \fIbxy\fP (6 characters).
592 Here \fIb\fP is button\-1,
593 and \fIx\fP and \fIy\fP are the x and y coordinates of the mouse
594 when the button was pressed.
595 This is the same code the kernel also produces.
597 Normal tracking mode (not implemented in Linux 2.0.24) sends an escape
598 sequence on both button press and release.
599 Modifier information is also sent.
600 It is enabled by sending ESC [ ? 1000 h and disabled with
602 On button press or release, \fBxterm\fP(1) sends ESC [ M
604 The low two bits of \fIb\fP encode button information:
605 0=MB1 pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release.
606 The upper bits encode what modifiers were down when the button was
607 pressed and are added together: 4=Shift, 8=Meta, 16=Control.
609 \fIy\fP are the x and y coordinates of the mouse event.
610 The upper left corner is (1,1).
611 .SS Comparisons with other terminals
612 Many different terminal types are described, like the Linux console,
613 as being "VT100-compatible".
614 Here we discuss differences between the
615 Linux console and the two most important others, the DEC VT102 and
619 .B Control-character handling
621 The VT102 also recognized the following control characters:
627 triggered an answerback message;
629 DC1 (0x11, \fB\[ha]Q\fP, XON)
630 resumed transmission;
632 DC3 (0x13, \fB\[ha]S\fP, XOFF)
633 caused VT100 to ignore (and stop transmitting)
634 all codes except XOFF and XON.
636 VT100-like DC1/DC3 processing may be enabled by the terminal driver.
640 program (in VT100 mode) recognizes the control characters
641 BEL, BS, HT, LF, VT, FF, CR, SO, SI, ESC.
646 VT100 console sequences not implemented on the Linux console:
650 Single shift 2. (Select G2 character set for the next character only.)
653 Single shift 3. (Select G3 character set for the next character only.)
656 Device control string (ended by ESC \e)
658 ESC X SOS Start of string.
659 ESC \[ha] PM Privacy message (ended by ESC \e)
660 ESC \e ST String terminator
661 ESC * ... Designate G2 character set
662 ESC + ... Designate G3 character set
667 (in VT100 mode) recognizes ESC c, ESC # 8, ESC >, ESC =,
668 ESC D, ESC E, ESC H, ESC M, ESC N, ESC O, ESC P ... ESC \e,
669 ESC Z (it answers ESC [ ? 1 ; 2 c, "I am a VT100 with
670 advanced video option")
671 and ESC \[ha] ... ESC \e with the same meanings as indicated above.
672 It accepts ESC (, ESC ), ESC *, ESC + followed by 0, A, B for
673 the DEC special character and line drawing set, UK, and US-ASCII,
676 The user can configure \fBxterm\fP(1) to respond to VT220-specific
677 control sequences, and it will identify itself as a VT52, VT100, and
678 up depending on the way it is configured and initialized.
680 It accepts ESC ] (OSC) for the setting of certain resources.
681 In addition to the ECMA-48 string terminator (ST),
682 \fBxterm\fP(1) accepts a BEL to terminate an OSC string.
683 These are a few of the OSC control sequences recognized by \fBxterm\fP(1):
686 ESC ] 0 ; \fItxt\fP ST T{
687 Set icon name and window title to \fItxt\fP.
689 ESC ] 1 ; \fItxt\fP ST Set icon name to \fItxt\fP.
690 ESC ] 2 ; \fItxt\fP ST Set window title to \fItxt\fP.
691 ESC ] 4 ; \fInum\fP; \fItxt\fP ST Set ANSI color \fInum\fP to \fItxt\fP.
692 ESC ] 10 ; \fItxt\fP ST Set dynamic text color to \fItxt\fP.
693 ESC ] 4 6 ; \fIname\fP ST T{
694 Change log file to \fIname\fP (normally disabled by a compile-time option).
696 ESC ] 5 0 ; \fIfn\fP ST Set font to \fIfn\fP.
699 It recognizes the following with slightly modified meaning
700 (saving more state, behaving closer to VT100/VT220):
703 ESC 7 DECSC Save cursor
704 ESC 8 DECRC Restore cursor
711 Cursor to lower left corner of screen (if enabled
712 by \fBxterm\fP(1)'s \fBhpLowerleftBugCompat\fP resource).
714 ESC l Memory lock (per HP terminals).
715 Locks memory above the cursor.
716 ESC m Memory unlock (per HP terminals).
717 ESC n LS2 Invoke the G2 character set.
718 ESC o LS3 Invoke the G3 character set.
719 ESC | LS3R Invoke the G3 character set as GR.
720 ESC } LS2R Invoke the G2 character set as GR.
721 ESC \[ti] LS1R Invoke the G1 character set as GR.
724 It also recognizes ESC % and provides a more complete UTF-8
725 implementation than Linux console.
730 Old versions of \fBxterm\fP(1), for example, from X11R5,
731 interpret the blink SGR as a bold SGR.
732 Later versions which implemented ANSI colors, for example,
733 XFree86 3.1.2A in 1995, improved this by allowing
734 the blink attribute to be displayed as a color.
735 Modern versions of xterm implement blink SGR as blinking text
736 and still allow colored text as an alternate rendering of SGRs.
737 Stock X11R6 versions did not recognize the color-setting SGRs until
738 the X11R6.8 release, which incorporated XFree86 xterm.
739 All ECMA-48 CSI sequences recognized by Linux are also recognized by
741 however \fBxterm\fP(1) implements several ECMA-48 and DEC control sequences
742 not recognized by Linux.
745 program recognizes all of the DEC Private Mode sequences listed
746 above, but none of the Linux private-mode sequences.
747 For discussion of \fBxterm\fP(1)'s
748 own private-mode sequences, refer to the
749 \fIXterm Control Sequences\fP
753 and Thomas E.\& Dickey
754 available with the X distribution.
755 That document, though terse, is much longer than this manual page.
756 For a chronological overview,
759 .UR http://invisible\-island.net\:/xterm\:/xterm.log.html
763 details changes to xterm.
765 The \fIvttest\fP program
768 .UR http://invisible\-island.net\:/vttest/
772 demonstrates many of these control sequences.
773 The \fBxterm\fP(1) source distribution also contains sample
774 scripts which exercise other features.
776 ESC 8 (DECRC) is not able to restore the character set changed with
779 In Linux 2.0.23, CSI is broken, and NUL is not ignored inside
782 Some older kernel versions (after Linux 2.0) interpret 8-bit control
784 These "C1 controls" use codes between 128 and 159 to replace
785 ESC [, ESC ] and similar two-byte control sequence initiators.
786 There are fragments of that in modern kernels (either overlooked or
787 broken by changes to support UTF-8),
788 but the implementation is incomplete and should be regarded
791 Linux "private mode" sequences do not follow the rules in ECMA-48
792 for private mode control sequences.
793 In particular, those ending with ] do not use a standard terminating
795 The OSC (set palette) sequence is a greater problem,
796 since \fBxterm\fP(1) may interpret this as a control sequence
797 which requires a string terminator (ST).
798 Unlike the \fBsetterm\fP(1) sequences which will be ignored (since
799 they are invalid control sequences), the palette sequence will make
800 \fBxterm\fP(1) appear to hang (though pressing the return-key
802 To accommodate applications which have been hardcoded to use Linux
804 set the \fBxterm\fP(1) resource \fBbrokenLinuxOSC\fP to true.
806 An older version of this document implied that Linux recognizes the
807 ECMA-48 control sequence for invisible text.
810 .BR ioctl_console (2),