]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man4/console_codes.4
unix.7: Add pointer to cmsg(3) for an example of use of SCM_RIGHTS
[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.\"
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.
8.\"
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>.
16.\"
17.\" Tiny correction, aeb, 961107.
18.\"
2866cb53
MK
19.\" 2006-05-27, Several corrections - Thomas E. Dickey
20.\"
d27d9203 21.TH CONSOLE_CODES 4 2008-01-01 "Linux" "Linux Programmer's Manual"
fea681da
MK
22.SH NAME
23console_codes \- Linux console escape and control sequences
24.SH DESCRIPTION
25The Linux console implements a large subset of the VT102 and ECMA-48/ISO
266429/ANSI X3.64 terminal controls, plus certain private-mode sequences
27for changing the color palette, character-set mapping, etc.
28In the tabular descriptions below, the second column gives ECMA-48 or DEC
29mnemonics (the latter if prefixed with DEC) for the given function.
30Sequences without a mnemonic are neither ECMA-48 nor VT102.
31.LP
32After all the normal output processing has been done, and a
33stream of characters arrives at the console driver for actual
34printing, the first thing that happens is a translation from
35the code used for processing to the code used for printing.
36.LP
37If the console is in UTF-8 mode, then the incoming bytes are
c13182ef
MK
38first assembled into 16-bit Unicode codes.
39Otherwise each byte is transformed according to the current mapping table
2866cb53 40(which translates it to a Unicode value).
511bfbc9 41See the \fBCharacter Sets\fP section below for discussion.
fea681da
MK
42.LP
43In the normal case, the Unicode value is converted to a font index,
44and this is stored in video memory, so that the corresponding glyph
45(as found in video ROM) appears on the screen.
46Note that the use of Unicode (and the design of the PC hardware)
47allows us to use 512 different glyphs simultaneously.
48.LP
49If the current Unicode value is a control character, or we are
50currently processing an escape sequence, the value will treated
c13182ef
MK
51specially.
52Instead of being turned into a font index and rendered as
fea681da 53a glyph, it may trigger cursor movement or other control functions.
511bfbc9 54See the \fBLinux Console Controls\fP section below for discussion.
fea681da
MK
55.LP
56It is generally not good practice to hard-wire terminal controls into
c13182ef
MK
57programs.
58Linux supports a
fea681da 59.BR terminfo (5)
c13182ef 60database of terminal capabilities.
fea681da
MK
61Rather than emitting console escape sequences by hand, you will almost
62always want to use a terminfo-aware screen library or utility such as
63.BR ncurses (3),
c13182ef 64.BR tput (1),
fea681da
MK
65or
66.BR reset (1).
1a947a96 67.SS "Linux Console Controls"
fea681da 68This section describes all the control characters and escape sequences
75b94dc3 69that invoke special functions (i.e., anything other than writing a
c13182ef 70glyph at the current cursor location) on the Linux console.
1a947a96
MK
71.PP
72.B "Control characters"
73.sp
fea681da
MK
74A character is a control character if (before transformation
75according to the mapping table) it has one of the 14 codes
7600 (NUL), 07 (BEL), 08 (BS), 09 (HT), 0a (LF), 0b (VT),
770c (FF), 0d (CR), 0e (SO), 0f (SI), 18 (CAN), 1a (SUB),
781b (ESC), 7f (DEL).
84c517a4 79One can set a "display control characters" mode (see below),
fea681da
MK
80and allow 07, 09, 0b, 18, 1a, 7f to be displayed as glyphs.
81On the other hand, in UTF-8 mode all codes 00-1f are regarded
84c517a4 82as control characters, regardless of any "display control characters"
fea681da 83mode.
2866cb53 84.PP
fea681da
MK
85If we have a control character, it is acted upon immediately
86and then discarded (even in the middle of an escape sequence)
87and the escape sequence continues with the next character.
88(However, ESC starts a new escape sequence, possibly aborting a previous
89unfinished one, and CAN and SUB abort any escape sequence.)
90The recognized control characters are BEL, BS, HT, LF, VT, FF,
c13182ef
MK
91CR, SO, SI, CAN, SUB, ESC, DEL, CSI.
92They do what one would expect:
fea681da 93.HP
8bb93cd4 94BEL (0x07, \fB^G\fP) beeps;
fea681da 95.HP
8bb93cd4 96BS (0x08, \fB^H\fP) backspaces one column
fea681da
MK
97(but not past the beginning of the line);
98.HP
8bb93cd4 99HT (0x09, \fB^I\fP) goes to the next tab stop or to the end of the line
fea681da
MK
100if there is no earlier tab stop;
101.HP
8bb93cd4
MK
102LF (0x0A, \fB^J\fP), VT (0x0B, \fB^K\fP) and
103FF (0x0C, \fB^L\fP) all give a linefeed,
d4aa1c16 104and if LF/NL (new-line mode) is set also a carriage return;
fea681da 105.HP
8bb93cd4 106CR (0x0D, \fB^M\fP) gives a carriage return;
fea681da 107.HP
8bb93cd4 108SO (0x0E, \fB^N\fP) activates the G1 character set;
fea681da 109.HP
8bb93cd4 110SI (0x0F, \fB^O\fP) activates the G0 character set;
fea681da 111.HP
8bb93cd4 112CAN (0x18, \fB^X\fP) and SUB (0x1A, \fB^Z\fP) interrupt escape sequences;
fea681da 113.HP
8bb93cd4 114ESC (0x1B, \fB^[\fP) starts an escape sequence;
fea681da
MK
115.HP
116DEL (0x7F) is ignored;
117.HP
118CSI (0x9B) is equivalent to ESC [.
1a947a96
MK
119.PP
120.B "ESC- but not CSI-sequences"
fea681da
MK
121.TS
122l l l.
123ESC c RIS Reset.
124ESC D IND Linefeed.
125ESC E NEL Newline.
126ESC H HTS Set tab stop at current column.
127ESC M RI Reverse linefeed.
2866cb53
MK
128ESC Z DECID T{
129DEC private identification. The kernel
130returns the string ESC [ ? 6 c, claiming
131that it is a VT102.
132T}
133ESC 7 DECSC T{
134Save current state (cursor coordinates,
135attributes, character sets pointed at by G0, G1).
136T}
fea681da
MK
137ESC 8 DECRC Restore state most recently saved by ESC 7.
138ESC [ CSI Control sequence introducer
139ESC % Start sequence selecting character set
140ESC % @ \0\0\0Select default (ISO 646 / ISO 8859-1)
141ESC % G \0\0\0Select UTF-8
142ESC % 8 \0\0\0Select UTF-8 (obsolete)
2bc2f479 143ESC # 8 DECALN DEC screen alignment test \- fill screen with E's.
fea681da
MK
144ESC ( Start sequence defining G0 character set
145ESC ( B \0\0\0Select default (ISO 8859-1 mapping)
2866cb53 146ESC ( 0 \0\0\0Select VT100 graphics mapping
2bc2f479
MK
147ESC ( U \0\0\0Select null mapping \- straight to character ROM
148ESC ( K \0\0\0Select user mapping \- the map that is loaded by
a4401275 149 \0\0\0the utility \fBmapscrn\fP(8).
fea681da
MK
150ESC ) Start sequence defining G1
151 (followed by one of B, 0, U, K, as above).
152ESC > DECPNM Set numeric keypad mode
153ESC = DECPAM Set application keypad mode
2866cb53
MK
154ESC ] OSC T{
155(Should be: Operating system command)
156ESC ] P \fInrrggbb\fP: set palette, with parameter
157given in 7 hexadecimal digits after the final P :-(.
158Here \fIn\fP is the color (0-15), and \fIrrggbb\fP indicates
c13182ef 159the red/green/blue values (0-255).
2866cb53
MK
160ESC ] R: reset palette
161T}
fea681da 162.TE
1a947a96
MK
163.PP
164.B "ECMA-48 CSI sequences"
165.sp
fea681da
MK
166CSI (or ESC [) is followed by a sequence of parameters,
167at most NPAR (16), that are decimal numbers separated by
c13182ef
MK
168semicolons.
169An empty or absent parameter is taken to be 0.
fea681da 170The sequence of parameters may be preceded by a single question mark.
2866cb53 171.PP
fea681da 172However, after CSI [ (or ESC [ [) a single character is read
c13182ef
MK
173and this entire sequence is ignored.
174(The idea is to ignore an echoed function key.)
2866cb53 175.PP
fea681da 176The action of a CSI sequence is determined by its final character.
fea681da
MK
177.TS
178l l l.
179@ ICH Insert the indicated # of blank characters.
180A CUU Move cursor up the indicated # of rows.
181B CUD Move cursor down the indicated # of rows.
182C CUF Move cursor right the indicated # of columns.
183D CUB Move cursor left the indicated # of columns.
184E CNL Move cursor down the indicated # of rows, to column 1.
185F CPL Move cursor up the indicated # of rows, to column 1.
186G CHA Move cursor to indicated column in current row.
187H CUP Move cursor to the indicated row, column (origin at 1,1).
188J 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.
191K EL Erase line (default: from cursor to end of line).
192 ESC [ 1 K: erase from start of line to cursor.
193 ESC [ 2 K: erase whole line.
194L IL Insert the indicated # of blank lines.
195M DL Delete the indicated # of lines.
196P DCH Delete the indicated # of characters on the current line.
197X ECH Erase the indicated # of characters on the current line.
198a HPR Move cursor right the indicated # of columns.
84c517a4 199c DA Answer ESC [ ? 6 c: "I am a VT102".
fea681da
MK
200d VPA Move cursor to the indicated row, current column.
201e VPR Move cursor down the indicated # of rows.
202f HVP Move cursor to the indicated row, column.
203g TBC Without parameter: clear tab stop at the current position.
204 ESC [ 3 g: delete all tab stops.
205h SM Set Mode (see below).
206l RM Reset Mode (see below).
207m SGR Set attributes (see below).
208n DSR Status report (see below).
209q DECLL Set keyboard LEDs.
210 ESC [ 0 q: clear all LEDs
211 ESC [ 1 q: set Scroll Lock LED
212 ESC [ 2 q: set Num Lock LED
213 ESC [ 3 q: set Caps Lock LED
214r DECSTBM Set scrolling region; parameters are top and bottom row.
215s ? Save cursor location.
216u ? Restore cursor location.
26868e5b 217\` HPA Move cursor to indicated column in current row.
fea681da 218.TE
1a947a96
MK
219.PP
220.B ECMA-48 Set Graphics Rendition
221.sp
c13182ef 222The ECMA-48 SGR sequence ESC [ \fIparameters\fP m sets display
2866cb53 223attributes.
c13182ef 224Several attributes can be set in the same sequence, separated by
2866cb53 225semicolons.
c13182ef 226An empty parameter (between semicolons or string initiator or
2866cb53 227terminator) is interpreted as a zero.
fea681da
MK
228.TS
229l l.
2866cb53 230param result
fea681da
MK
2310 reset all attributes to their defaults
2321 set bold
2332 set half-bright (simulated with color on a color display)
2866cb53
MK
2344 T{
235set underscore (simulated with color on a color display)
236(the colors used to simulate dim or underline are set
237using ESC ] ...)
238T}
fea681da
MK
2395 set blink
2407 set reverse video
2866cb53
MK
24110 T{
242reset selected mapping, display control flag,
243and toggle meta flag (ECMA-48 says "primary font").
244T}
24511 T{
246select null mapping, set display control flag,
247reset toggle meta flag (ECMA-48 says "first alternate font").
248T}
24912 T{
250select null mapping, set display control flag,
251set toggle meta flag (ECMA-48 says "second alternate font").
252The toggle meta flag
253causes the high bit of a byte to be toggled
254before the mapping table translation is done.
255T}
25621 set normal intensity (ECMA-48 says "doubly underlined")
fea681da
MK
25722 set normal intensity
25824 underline off
25925 blink off
26027 reverse video off
26130 set black foreground
26231 set red foreground
26332 set green foreground
26433 set brown foreground
26534 set blue foreground
26635 set magenta foreground
26736 set cyan foreground
26837 set white foreground
26938 set underscore on, set default foreground color
27039 set underscore off, set default foreground color
27140 set black background
27241 set red background
27342 set green background
27443 set brown background
27544 set blue background
27645 set magenta background
27746 set cyan background
27847 set white background
27949 set default background color
280.TE
1a947a96
MK
281.PP
282.B ECMA-48 Mode Switches
fea681da
MK
283.TP
284ESC [ 3 h
285DECCRM (default off): Display control chars.
286.TP
287ESC [ 4 h
288DECIM (default off): Set insert mode.
289.TP
290ESC [ 20 h
291LF/NL (default off): Automatically follow echo of LF, VT or FF with CR.
292.\"
1a947a96
MK
293.PP
294.B ECMA-48 Status Report Commands
fea681da
MK
295.\"
296.TP
297ESC [ 5 n
298Device status report (DSR): Answer is ESC [ 0 n (Terminal OK).
299.TP
300ESC [ 6 n
301Cursor position report (CPR): Answer is ESC [ \fIy\fP ; \fIx\fP R,
302where \fIx,y\fP is the cursor location.
303.\"
1a947a96
MK
304.PP
305.B DEC Private Mode (DECSET/DECRST) sequences
306.sp
fea681da 307.\"
c13182ef
MK
308These are not described in ECMA-48.
309We list the Set Mode sequences;
f81fb444
MK
310the Reset Mode sequences are obtained by replacing the final \(aqh\(aq
311by \(aql\(aq.
fea681da
MK
312.TP
313ESC [ ? 1 h
314DECCKM (default off): When set, the cursor keys send an ESC O prefix,
315rather than ESC [.
316.TP
317ESC [ ? 3 h
c13182ef
MK
318DECCOLM (default off = 80 columns): 80/132 col mode switch.
319The driver sources note that this alone does not suffice; some user-mode
fea681da
MK
320utility such as
321.BR resizecons (8)
322has to change the hardware registers on the console video card.
323.TP
324ESC [ ? 5 h
325DECSCNM (default off): Set reverse-video mode.
326.TP
327ESC [ ? 6 h
328DECOM (default off): When set, cursor addressing is relative to
329the upper left corner of the scrolling region.
330.TP
331ESC [ ? 7 h
c13182ef
MK
332DECAWM (default on): Set autowrap on.
333In this mode, a graphic
fea681da
MK
334character emitted after column 80 (or column 132 of DECCOLM is on)
335forces a wrap to the beginning of the following line first.
336.TP
337ESC [ ? 8 h
e3e12155 338DECARM (default on): Set keyboard autorepeat on.
fea681da
MK
339.TP
340ESC [ ? 9 h
341X10 Mouse Reporting (default off): Set reporting mode to 1 (or reset to
df8a3cac 3420) \(em see below.
fea681da
MK
343.TP
344ESC [ ? 25 h
2866cb53 345DECTECM (default on): Make cursor visible.
fea681da
MK
346.TP
347ESC [ ? 1000 h
348X11 Mouse Reporting (default off): Set reporting mode to 2 (or reset
df8a3cac 349to 0) \(em see below.
fea681da 350.\"
1a947a96
MK
351.PP
352.B Linux Console Private CSI Sequences
353.sp
fea681da 354.\"
c13182ef
MK
355The following sequences are neither ECMA-48 nor native VT102.
356They are native to the Linux console driver.
357Colors are in SGR parameters:
fea681da
MK
3580 = black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 =
359cyan, 7 = white.
fea681da
MK
360.TS
361l l.
362ESC [ 1 ; \fIn\fP ] Set color \fIn\fP as the underline color
363ESC [ 2 ; \fIn\fP ] Set color \fIn\fP as the dim color
364ESC [ 8 ] Make the current color pair the default attributes.
365ESC [ 9 ; \fIn\fP ] Set screen blank timeout to \fIn\fP minutes.
366ESC [ 10 ; \fIn\fP ] Set bell frequency in Hz.
367ESC [ 11 ; \fIn\fP ] Set bell duration in msec.
368ESC [ 12 ; \fIn\fP ] Bring specified console to the front.
369ESC [ 13 ] Unblank the screen.
370ESC [ 14 ; \fIn\fP ] Set the VESA powerdown interval in minutes.
371.TE
1a947a96 372.SS "Character Sets"
c13182ef 373The kernel knows about 4 translations of bytes into console-screen
2866cb53 374symbols.
4d9b6984
MK
375The four tables are: a) Latin1 \-> PC,
376b) VT100 graphics \-> PC, c) PC \-> PC, d) user-defined.
2866cb53 377.PP
fea681da 378There are two character sets, called G0 and G1, and one of them
6387216b
MK
379is the current character set.
380(Initially G0.)
8bb93cd4
MK
381Typing \fB^N\fP causes G1 to become current,
382\fB^O\fP causes G0 to become current.
2866cb53 383.PP
c13182ef
MK
384These variables G0 and G1 point at a translation table, and can be
385changed by the user.
2866cb53 386Initially they point at tables a) and b), respectively.
c13182ef 387The sequences ESC ( B and ESC ( 0 and ESC ( U and ESC ( K cause G0 to
2866cb53 388point at translation table a), b), c) and d), respectively.
c13182ef 389The sequences ESC ) B and ESC ) 0 and ESC ) U and ESC ) K cause G1 to
2866cb53
MK
390point at translation table a), b), c) and d), respectively.
391.PP
fea681da 392The sequence ESC c causes a terminal reset, which is what you want if the
c13182ef 393screen is all garbled.
2866cb53 394The oft-advised "echo ^V^O" will only make G0 current,
fea681da
MK
395but there is no guarantee that G0 points at table a).
396In some distributions there is a program
397.BR reset (1)
398that just does "echo ^[c".
c13182ef 399If your terminfo entry for the console is correct
2866cb53
MK
400(and has an entry rs1=\\Ec), then "tput reset" will also work.
401.PP
fea681da
MK
402The user-defined mapping table can be set using
403.BR mapscrn (8).
404The result of the mapping is that if a symbol c is printed, the symbol
c13182ef
MK
405s = map[c] is sent to the video memory.
406The bitmap that corresponds to
fea681da 407s is found in the character ROM, and can be changed using
a5e0a0e4 408.BR setfont (8).
1a947a96 409.SS "Mouse Tracking"
511bfbc9 410The mouse tracking facility is intended to return