Imported upstream version 1.5
[manpages-zh.git] / raw / man4 / console_codes.4
blob7b8fbf3aa644b2e71a3d3dd3b73b113614d5d36b
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 .\"
19 .TH CONSOLE_CODES 4 1996-10-31 "Linux" "Linux Programmer's Manual"
20 .SH NAME
21 console_codes \- Linux console escape and control sequences
22 .SH DESCRIPTION
23 The Linux console implements a large subset of the VT102 and ECMA-48/ISO
24 6429/ANSI X3.64 terminal controls, plus certain private-mode sequences
25 for changing the color palette, character-set mapping, etc.
26 In the tabular descriptions below, the second column gives ECMA-48 or DEC
27 mnemonics (the latter if prefixed with DEC) for the given function.
28 Sequences without a mnemonic are neither ECMA-48 nor VT102.
29 .LP
30 After all the normal output processing has been done, and a
31 stream of characters arrives at the console driver for actual
32 printing, the first thing that happens is a translation from
33 the code used for processing to the code used for printing.
34 .LP
35 If the console is in UTF-8 mode, then the incoming bytes are
36 first assembled into 16-bit Unicode codes.  Otherwise
37 each byte is transformed according to the current mapping table
38 (which translates it to a Unicode value).  See the CHARACTER SETS
39 section below for discussion.
40 .LP
41 In the normal case, the Unicode value is converted to a font index,
42 and this is stored in video memory, so that the corresponding glyph
43 (as found in video ROM) appears on the screen.
44 Note that the use of Unicode (and the design of the PC hardware)
45 allows us to use 512 different glyphs simultaneously.
46 .LP
47 If the current Unicode value is a control character, or we are
48 currently processing an escape sequence, the value will treated
49 specially.  Instead of being turned into a font index and rendered as
50 a glyph, it may trigger cursor movement or other control functions.
51 See the LINUX CONSOLE CONTROLS section below for discussion.
52 .LP
53 It is generally not good practice to hard-wire terminal controls into
54 programs.  Linux supports a 
55 .BR terminfo (5)
56 database of terminal capabilities.  
57 Rather than emitting console escape sequences by hand, you will almost
58 always want to use a terminfo-aware screen library or utility such as
59 .BR ncurses (3),
60 .BR tput (1), 
62 .BR reset (1).
64 .SH "LINUX CONSOLE CONTROLS"
66 This section describes all the control characters and escape sequences
67 that invoke special functions (i.e. anything other than writing a
68 glyph at the current cursor location) on the Linux console. 
69 .SS "Control characters"
70 A character is a control character if (before transformation
71 according to the mapping table) it has one of the 14 codes
72 00 (NUL), 07 (BEL), 08 (BS), 09 (HT), 0a (LF), 0b (VT),
73 0c (FF), 0d (CR), 0e (SO), 0f (SI), 18 (CAN), 1a (SUB),
74 1b (ESC), 7f (DEL).
75 One can set a `display control characters' mode (see below),
76 and allow 07, 09, 0b, 18, 1a, 7f to be displayed as glyphs.
77 On the other hand, in UTF-8 mode all codes 00-1f are regarded
78 as control characters, regardless of any `display control characters'
79 mode.
81 If we have a control character, it is acted upon immediately
82 and then discarded (even in the middle of an escape sequence)
83 and the escape sequence continues with the next character.
84 (However, ESC starts a new escape sequence, possibly aborting a previous
85 unfinished one, and CAN and SUB abort any escape sequence.)
86 The recognized control characters are BEL, BS, HT, LF, VT, FF,
87 CR, SO, SI, CAN, SUB, ESC, DEL, CSI. They do what one would expect:
88 .HP
89 BEL (0x07, ^G) beeps;
90 .HP
91 BS (0x08, ^H) backspaces one column
92 (but not past the beginning of the line);
93 .HP
94 HT (0x09, ^I) goes to the next tab stop or to the end of the line
95 if there is no earlier tab stop;
96 .HP
97 LF (0x0A, ^J), VT (0x0B, ^K) and FF (0x0C, ^L) all give a linefeed;
98 .HP
99 CR (0x0D, ^M) gives a carriage return;
101 SO (0x0E, ^N) activates the G1 character set,
102 and if LF/NL (new line mode) is set also a carriage return;
104 SI (0x0F, ^O) activates the G0 character set;
106 CAN (0x18, ^X) and SUB (0x1A, ^Z) interrupt escape sequences;
108 ESC (0x1B, ^[) starts an escape sequence;
110 DEL (0x7F) is ignored;
112 CSI (0x9B) is equivalent to ESC [.
113 .\" .LP
114 .SS "ESC- but not CSI-sequences"
116 l l l.
117 ESC c   RIS     Reset.
118 ESC D   IND     Linefeed.
119 ESC E   NEL     Newline.
120 ESC H   HTS     Set tab stop at current column.
121 ESC M   RI      Reverse linefeed.
122 ESC Z   DECID   DEC private identification. The kernel
123                 returns the string  ESC [ ? 6 c, claiming
124                 that it is a VT102.
125 ESC 7   DECSC   Save current state (cursor coordinates,
126                 attributes, character sets pointed at by G0, G1).
127 ESC 8   DECRC   Restore state most recently saved by ESC 7.
128 ESC [   CSI     Control sequence introducer
129 ESC %           Start sequence selecting character set
130 ESC % @         \0\0\0Select default (ISO 646 / ISO 8859-1)
131 ESC % G         \0\0\0Select UTF-8
132 ESC % 8         \0\0\0Select UTF-8 (obsolete)
133 ESC # 8 DECALN  DEC screen alignment test - fill screen with E's.
134 ESC (           Start sequence defining G0 character set
135 ESC ( B         \0\0\0Select default (ISO 8859-1 mapping)
136 ESC ( 0         \0\0\0Select vt100 graphics mapping
137 ESC ( U         \0\0\0Select null mapping - straight to character ROM
138 ESC ( K         \0\0\0Select user mapping - the map that is loaded by
139                 \0\0\0the utility \fBmapscrn\fP(8).
140 ESC )           Start sequence defining G1
141                 (followed by one of B, 0, U, K, as above).
142 ESC >   DECPNM  Set numeric keypad mode
143 ESC =   DECPAM  Set application keypad mode
144 ESC ]   OSC     (Should be: Operating system command)
145                 ESC ] P \fInrrggbb\fP: set palette, with parameter
146                 given in 7 hexadecimal digits after the final P :-(.
147                 Here \fIn\fP is the color (0-15), and \fIrrggbb\fP indicates
148                 the red/green/blue values (0-255). 
149                 ESC ] R: reset palette
151 .SS "ECMA-48 CSI sequences"
153 CSI (or ESC [) is followed by a sequence of parameters,
154 at most NPAR (16), that are decimal numbers separated by
155 semicolons. An empty or absent parameter is taken to be 0.
156 The sequence of parameters may be preceded by a single question mark.
158 However, after CSI [ (or ESC [ [) a single character is read
159 and this entire sequence is ignored. (The idea is to ignore
160 an echoed function key.)
162 The action of a CSI sequence is determined by its final character.
165 l l l.
166 @       ICH     Insert the indicated # of blank characters.
167 A       CUU     Move cursor up the indicated # of rows.
168 B       CUD     Move cursor down the indicated # of rows.
169 C       CUF     Move cursor right the indicated # of columns.
170 D       CUB     Move cursor left the indicated # of columns.
171 E       CNL     Move cursor down the indicated # of rows, to column 1.
172 F       CPL     Move cursor up the indicated # of rows, to column 1.
173 G       CHA     Move cursor to indicated column in current row.
174 H       CUP     Move cursor to the indicated row, column (origin at 1,1).
175 J       ED      Erase display (default: from cursor to end of display).
176                 ESC [ 1 J: erase from start to cursor.
177                 ESC [ 2 J: erase whole display.
178 K       EL      Erase line (default: from cursor to end of line).
179                 ESC [ 1 K: erase from start of line to cursor.
180                 ESC [ 2 K: erase whole line.
181 L       IL      Insert the indicated # of blank lines.
182 M       DL      Delete the indicated # of lines.
183 P       DCH     Delete the indicated # of characters on the current line.
184 X       ECH     Erase the indicated # of characters on the current line.
185 a       HPR     Move cursor right the indicated # of columns.
186 c       DA      Answer ESC [ ? 6 c: `I am a VT102'.
187 d       VPA     Move cursor to the indicated row, current column.
188 e       VPR     Move cursor down the indicated # of rows.
189 f       HVP     Move cursor to the indicated row, column.
190 g       TBC     Without parameter: clear tab stop at the current position.
191                 ESC [ 3 g: delete all tab stops.
192 h       SM      Set Mode (see below).
193 l       RM      Reset Mode (see below).
194 m       SGR     Set attributes (see below).
195 n       DSR     Status report (see below).
196 q       DECLL   Set keyboard LEDs.
197                 ESC [ 0 q: clear all LEDs
198                 ESC [ 1 q: set Scroll Lock LED
199                 ESC [ 2 q: set Num Lock LED
200                 ESC [ 3 q: set Caps Lock LED
201 r       DECSTBM Set scrolling region; parameters are top and bottom row.
202 s       ?       Save cursor location.
203 u       ?       Restore cursor location.
204 `       HPA     Move cursor to indicated column in current row.
206 .SS ECMA-48 Set Graphics Rendition
208 The ECMA-48 SGR sequence ESC [ <parameters> m sets display attributes.
209 Several attributes can be set in the same sequence.
212 l l.
213 par     result
214 0       reset all attributes to their defaults
215 1       set bold
216 2       set half-bright (simulated with color on a color display)
217 4       set underscore (simulated with color on a color display)
218         (the colors used to simulate dim or underline are set
219         using ESC ] ...)
220 5       set blink
221 7       set reverse video
222 10      reset selected mapping, display control flag,
223         and toggle meta flag.
224 11      select null mapping, set display control flag,
225         reset toggle meta flag.
226 12      select null mapping, set display control flag,
227         set toggle meta flag. (The toggle meta flag
228         causes the high bit of a byte to be toggled
229         before the mapping table translation is done.)
230 21      set normal intensity (this is not compatible with ECMA-48)
231 22      set normal intensity
232 24      underline off
233 25      blink off
234 27      reverse video off
235 30      set black foreground
236 31      set red foreground
237 32      set green foreground
238 33      set brown foreground
239 34      set blue foreground
240 35      set magenta foreground
241 36      set cyan foreground
242 37      set white foreground
243 38      set underscore on, set default foreground color
244 39      set underscore off, set default foreground color
245 40      set black background
246 41      set red background
247 42      set green background
248 43      set brown background
249 44      set blue background
250 45      set magenta background
251 46      set cyan background
252 47      set white background
253 49      set default background color
255 .SS ECMA-48 Mode Switches
257 ESC [ 3 h
258 DECCRM (default off): Display control chars.
260 ESC [ 4 h
261 DECIM (default off): Set insert mode.
263 ESC [ 20 h
264 LF/NL (default off): Automatically follow echo of LF, VT or FF with CR.
266 .SS ECMA-48 Status Report Commands
269 ESC [ 5 n
270 Device status report (DSR): Answer is ESC [ 0 n (Terminal OK).
272 ESC [ 6 n
273 Cursor position report (CPR): Answer is ESC [ \fIy\fP ; \fIx\fP R,
274 where \fIx,y\fP is the cursor location.
276 .SS DEC Private Mode (DECSET/DECRST) sequences.
278 These are not described in ECMA-48.  We list the Set Mode sequences;
279 the Reset Mode sequences are obtained by replacing the final `h'
280 by `l'.
282 ESC [ ? 1 h
283 DECCKM (default off): When set, the cursor keys send an ESC O prefix,
284 rather than ESC [.
286 ESC [ ? 3 h
287 DECCOLM (default off = 80 columns): 80/132 col mode switch.  The
288 driver sources note that this alone does not suffice; some user-mode
289 utility such as
290 .BR resizecons (8)
291 has to change the hardware registers on the console video card.
293 ESC [ ? 5 h
294 DECSCNM (default off): Set reverse-video mode.
296 ESC [ ? 6 h
297 DECOM (default off): When set, cursor addressing is relative to
298 the upper left corner of the scrolling region.
300 ESC [ ? 7 h
301 DECAWM (default on): Set autowrap on.  In this mode, a graphic
302 character emitted after column 80 (or column 132 of DECCOLM is on)
303 forces a wrap to the beginning of the following line first.
305 ESC [ ? 8 h
306 DECARM (default on): Set keyboard autorepreat on.
308 ESC [ ? 9 h
309 X10 Mouse Reporting (default off): Set reporting mode to 1 (or reset to
310 0) \- see below.
312 ESC [ ? 25 h
313 DECCM (default on): Make cursor visible.
315 ESC [ ? 1000 h
316 X11 Mouse Reporting (default off): Set reporting mode to 2 (or reset
317 to 0) \- see below.
319 .SS Linux Console Private CSI Sequences
321 The following sequences are neither ECMA-48 nor native VT102.  They
322 are native to the Linux console driver.  Colors are in SGR parameters:
323 0 = black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 =
324 cyan, 7 = white.
327 l l.
328 ESC [ 1 ; \fIn\fP ]     Set color \fIn\fP as the underline color
329 ESC [ 2 ; \fIn\fP ]     Set color \fIn\fP as the dim color
330 ESC [ 8 ]               Make the current color pair the default attributes.
331 ESC [ 9 ; \fIn\fP ]     Set screen blank timeout to \fIn\fP minutes.
332 ESC [ 10 ; \fIn\fP ]    Set bell frequency in Hz.
333 ESC [ 11 ; \fIn\fP ]    Set bell duration in msec.
334 ESC [ 12 ; \fIn\fP ]    Bring specified console to the front.
335 ESC [ 13 ]              Unblank the screen.
336 ESC [ 14 ; \fIn\fP ]    Set the VESA powerdown interval in minutes.
339 .SH "CHARACTER SETS"
341 The kernel knows about 4 translations of bytes into console-screen symbols.
342 The four tables are: a) Latin1 -> PC,  b) VT100 graphics -> PC, c) PC -> PC,
343 d) user-defined.
345 There are two character sets, called G0 and G1, and one of them
346 is the current character set. (Initially G0.)
347 Typing ^N causes G1 to become current, ^O causes G0 to become current.
349 These variables G0 and G1 point at a translation table, and can be changed
350 by the user. Initially they point at tables a) and b), respectively.
351 The sequences ESC ( B and ESC ( 0 and ESC ( U and ESC ( K cause G0 to point
352 at translation table a), b), c) and d), respectively.
353 The sequences ESC ) B and ESC ) 0 and ESC ) U and ESC ) K cause G1 to point
354 at translation table a), b), c) and d), respectively.
356 The sequence ESC c causes a terminal reset, which is what you want if the
357 screen is all garbled. The oft-advised "echo ^V^O" will only make G0 current,
358 but there is no guarantee that G0 points at table a).
359 In some distributions there is a program
360 .BR reset (1)
361 that just does "echo ^[c".
362 If your terminfo entry for the console is correct (and has an entry rs1=\\Ec),
363 then "tput reset" will also work.
365 The user-defined mapping table can be set using
366 .BR mapscrn (8).
367 The result of the mapping is that if a symbol c is printed, the symbol
368 s = map[c] is sent to the video memory. The bitmap that corresponds to
369 s is found in the character ROM, and can be changed using
370 .BR setfont(8).
372 .SH "MOUSE TRACKING"
374 The mouse tracking facility is intended to return xterm-compatible
375 mouse status reports.  Because the console driver has no way to know
376 the device or type of the mouse, these reports are returned in the 
377 console input stream only when the virtual terminal driver receives 
378 a mouse update ioctl.  These ioctls must be generated by a mouse-aware
379 user-mode application such as the \fBgpm(8)\fR daemon.
381 Parameters for all mouse tracking escape sequences generated by
382 \fIxterm\fP encode numeric parameters in a single character as
383 \fIvalue\fP+040.  For example, `!' is 1.  The screen
384 coordinate system is 1-based.
386 The X10 compatibility mode sends an escape sequence on button press
387 encoding the location and the mouse button pressed.
388 It is enabled by sending ESC [ ? 9 h and disabled with ESC [ ? 9 l.
389 On button press, \fIxterm\fP sends
390 ESC [ M \fIbxy\fP (6 characters).  Here \fIb\fP is button\-1,
391 and \fIx\fP and \fIy\fP are the x and y coordinates of the mouse
392 when the button was pressed.
393 This is the same code the kernel also produces.
395 Normal tracking mode (not implemented in Linux 2.0.24) sends an escape
396 sequence on both button press and release.  Modifier information is
397 also sent.  It is enabled by sending ESC [ ? 1000 h and disabled with
398 ESC [ 1000 l.  On button press or release, \fIxterm\fP sends ESC [ M
399 \fIbxy\fP.  The low two bits of \fIb\fP encode button information:
400 0=MB1 pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release.  The upper
401 bits encode what modifiers were down when the button was pressed and
402 are added together: 4=Shift, 8=Meta, 16=Control.  Again \fIx\fP and
403 \fIy\fP are the x and y coordinates of the mouse event.  The upper
404 left corner is (1,1).
406 .SH "COMPARISONS WITH OTHER TERMINALS"
408 Many different terminal types are described, like the Linux console,
409 as being `VT100-compatible'.  Here we discuss differences vbetween the
410 Linux console an the two most important others, the DEC VT102 and
411 .BR xterm (1).
413 .SS Control-character handling
414 The vt102 also recognized the following control characters:
416 NUL (0x00) was ignored;
418 ENQ (0x05) triggered an answerback message;
420 DC1 (0x11, ^Q, XON) resumed transmission;
422 DC3 (0x13, ^S, XOFF) caused vt100 to ignore (and stop transmitting)
423 all codes except XOFF and XON.
425 VT100-like DC1/DC3 processing may be enabled by the tty driver.
427 The 
428 .I xterm
429 program (in vt100 mode) recognizes the control characters 
430 BEL, BS, HT, LF, VT, FF, CR, SO, SI, ESC.
432 .SS Escape sequences
433 VT100 console sequences not implemented on the Linux console:
436 l l l.
437 ESC N   SS2     Single shift 2. (Select G2 character set for the next
438                 character only.)
439 ESC O   SS3     Single shift 3. (Select G3 character set for the next
440                 character only.)
441 ESC P   DCS     Device control string (ended by ESC \e)
442 ESC X   SOS     Start of string.
443 ESC ^   PM      Privacy message (ended by ESC \e)
444 ESC \e  ST      String terminator
445 ESC * ...               Designate G2 character set
446 ESC + ...               Designate G3 character set
449 The program
450 .I xterm
451 (in vt100 mode) recognizes ESC c, ESC # 8, ESC >, ESC =,
452 ESC D, ESC E, ESC H, ESC M, ESC N, ESC O, ESC P ... ESC \,
453 ESC Z (it answers ESC [ ? 1 ; 2 c, `I am a vt100 with advanced video option')
454 and ESC ^ ... ESC \ with the same meanings as indicated above.
455 It accepts ESC (, ESC ), ESC *,  ESC + followed by 0, A, B for
456 the DEC special character and line drawing set, UK, and USASCII,
457 respectively.
458 It accepts ESC ] for the setting of certain resources:
461 l l.
462 ESC ] 0 ; txt BEL       Set icon name and window title to txt.
463 ESC ] 1 ; txt BEL       Set icon name to txt.
464 ESC ] 2 ; txt BEL       Set window title to txt.
465 ESC ] 4 6 ; name BEL    Change log file to name (normally disabled
466         by a compile-time option)
467 ESC ] 5 0 ; fn BEL      Set font to fn.
470 It recognizes the following with slightly modified meaning:
473 l l l.
474 ESC 7  DECSC    Save cursor
475 ESC 8  DECRC    Restore cursor
478 It also recognizes
481 l l l.
482 ESC F           Cursor to lower left corner of screen (if enabled by
483                 the hpLowerleftBugCompat resource)
484 ESC l           Memory lock (per HP terminals).
485                 Locks memory above the cursor.
486 ESC m           Memory unlock (per HP terminals).
487 ESC n   LS2     Invoke the G2 character set.
488 ESC o   LS3     Invoke the G3 character set.
489 ESC |   LS3R    Invoke the G3 character set as GR.
490                 Has no visible effect in xterm.
491 ESC }   LS2R    Invoke the G2 character set as GR.
492                 Has no visible effect in xterm.
493 ESC ~   LS1R    Invoke the G1 character set as GR.
494                 Has no visible effect in xterm.
497 It does not recognize ESC % ...
499 .SS CSI Sequences
500 The 
501 .I xterm
502 program (as of XFree86 3.1.2G) does not recognize the blink or invisible-mode 
503 SGRs. Stock X11R6 versions do not recognize the color-setting SGRs.
504 All other ECMA-48 CSI sequences recognized by Linux are also recognized by
505 .IR xterm ,
506 and vice-versa.
508 The 
509 .I xterm
510 program will recognize all of the DEC Private Mode sequences listed
511 above, but none of the Linux private-mode sequences.  For discussion
512 of 
513 .IR xterm 's
514 own private-mode sequences, refer to the
515 .I Xterm Control Sequences
516 document by Edward Moy and Stephen Gildea, available with the X 
517 distribution.
519 .SH BUGS
521 In 2.0.23, CSI is broken, and NUL is not ignored inside escape sequences.
523 .SH "SEE ALSO"
524 .BR console (4),
525 .BR console_ioctl (4),
526 .BR charsets (7)