]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man4/console_codes.4
veth.4: tfix
[thirdparty/man-pages.git] / man4 / console_codes.4
CommitLineData
fea681da
MK
1.\" Copyright (c) 1996 Andries Brouwer <aeb@cwi.nl>, Mon Oct 31 22:13:04 1996
2.\"
89e3ffe9 3.\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA)
fea681da
MK
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.
8f8359d8 8.\" %%%LICENSE_END
fea681da
MK
9.\"
10.\" This is combined from many sources.
11.\" For Linux, the definitive source is of course console.c.
12.\" About vt100-like escape sequences in general there are
13.\" the ISO 6429 and ISO 2022 norms, the descriptions of
14.\" an actual vt100, and the xterm docs (ctlseqs.ms).
15.\" Substantial portions of this text are derived from a write-up
16.\" by Eric S. Raymond <esr@thyrsus.com>.
17.\"
18.\" Tiny correction, aeb, 961107.
19.\"
2866cb53
MK
20.\" 2006-05-27, Several corrections - Thomas E. Dickey
21.\"
1d767b55 22.TH CONSOLE_CODES 4 2021-03-22 "Linux" "Linux Programmer's Manual"
fea681da
MK
23.SH NAME
24console_codes \- Linux console escape and control sequences
25.SH DESCRIPTION
26The Linux console implements a large subset of the VT102 and ECMA-48/ISO
276429/ANSI X3.64 terminal controls, plus certain private-mode sequences
28b3cbc5 28for changing the color palette, character-set mapping, and so on.
fea681da
MK
29In the tabular descriptions below, the second column gives ECMA-48 or DEC
30mnemonics (the latter if prefixed with DEC) for the given function.
31Sequences without a mnemonic are neither ECMA-48 nor VT102.
dd3568a1 32.PP
fea681da
MK
33After all the normal output processing has been done, and a
34stream of characters arrives at the console driver for actual
35printing, the first thing that happens is a translation from
36the code used for processing to the code used for printing.
dd3568a1 37.PP
fea681da 38If the console is in UTF-8 mode, then the incoming bytes are
c13182ef 39first assembled into 16-bit Unicode codes.
2b9b829d 40Otherwise, each byte is transformed according to the current mapping table
2866cb53 41(which translates it to a Unicode value).
511bfbc9 42See the \fBCharacter Sets\fP section below for discussion.
dd3568a1 43.PP
fea681da
MK
44In the normal case, the Unicode value is converted to a font index,
45and this is stored in video memory, so that the corresponding glyph
46(as found in video ROM) appears on the screen.
47Note that the use of Unicode (and the design of the PC hardware)
48allows us to use 512 different glyphs simultaneously.
dd3568a1 49.PP
fea681da
MK
50If the current Unicode value is a control character, or we are
51currently processing an escape sequence, the value will treated
c13182ef
MK
52specially.
53Instead of being turned into a font index and rendered as
fea681da 54a glyph, it may trigger cursor movement or other control functions.
511bfbc9 55See the \fBLinux Console Controls\fP section below for discussion.
dd3568a1 56.PP
fea681da 57It is generally not good practice to hard-wire terminal controls into
c13182ef
MK
58programs.
59Linux supports a
fea681da 60.BR terminfo (5)
c13182ef 61database of terminal capabilities.
fea681da
MK
62Rather than emitting console escape sequences by hand, you will almost
63always want to use a terminfo-aware screen library or utility such as
64.BR ncurses (3),
c13182ef 65.BR tput (1),
fea681da
MK
66or
67.BR reset (1).
73d8cece 68.SS Linux console controls
fea681da 69This section describes all the control characters and escape sequences
75b94dc3 70that invoke special functions (i.e., anything other than writing a
c13182ef 71glyph at the current cursor location) on the Linux console.
1a947a96
MK
72.PP
73.B "Control characters"
bdd915e2 74.PP
fea681da
MK
75A character is a control character if (before transformation
76according to the mapping table) it has one of the 14 codes
7700 (NUL), 07 (BEL), 08 (BS), 09 (HT), 0a (LF), 0b (VT),
780c (FF), 0d (CR), 0e (SO), 0f (SI), 18 (CAN), 1a (SUB),
791b (ESC), 7f (DEL).
84c517a4 80One can set a "display control characters" mode (see below),
fea681da 81and allow 07, 09, 0b, 18, 1a, 7f to be displayed as glyphs.
9bc87ed0 82On the other hand, in UTF-8 mode all codes 00\(en1f are regarded
84c517a4 83as control characters, regardless of any "display control characters"
fea681da 84mode.
2866cb53 85.PP
fea681da
MK
86If we have a control character, it is acted upon immediately
87and then discarded (even in the middle of an escape sequence)
88and the escape sequence continues with the next character.
89(However, ESC starts a new escape sequence, possibly aborting a previous
90unfinished one, and CAN and SUB abort any escape sequence.)
91The recognized control characters are BEL, BS, HT, LF, VT, FF,
c13182ef
MK
92CR, SO, SI, CAN, SUB, ESC, DEL, CSI.
93They do what one would expect:
fea681da 94.HP
9ca13180 95BEL (0x07, \fB\(haG\fP) beeps;
fea681da 96.HP
9ca13180 97BS (0x08, \fB\(haH\fP) backspaces one column
fea681da
MK
98(but not past the beginning of the line);
99.HP
9ca13180 100HT (0x09, \fB\(haI\fP) goes to the next tab stop or to the end of the line
fea681da
MK
101if there is no earlier tab stop;
102.HP
735334d4 103LF (0x0A, \fB\(haJ\fP), VT (0x0B, \fB\(haK\fP), and
9ca13180 104FF (0x0C, \fB\(haL\fP) all give a linefeed,
d4aa1c16 105and if LF/NL (new-line mode) is set also a carriage return;
fea681da 106.HP
9ca13180 107CR (0x0D, \fB\(haM\fP) gives a carriage return;
fea681da 108.HP
9ca13180 109SO (0x0E, \fB\(haN\fP) activates the G1 character set;
fea681da 110.HP
9ca13180 111SI (0x0F, \fB\(haO\fP) activates the G0 character set;
fea681da 112.HP
9ca13180 113CAN (0x18, \fB\(haX\fP) and SUB (0x1A, \fB\(haZ\fP) abort escape sequences;
fea681da 114.HP
9ca13180 115ESC (0x1B, \fB\(ha[\fP) starts an escape sequence;
fea681da
MK
116.HP
117DEL (0x7F) is ignored;
118.HP
119CSI (0x9B) is equivalent to ESC [.
1a947a96
MK
120.PP
121.B "ESC- but not CSI-sequences"
0b174fe0 122.ad l
fea681da 123.TS
0b174fe0 124l l lx.
fea681da
MK
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}
0b174fe0
MK
139ESC 8 DECRC T{
140Restore state most recently saved by ESC 7.
141T}
fea681da
MK
142ESC [ CSI Control sequence introducer
143ESC % Start sequence selecting character set
144ESC % @ \0\0\0Select default (ISO 646 / ISO 8859-1)
145ESC % G \0\0\0Select UTF-8
146ESC % 8 \0\0\0Select UTF-8 (obsolete)
0b174fe0
MK
147ESC # 8 DECALN T{
148DEC screen alignment test \- fill screen with E's
149T}
150ESC ( T{
151Start sequence defining G0 character set
152(followed by one of B, 0, U, K, as below)
153T}
154ESC ( B T{
155Select default (ISO 8859-1 mapping)
156T}
157ESC ( 0 T{
158Select VT100 graphics mapping
159T}
160ESC ( U T{
161Select null mapping \- straight to character ROM
162T}
163ESC ( K T{
164Select user mapping \- the map that is loaded by the utility \fBmapscrn\fP(8)
165T}
166ESC ) T{
167Start sequence defining G1 (followed by one of B, 0, U, K, as above).
168T}
fea681da
MK
169ESC > DECPNM Set numeric keypad mode
170ESC = DECPAM Set application keypad mode
2866cb53
MK
171ESC ] OSC T{
172(Should be: Operating system command)
173ESC ] P \fInrrggbb\fP: set palette, with parameter
174given in 7 hexadecimal digits after the final P :-(.
9bc87ed0
MK
175Here \fIn\fP is the color (0\(en15), and \fIrrggbb\fP indicates
176the red/green/blue values (0\(en255).
2866cb53
MK
177ESC ] R: reset palette
178T}
fea681da 179.TE
0b174fe0 180.ad
1a947a96
MK
181.PP
182.B "ECMA-48 CSI sequences"
bdd915e2 183.PP
fea681da
MK
184CSI (or ESC [) is followed by a sequence of parameters,
185at most NPAR (16), that are decimal numbers separated by
c13182ef
MK
186semicolons.
187An empty or absent parameter is taken to be 0.
fea681da 188The sequence of parameters may be preceded by a single question mark.
2866cb53 189.PP
fea681da 190However, after CSI [ (or ESC [ [) a single character is read
c13182ef
MK
191and this entire sequence is ignored.
192(The idea is to ignore an echoed function key.)
2866cb53 193.PP
fea681da 194The action of a CSI sequence is determined by its final character.
0b174fe0 195.ad l
fea681da 196.TS
0b174fe0
MK
197l l lx.
198@ ICH T{
199Insert the indicated # of blank characters.
200T}
201A CUU T{
202Move cursor up the indicated # of rows.
203T}
204B CUD T{
205Move cursor down the indicated # of rows.
206T}
207C CUF T{
208Move cursor right the indicated # of columns.
209T}
210D CUB T{
211Move cursor left the indicated # of columns.
212T}
213E CNL T{
214Move cursor down the indicated # of rows, to column 1.
215T}
216F CPL T{
217Move cursor up the indicated # of rows, to column 1.
218T}
219G CHA T{
220Move cursor to indicated column in current row.
221T}
222H CUP T{
223Move cursor to the indicated row, column (origin at 1,1).
224T}
225J ED T{
226Erase display (default: from cursor to end of display).
227T}
228 T{
229ESC [ 1 J: erase from start to cursor.
230T}
231 T{
232ESC [ 2 J: erase whole display.
233T}
234 T{
235ESC [ 3 J: erase whole display including scroll-back
236buffer (since Linux 3.0).
237T}
31483837 238.\" ESC [ 3 J: commit f8df13e0a901fe55631fed66562369b4dba40f8b
0b174fe0
MK
239K EL T{
240Erase line (default: from cursor to end of line).
241T}
242 T{
243ESC [ 1 K: erase from start of line to cursor.
244T}
245 T{
246ESC [ 2 K: erase whole line.
247T}
248L IL T{
249Insert the indicated # of blank lines.
250T}
251M DL T{
252Delete the indicated # of lines.
253T}
254P DCH T{
255Delete the indicated # of characters on current line.
256T}
257X ECH T{
258Erase the indicated # of characters on current line.
259T}
260a HPR T{
261Move cursor right the indicated # of columns.
262T}
263c DA T{
264Answer ESC [ ? 6 c: "I am a VT102".
265T}
266d VPA T{
267Move cursor to the indicated row, current column.
268T}
269e VPR T{
270Move cursor down the indicated # of rows.
271T}
272f HVP T{
273Move cursor to the indicated row, column.
274T}
275g TBC T{
276Without parameter: clear tab stop at current position.
277T}
278 T{
279ESC [ 3 g: delete all tab stops.
280T}
fea681da
MK
281h SM Set Mode (see below).
282l RM Reset Mode (see below).
283m SGR Set attributes (see below).
284n DSR Status report (see below).
285q DECLL Set keyboard LEDs.
286 ESC [ 0 q: clear all LEDs
287 ESC [ 1 q: set Scroll Lock LED
288 ESC [ 2 q: set Num Lock LED
289 ESC [ 3 q: set Caps Lock LED
0b174fe0
MK
290r DECSTBM T{
291Set scrolling region; parameters are top and bottom row.
292T}
fea681da
MK
293s ? Save cursor location.
294u ? Restore cursor location.
0b174fe0
MK
295\` HPA T{
296Move cursor to indicated column in current row.
297T}
fea681da 298.TE
0b174fe0 299.ad
1a947a96 300.PP
f603c6f3 301.B ECMA-48 Select Graphic Rendition
bdd915e2 302.PP
c13182ef 303The ECMA-48 SGR sequence ESC [ \fIparameters\fP m sets display
2866cb53 304attributes.
c13182ef 305Several attributes can be set in the same sequence, separated by
2866cb53 306semicolons.
c13182ef 307An empty parameter (between semicolons or string initiator or
2866cb53 308terminator) is interpreted as a zero.
0b174fe0 309.ad l
fea681da 310.TS
0b174fe0 311l lx.
2866cb53 312param result
0b174fe0
MK
3130 T{
314reset all attributes to their defaults
315T}
fea681da 3161 set bold
0b174fe0
MK
3172 T{
318set half-bright (simulated with color on a color display)
319T}
2866cb53
MK
3204 T{
321set underscore (simulated with color on a color display)
322(the colors used to simulate dim or underline are set
323using ESC ] ...)
324T}
fea681da
MK
3255 set blink
3267 set reverse video
2866cb53
MK
32710 T{
328reset selected mapping, display control flag,
329and toggle meta flag (ECMA-48 says "primary font").
330T}
33111 T{
332select null mapping, set display control flag,
333reset toggle meta flag (ECMA-48 says "first alternate font").
334T}
33512 T{
336select null mapping, set display control flag,
337set toggle meta flag (ECMA-48 says "second alternate font").
338The toggle meta flag
339causes the high bit of a byte to be toggled
340before the mapping table translation is done.
341T}
40fe605b 34221 T{
cb83181d
MK
343set underline; before Linux 4.17, this value
344set normal intensity (as is done in many other terminals)
40fe605b 345T}
fea681da
MK
34622 set normal intensity
34724 underline off
34825 blink off
34927 reverse video off
35030 set black foreground
35131 set red foreground
35232 set green foreground
35333 set brown foreground
35434 set blue foreground
35535 set magenta foreground
35636 set cyan foreground
35737 set white foreground
40fe605b
MK
35838 T{
359256/24-bit foreground color follows, shoehorned into 16 basic colors
cb83181d
MK
360(before Linux 3.16: set underscore on, set default foreground color)
361T}
36239 T{
363set default foreground color
364(before Linux 3.16: set underscore off, set default foreground color)
40fe605b 365T}
fea681da
MK
36640 set black background
36741 set red background
36842 set green background
36943 set brown background
37044 set blue background
37145 set magenta background
37246 set cyan background
37347 set white background
40fe605b
MK
37448 T{
375256/24-bit background color follows, shoehorned into 8 basic colors
376T}
fea681da 37749 set default background color
0b174fe0
MK
37890..97 T{
379set foreground to bright versions of 30..37
380T}
381100.107 T{
382set background, same as 40..47 (bright not supported)
383T}
fea681da 384.TE
0b174fe0 385.ad
1a947a96 386.PP
f1779b12
AB
387Commands 38 and 48 require further arguments:
388.TS
0b174fe0 389l lx.
f1779b12
AB
390;5;x T{
391256 color: values 0..15 are IBGR (black, red, green, ... white),
39216..231 a 6x6x6 color cube, 232..255 a grayscale ramp
393T}
0b174fe0
MK
394;2;r;g;b T{
39524-bit color, r/g/b components are in the range 0..255
396T}
f1779b12
AB
397.TE
398.PP
1a947a96 399.B ECMA-48 Mode Switches
fea681da
MK
400.TP
401ESC [ 3 h
402DECCRM (default off): Display control chars.
403.TP
404ESC [ 4 h
405DECIM (default off): Set insert mode.
406.TP
407ESC [ 20 h
735334d4 408LF/NL (default off): Automatically follow echo of LF, VT, or FF with CR.
fea681da 409.\"
1a947a96
MK
410.PP
411.B ECMA-48 Status Report Commands
fea681da
MK
412.\"
413.TP
414ESC [ 5 n
415Device status report (DSR): Answer is ESC [ 0 n (Terminal OK).
416.TP
417ESC [ 6 n
418Cursor position report (CPR): Answer is ESC [ \fIy\fP ; \fIx\fP R,
419where \fIx,y\fP is the cursor location.
420.\"
1a947a96
MK
421.PP
422.B DEC Private Mode (DECSET/DECRST) sequences
bdd915e2 423.PP
fea681da 424.\"
c13182ef
MK
425These are not described in ECMA-48.
426We list the Set Mode sequences;
f81fb444
MK
427the Reset Mode sequences are obtained by replacing the final \(aqh\(aq
428by \(aql\(aq.
fea681da
MK
429.TP
430ESC [ ? 1 h
431DECCKM (default off): When set, the cursor keys send an ESC O prefix,
432rather than ESC [.
433.TP
434ESC [ ? 3 h
c13182ef
MK
435DECCOLM (default off = 80 columns): 80/132 col mode switch.
436The driver sources note that this alone does not suffice; some user-mode
fea681da
MK
437utility such as
438.BR resizecons (8)
439has to change the hardware registers on the console video card.
440.TP
441ESC [ ? 5 h
442DECSCNM (default off): Set reverse-video mode.
443.TP
444ESC [ ? 6 h
445DECOM (default off): When set, cursor addressing is relative to
446the upper left corner of the scrolling region.
447.TP
448ESC [ ? 7 h
c13182ef
MK
449DECAWM (default on): Set autowrap on.
450In this mode, a graphic
fea681da
MK
451character emitted after column 80 (or column 132 of DECCOLM is on)
452forces a wrap to the beginning of the following line first.
453.TP
454ESC [ ? 8 h
e3e12155 455DECARM (default on): Set keyboard autorepeat on.
fea681da
MK
456.TP
457ESC [ ? 9 h
458X10 Mouse Reporting (default off): Set reporting mode to 1 (or reset to
5503c85e 4590)\(emsee below.
fea681da
MK
460.TP
461ESC [ ? 25 h
2866cb53 462DECTECM (default on): Make cursor visible.
fea681da
MK
463.TP
464ESC [ ? 1000 h
465X11 Mouse Reporting (default off): Set reporting mode to 2 (or reset
5503c85e 466to 0)\(emsee below.
fea681da 467.\"
1a947a96
MK
468.PP
469.B Linux Console Private CSI Sequences
bdd915e2 470.PP
fea681da 471.\"
c13182ef
MK
472The following sequences are neither ECMA-48 nor native VT102.
473They are native to the Linux console driver.
474Colors are in SGR parameters:
fea681da 4750 = black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 =
e224cfce 476cyan, 7 = white; 8\(en15 = bright versions of 0\(en7.
fea681da 477.TS
0b174fe0
MK
478l lx.
479ESC [ 1 ; \fIn\fP ] T{
480Set color \fIn\fP as the underline color.
481T}
482ESC [ 2 ; \fIn\fP ] T{
483Set color \fIn\fP as the dim color.
484T}
485ESC [ 8 ] T{
486Make the current color pair the default attributes.
487T}
488ESC [ 9 ; \fIn\fP ] T{
489Set screen blank timeout to \fIn\fP minutes.
490T}
491ESC [ 10 ; \fIn\fP ] T{
492Set bell frequency in Hz.
493T}
494ESC [ 11 ; \fIn\fP ] T{
495Set bell duration in msec.
496T}
497ESC [ 12 ; \fIn\fP ] T{
498Bring specified console to the front.
499T}
500ESC [ 13 ] T{
501Unblank the screen.
502T}
503ESC [ 14 ; \fIn\fP ] T{
504Set the VESA powerdown interval in minutes.
505T}
ee6a7196 506ESC [ 15 ] T{
f8db29e8
MK
507Bring the previous console to the front
508(since Linux 2.6.0).
509T}
ee6a7196 510ESC [ 16 ; \fIn\fP ] T{
8e085a68 511Set the cursor blink interval in milliseconds
db2280ee 512(since Linux 4.2).
8e085a68
MK
513T}
514.\" commit bd63364caa8df38bad2b25b11b2a1b849475cce5
fea681da 515.TE
73d8cece 516.SS Character sets
c13182ef 517The kernel knows about 4 translations of bytes into console-screen
2866cb53 518symbols.
4d9b6984
MK
519The four tables are: a) Latin1 \-> PC,
520b) VT100 graphics \-> PC, c) PC \-> PC, d) user-defined.
2866cb53 521.PP
fea681da 522There are two character sets, called G0 and G1, and one of them
6387216b
MK
523is the current character set.
524(Initially G0.)
9ca13180
MK
525Typing \fB\(haN\fP causes G1 to become current,
526\fB\(haO\fP causes G0 to become current.
2866cb53 527.PP
c13182ef
MK
528These variables G0 and G1 point at a translation table, and can be
529changed by the user.
2866cb53 530Initially they point at tables a) and b), respectively.
c13182ef 531The sequences ESC ( B and ESC ( 0 and ESC ( U and ESC ( K cause G0 to
735334d4 532point at translation table a), b), c), and d), respectively.
c13182ef 533The sequences ESC ) B and ESC ) 0 and ESC ) U and ESC ) K cause G1 to
735334d4 534point at translation table a), b), c), and d), respectively.
2866cb53 535.PP
fea681da 536The sequence ESC c causes a terminal reset, which is what you want if the
c13182ef 537screen is all garbled.
9ca13180 538The oft-advised "echo \(haV\(haO" will make only G0 current,
fea681da
MK
539but there is no guarantee that G0 points at table a).
540In some distributions there is a program
541.BR reset (1)
9ca13180 542that just does "echo \(ha[c".
c13182ef 543If your terminfo entry for the console is correct
d1a71985 544(and has an entry rs1=\eEc), then "tput reset" will also work.
2866cb53 545.PP
fea681da
MK
546The user-defined mapping table can be set using
547.BR mapscrn (8).
548The result of the mapping is that if a symbol c is printed, the symbol
c13182ef
MK
549s = map[c] is sent to the video memory.
550The bitmap that corresponds to
fea681da 551s is found in the character ROM, and can be changed using
a5e0a0e4 552.BR setfont (8).
73d8cece 553.SS Mouse tracking
511bfbc9 554The mouse tracking facility is intended to return