]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man4/console_codes.4
rename.2: SEE ALSO: add rename(1)
[thirdparty/man-pages.git] / man4 / console_codes.4
CommitLineData
fea681da
MK
1'\" t
2.\" Copyright (c) 1996 Andries Brouwer <aeb@cwi.nl>, Mon Oct 31 22:13:04 1996
3.\"
89e3ffe9 4.\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA)
fea681da
MK
5.\" This is free documentation; you can redistribute it and/or
6.\" modify it under the terms of the GNU General Public License as
7.\" published by the Free Software Foundation; either version 2 of
8.\" the License, or (at your option) any later version.
8f8359d8 9.\" %%%LICENSE_END
fea681da
MK
10.\"
11.\" This is combined from many sources.
12.\" For Linux, the definitive source is of course console.c.
13.\" About vt100-like escape sequences in general there are
14.\" the ISO 6429 and ISO 2022 norms, the descriptions of
15.\" an actual vt100, and the xterm docs (ctlseqs.ms).
16.\" Substantial portions of this text are derived from a write-up
17.\" by Eric S. Raymond <esr@thyrsus.com>.
18.\"
19.\" Tiny correction, aeb, 961107.
20.\"
2866cb53
MK
21.\" 2006-05-27, Several corrections - Thomas E. Dickey
22.\"
6b621d05 23.TH CONSOLE_CODES 4 2020-02-09 "Linux" "Linux Programmer's Manual"
fea681da
MK
24.SH NAME
25console_codes \- Linux console escape and control sequences
26.SH DESCRIPTION
27The Linux console implements a large subset of the VT102 and ECMA-48/ISO
286429/ANSI X3.64 terminal controls, plus certain private-mode sequences
28b3cbc5 29for changing the color palette, character-set mapping, and so on.
fea681da
MK
30In the tabular descriptions below, the second column gives ECMA-48 or DEC
31mnemonics (the latter if prefixed with DEC) for the given function.
32Sequences without a mnemonic are neither ECMA-48 nor VT102.
dd3568a1 33.PP
fea681da
MK
34After all the normal output processing has been done, and a
35stream of characters arrives at the console driver for actual
36printing, the first thing that happens is a translation from
37the code used for processing to the code used for printing.
dd3568a1 38.PP
fea681da 39If the console is in UTF-8 mode, then the incoming bytes are
c13182ef 40first assembled into 16-bit Unicode codes.
2b9b829d 41Otherwise, each byte is transformed according to the current mapping table
2866cb53 42(which translates it to a Unicode value).
511bfbc9 43See the \fBCharacter Sets\fP section below for discussion.
dd3568a1 44.PP
fea681da
MK
45In the normal case, the Unicode value is converted to a font index,
46and this is stored in video memory, so that the corresponding glyph
47(as found in video ROM) appears on the screen.
48Note that the use of Unicode (and the design of the PC hardware)
49allows us to use 512 different glyphs simultaneously.
dd3568a1 50.PP
fea681da
MK
51If the current Unicode value is a control character, or we are
52currently processing an escape sequence, the value will treated
c13182ef
MK
53specially.
54Instead of being turned into a font index and rendered as
fea681da 55a glyph, it may trigger cursor movement or other control functions.
511bfbc9 56See the \fBLinux Console Controls\fP section below for discussion.
dd3568a1 57.PP
fea681da 58It is generally not good practice to hard-wire terminal controls into
c13182ef
MK
59programs.
60Linux supports a
fea681da 61.BR terminfo (5)
c13182ef 62database of terminal capabilities.
fea681da
MK
63Rather than emitting console escape sequences by hand, you will almost
64always want to use a terminfo-aware screen library or utility such as
65.BR ncurses (3),
c13182ef 66.BR tput (1),
fea681da
MK
67or
68.BR reset (1).
73d8cece 69.SS Linux console controls
fea681da 70This section describes all the control characters and escape sequences
75b94dc3 71that invoke special functions (i.e., anything other than writing a
c13182ef 72glyph at the current cursor location) on the Linux console.
1a947a96
MK
73.PP
74.B "Control characters"
bdd915e2 75.PP
fea681da
MK
76A character is a control character if (before transformation
77according to the mapping table) it has one of the 14 codes
7800 (NUL), 07 (BEL), 08 (BS), 09 (HT), 0a (LF), 0b (VT),
790c (FF), 0d (CR), 0e (SO), 0f (SI), 18 (CAN), 1a (SUB),
801b (ESC), 7f (DEL).
84c517a4 81One can set a "display control characters" mode (see below),
fea681da 82and allow 07, 09, 0b, 18, 1a, 7f to be displayed as glyphs.
9bc87ed0 83On the other hand, in UTF-8 mode all codes 00\(en1f are regarded
84c517a4 84as control characters, regardless of any "display control characters"
fea681da 85mode.
2866cb53 86.PP
fea681da
MK
87If we have a control character, it is acted upon immediately
88and then discarded (even in the middle of an escape sequence)
89and the escape sequence continues with the next character.
90(However, ESC starts a new escape sequence, possibly aborting a previous
91unfinished one, and CAN and SUB abort any escape sequence.)
92The recognized control characters are BEL, BS, HT, LF, VT, FF,
c13182ef
MK
93CR, SO, SI, CAN, SUB, ESC, DEL, CSI.
94They do what one would expect:
fea681da 95.HP
8bb93cd4 96BEL (0x07, \fB^G\fP) beeps;
fea681da 97.HP
8bb93cd4 98BS (0x08, \fB^H\fP) backspaces one column
fea681da
MK
99(but not past the beginning of the line);
100.HP
8bb93cd4 101HT (0x09, \fB^I\fP) goes to the next tab stop or to the end of the line
fea681da
MK
102if there is no earlier tab stop;
103.HP
8bb93cd4
MK
104LF (0x0A, \fB^J\fP), VT (0x0B, \fB^K\fP) and
105FF (0x0C, \fB^L\fP) all give a linefeed,
d4aa1c16 106and if LF/NL (new-line mode) is set also a carriage return;
fea681da 107.HP
8bb93cd4 108CR (0x0D, \fB^M\fP) gives a carriage return;
fea681da 109.HP
8bb93cd4 110SO (0x0E, \fB^N\fP) activates the G1 character set;
fea681da 111.HP
8bb93cd4 112SI (0x0F, \fB^O\fP) activates the G0 character set;
fea681da 113.HP
b6df9451 114CAN (0x18, \fB^X\fP) and SUB (0x1A, \fB^Z\fP) abort escape sequences;
fea681da 115.HP
8bb93cd4 116ESC (0x1B, \fB^[\fP) starts an escape sequence;
fea681da
MK
117.HP
118DEL (0x7F) is ignored;
119.HP
120CSI (0x9B) is equivalent to ESC [.
1a947a96
MK
121.PP
122.B "ESC- but not CSI-sequences"
fea681da
MK
123.TS
124l l l.
125ESC c RIS Reset.
126ESC D IND Linefeed.
127ESC E NEL Newline.
128ESC H HTS Set tab stop at current column.
129ESC M RI Reverse linefeed.
2866cb53
MK
130ESC Z DECID T{
131DEC private identification. The kernel
132returns the string ESC [ ? 6 c, claiming
133that it is a VT102.
134T}
135ESC 7 DECSC T{
136Save current state (cursor coordinates,
137attributes, character sets pointed at by G0, G1).
138T}
fea681da
MK
139ESC 8 DECRC Restore state most recently saved by ESC 7.
140ESC [ CSI Control sequence introducer
141ESC % Start sequence selecting character set
142ESC % @ \0\0\0Select default (ISO 646 / ISO 8859-1)
143ESC % G \0\0\0Select UTF-8
144ESC % 8 \0\0\0Select UTF-8 (obsolete)
2bc2f479 145ESC # 8 DECALN DEC screen alignment test \- fill screen with E's.
fea681da
MK
146ESC ( Start sequence defining G0 character set
147ESC ( B \0\0\0Select default (ISO 8859-1 mapping)
2866cb53 148ESC ( 0 \0\0\0Select VT100 graphics mapping
2bc2f479
MK
149ESC ( U \0\0\0Select null mapping \- straight to character ROM
150ESC ( K \0\0\0Select user mapping \- the map that is loaded by
a4401275 151 \0\0\0the utility \fBmapscrn\fP(8).
fea681da
MK
152ESC ) Start sequence defining G1
153 (followed by one of B, 0, U, K, as above).
154ESC > DECPNM Set numeric keypad mode
155ESC = DECPAM Set application keypad mode
2866cb53
MK
156ESC ] OSC T{
157(Should be: Operating system command)
158ESC ] P \fInrrggbb\fP: set palette, with parameter
159given in 7 hexadecimal digits after the final P :-(.
9bc87ed0
MK
160Here \fIn\fP is the color (0\(en15), and \fIrrggbb\fP indicates
161the red/green/blue values (0\(en255).
2866cb53
MK
162ESC ] R: reset palette
163T}
fea681da 164.TE
1a947a96
MK
165.PP
166.B "ECMA-48 CSI sequences"
bdd915e2 167.PP
fea681da
MK
168CSI (or ESC [) is followed by a sequence of parameters,
169at most NPAR (16), that are decimal numbers separated by
c13182ef
MK
170semicolons.
171An empty or absent parameter is taken to be 0.
fea681da 172The sequence of parameters may be preceded by a single question mark.
2866cb53 173.PP
fea681da 174However, after CSI [ (or ESC [ [) a single character is read
c13182ef
MK
175and this entire sequence is ignored.
176(The idea is to ignore an echoed function key.)
2866cb53 177.PP
fea681da 178The action of a CSI sequence is determined by its final character.
fea681da 179.TS
759e590d 180l l l.
fea681da
MK
181@ ICH Insert the indicated # of blank characters.
182A CUU Move cursor up the indicated # of rows.
183B CUD Move cursor down the indicated # of rows.
184C CUF Move cursor right the indicated # of columns.
185D CUB Move cursor left the indicated # of columns.
186E CNL Move cursor down the indicated # of rows, to column 1.
187F CPL Move cursor up the indicated # of rows, to column 1.
188G CHA Move cursor to indicated column in current row.
189H CUP Move cursor to the indicated row, column (origin at 1,1).
190J ED Erase display (default: from cursor to end of display).
191 ESC [ 1 J: erase from start to cursor.
192 ESC [ 2 J: erase whole display.
31483837
PP
193 ESC [ 3 J: erase whole display including scroll-back
194 buffer (since Linux 3.0).
195.\" ESC [ 3 J: commit f8df13e0a901fe55631fed66562369b4dba40f8b
fea681da
MK
196K EL Erase line (default: from cursor to end of line).
197 ESC [ 1 K: erase from start of line to cursor.
198 ESC [ 2 K: erase whole line.
199L IL Insert the indicated # of blank lines.
200M DL Delete the indicated # of lines.
759e590d
MK
201P DCH Delete the indicated # of characters on current line.
202X ECH Erase the indicated # of characters on current line.
fea681da 203a HPR Move cursor right the indicated # of columns.
84c517a4 204c DA Answer ESC [ ? 6 c: "I am a VT102".
fea681da
MK
205d VPA Move cursor to the indicated row, current column.
206e VPR Move cursor down the indicated # of rows.
207f HVP Move cursor to the indicated row, column.
759e590d 208g TBC Without parameter: clear tab stop at current position.
fea681da
MK
209 ESC [ 3 g: delete all tab stops.
210h SM Set Mode (see below).
211l RM Reset Mode (see below).
212m SGR Set attributes (see below).
213n DSR Status report (see below).
214q DECLL Set keyboard LEDs.
215 ESC [ 0 q: clear all LEDs
216 ESC [ 1 q: set Scroll Lock LED
217 ESC [ 2 q: set Num Lock LED
218 ESC [ 3 q: set Caps Lock LED
219r DECSTBM Set scrolling region; parameters are top and bottom row.
220s ? Save cursor location.
221u ? Restore cursor location.
26868e5b 222\` HPA Move cursor to indicated column in current row.
fea681da 223.TE
1a947a96
MK
224.PP
225.B ECMA-48 Set Graphics Rendition
bdd915e2 226.PP
c13182ef 227The ECMA-48 SGR sequence ESC [ \fIparameters\fP m sets display
2866cb53 228attributes.
c13182ef 229Several attributes can be set in the same sequence, separated by
2866cb53 230semicolons.
c13182ef 231An empty parameter (between semicolons or string initiator or
2866cb53 232terminator) is interpreted as a zero.
fea681da
MK
233.TS
234l l.
2866cb53 235param result
fea681da
MK
2360 reset all attributes to their defaults
2371 set bold
2382 set half-bright (simulated with color on a color display)
2866cb53
MK
2394 T{
240set underscore (simulated with color on a color display)
241(the colors used to simulate dim or underline are set
242using ESC ] ...)
243T}
fea681da
MK
2445 set blink
2457 set reverse video
2866cb53
MK
24610 T{
247reset selected mapping, display control flag,
248and toggle meta flag (ECMA-48 says "primary font").
249T}
25011 T{
251select null mapping, set display control flag,
252reset toggle meta flag (ECMA-48 says "first alternate font").
253T}
25412 T{
255select null mapping, set display control flag,
256set toggle meta flag (ECMA-48 says "second alternate font").
257The toggle meta flag
258causes the high bit of a byte to be toggled
259before the mapping table translation is done.
260T}
40fe605b 26121 T{
cb83181d
MK
262set underline; before Linux 4.17, this value
263set normal intensity (as is done in many other terminals)
40fe605b 264T}
fea681da
MK
26522 set normal intensity
26624 underline off
26725 blink off
26827 reverse video off
26930 set black foreground
27031 set red foreground
27132 set green foreground
27233 set brown foreground
27334 set blue foreground
27435 set magenta foreground
27536 set cyan foreground
27637 set white foreground
40fe605b
MK
27738 T{
278256/24-bit foreground color follows, shoehorned into 16 basic colors
cb83181d
MK
279(before Linux 3.16: set underscore on, set default foreground color)
280T}
28139 T{
282set default foreground color
283(before Linux 3.16: set underscore off, set default foreground color)
40fe605b 284T}
fea681da
MK
28540 set black background
28641 set red background
28742 set green background
28843 set brown background
28944 set blue background
29045 set magenta background
29146 set cyan background
29247 set white background
40fe605b
MK
29348 T{
294256/24-bit background color follows, shoehorned into 8 basic colors
295T}
fea681da 29649 set default background color
329eb744
AB
29790..97 set foreground to bright versions of 30..37
298100.107 set background, same as 40..47 (bright not supported)
fea681da 299.TE
1a947a96 300.PP
f1779b12
AB
301Commands 38 and 48 require further arguments:
302.TS
303l l.
304;5;x T{
305256 color: values 0..15 are IBGR (black, red, green, ... white),
30616..231 a 6x6x6 color cube, 232..255 a grayscale ramp
307T}
cb83181d 308;2;r;g;b 24-bit color, r/g/b components are in the range 0..255
f1779b12
AB
309.TE
310.PP
1a947a96 311.B ECMA-48 Mode Switches
fea681da
MK
312.TP
313ESC [ 3 h
314DECCRM (default off): Display control chars.
315.TP
316ESC [ 4 h
317DECIM (default off): Set insert mode.
318.TP
319ESC [ 20 h
320LF/NL (default off): Automatically follow echo of LF, VT or FF with CR.
321.\"
1a947a96
MK
322.PP
323.B ECMA-48 Status Report Commands
fea681da
MK
324.\"
325.TP
326ESC [ 5 n
327Device status report (DSR): Answer is ESC [ 0 n (Terminal OK).
328.TP
329ESC [ 6 n
330Cursor position report (CPR): Answer is ESC [ \fIy\fP ; \fIx\fP R,
331where \fIx,y\fP is the cursor location.
332.\"
1a947a96
MK
333.PP
334.B DEC Private Mode (DECSET/DECRST) sequences
bdd915e2 335.PP
fea681da 336.\"
c13182ef
MK
337These are not described in ECMA-48.
338We list the Set Mode sequences;
f81fb444
MK
339the Reset Mode sequences are obtained by replacing the final \(aqh\(aq
340by \(aql\(aq.
fea681da
MK
341.TP
342ESC [ ? 1 h
343DECCKM (default off): When set, the cursor keys send an ESC O prefix,
344rather than ESC [.
345.TP
346ESC [ ? 3 h
c13182ef
MK
347DECCOLM (default off = 80 columns): 80/132 col mode switch.
348The driver sources note that this alone does not suffice; some user-mode
fea681da
MK
349utility such as
350.BR resizecons (8)
351has to change the hardware registers on the console video card.
352.TP
353ESC [ ? 5 h
354DECSCNM (default off): Set reverse-video mode.
355.TP
356ESC [ ? 6 h
357DECOM (default off): When set, cursor addressing is relative to
358the upper left corner of the scrolling region.
359.TP
360ESC [ ? 7 h
c13182ef
MK
361DECAWM (default on): Set autowrap on.
362In this mode, a graphic
fea681da
MK
363character emitted after column 80 (or column 132 of DECCOLM is on)
364forces a wrap to the beginning of the following line first.
365.TP
366ESC [ ? 8 h
e3e12155 367DECARM (default on): Set keyboard autorepeat on.
fea681da
MK
368.TP
369ESC [ ? 9 h
370X10 Mouse Reporting (default off): Set reporting mode to 1 (or reset to
5503c85e 3710)\(emsee below.
fea681da
MK
372.TP
373ESC [ ? 25 h
2866cb53 374DECTECM (default on): Make cursor visible.
fea681da
MK
375.TP
376ESC [ ? 1000 h
377X11 Mouse Reporting (default off): Set reporting mode to 2 (or reset
5503c85e 378to 0)\(emsee below.
fea681da 379.\"
1a947a96
MK
380.PP
381.B Linux Console Private CSI Sequences
bdd915e2 382.PP
fea681da 383.\"
c13182ef
MK
384The following sequences are neither ECMA-48 nor native VT102.
385They are native to the Linux console driver.
386Colors are in SGR parameters:
fea681da 3870 = black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 =
e224cfce 388cyan, 7 = white; 8\(en15 = bright versions of 0\(en7.
fea681da
MK
389.TS
390l l.
db2280ee
JW
391ESC [ 1 ; \fIn\fP ] Set color \fIn\fP as the underline color.
392ESC [ 2 ; \fIn\fP ] Set color \fIn\fP as the dim color.
fea681da
MK
393ESC [ 8 ] Make the current color pair the default attributes.
394ESC [ 9 ; \fIn\fP ] Set screen blank timeout to \fIn\fP minutes.
395ESC [ 10 ; \fIn\fP ] Set bell frequency in Hz.
396ESC [ 11 ; \fIn\fP ] Set bell duration in msec.
397ESC [ 12 ; \fIn\fP ] Bring specified console to the front.
398ESC [ 13 ] Unblank the screen.
399ESC [ 14 ; \fIn\fP ] Set the VESA powerdown interval in minutes.
f8db29e8
MK
400ESC [ 15 ] T{
401Bring the previous console to the front
402(since Linux 2.6.0).
403T}
8e085a68
MK
404ESC [ 16 ; \fIn\fP ] T{
405Set the cursor blink interval in milliseconds
db2280ee 406(since Linux 4.2).
8e085a68
MK
407T}
408.\" commit bd63364caa8df38bad2b25b11b2a1b849475cce5
fea681da 409.TE
73d8cece 410.SS Character sets
c13182ef 411The kernel knows about 4 translations of bytes into console-screen
2866cb53 412symbols.
4d9b6984
MK
413The four tables are: a) Latin1 \-> PC,
414b) VT100 graphics \-> PC, c) PC \-> PC, d) user-defined.
2866cb53 415.PP
fea681da 416There are two character sets, called G0 and G1, and one of them
6387216b
MK
417is the current character set.
418(Initially G0.)
8bb93cd4
MK
419Typing \fB^N\fP causes G1 to become current,
420\fB^O\fP causes G0 to become current.
2866cb53 421.PP
c13182ef
MK
422These variables G0 and G1 point at a translation table, and can be
423changed by the user.
2866cb53 424Initially they point at tables a) and b), respectively.
c13182ef 425The sequences ESC ( B and ESC ( 0 and ESC ( U and ESC ( K cause G0 to
2866cb53 426point at translation table a), b), c) and d), respectively.
c13182ef 427The sequences ESC ) B and ESC ) 0 and ESC ) U and ESC ) K cause G1 to
2866cb53
MK
428point at translation table a), b), c) and d), respectively.
429.PP
fea681da 430The sequence ESC c causes a terminal reset, which is what you want if the
c13182ef 431screen is all garbled.
33a0ccb2 432The oft-advised "echo ^V^O" will make only G0 current,
fea681da
MK
433but there is no guarantee that G0 points at table a).
434In some distributions there is a program
435.BR reset (1)
436that just does "echo ^[c".
c13182ef 437If your terminfo entry for the console is correct
d1a71985 438(and has an entry rs1=\eEc), then "tput reset" will also work.
2866cb53 439.PP
fea681da
MK
440The user-defined mapping table can be set using
441.BR mapscrn (8).
442The result of the mapping is that if a symbol c is printed, the symbol
c13182ef
MK
443s = map[c] is sent to the video memory.
444The bitmap that corresponds to
fea681da 445s is found in the character ROM, and can be changed using
a5e0a0e4 446.BR setfont (8).
73d8cece 447.SS Mouse tracking
511bfbc9 448The mouse tracking facility is intended to return