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