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