Penguin
Blame: console_codes(4)
EditPageHistoryDiffInfoLikePages
Annotated edit history of console_codes(4) version 4, including all changes. View license author blame.
Rev Author # Line
1 perry 1 CONSOLE_CODES
2 !!!CONSOLE_CODES
3 NAME
4 DESCRIPTION
5 LINUX CONSOLE CONTROLS
6 CHARACTER SETS
7 MOUSE TRACKING
8 COMPARISONS WITH OTHER TERMINALS
9 BUGS
10 SEE ALSO
11 ----
12 !!NAME
13
14
15 console_codes - Linux console escape and control sequences
16 !!DESCRIPTION
17
18
19 The Linux console implements a large subset of the VT102 and
20 ECMA-48/ISO 6429/ANSI X3.64 terminal controls, plus certain
21 private-mode sequences for changing the color palette,
22 character-set mapping, etc. In the tabular descriptions
23 below, the second column gives ECMA-48 or DEC mnemonics (the
24 latter if prefixed with DEC) for the given function.
25 Sequences without a mnemonic are neither ECMA-48 nor
26 VT102.
27
28
29 After all the normal output processing has been done, and a
30 stream of characters arrives at the console driver for
31 actual printing, the first thing that happens is a
32 translation from the code used for processing to the code
33 used for printing.
34
35
36 If the console is in UTF-8 mode, then the incoming bytes are
37 first assembled into 16-bit Unicode codes. Otherwise each
38 byte is transformed according to the current mapping table
39 (which translates it to a Unicode value). See the CHARACTER
40 SETS section below for discussion.
41
42
43 In the normal case, the Unicode value is converted to a font
44 index, and this is stored in video memory, so that the
45 corresponding glyph (as found in video ROM) appears on the
46 screen. Note that the use of Unicode (and the design of the
47 PC hardware) allows us to use 512 different glyphs
48 simultaneously.
49
50
51 If the current Unicode value is a control character, or we
52 are currently processing an escape sequence, the value will
53 treated specially. Instead of being turned into a font index
54 and rendered as a glyph, it may trigger cursor movement or
55 other control functions. See the LINUX CONSOLE CONTROLS
56 section below for discussion.
57
58
59 It is generally not good practice to hard-wire terminal
60 controls into programs. Linux supports a terminfo(5)
61 database of terminal capabilities. Rather than emitting
62 console escape sequences by hand, you will almost always
63 want to use a terminfo-aware screen library or utility such
64 as ncurses(3), tput(1), or
65 reset(1).
66 !!LINUX CONSOLE CONTROLS
67
68
69 This section describes all the control characters and escape
70 sequences that invoke special functions (i.e. anything other
71 than writing a glyph at the current cursor location) on the
72 Linux console.
73
74
75 __Control characters__
76
77
78 A character is a control character if (before transformation
79 according to the mapping table) it has one of the 14 codes
80 00 (NUL), 07 (BEL), 08 (BS), 09 (HT), 0a (LF), 0b (VT), 0c
81 (FF), 0d (CR), 0e (SO), 0f (SI), 18 (CAN), 1a (SUB), 1b
82 (ESC), 7f (DEL). One can set a `display control characters'
83 mode (see below), and allow 07, 09, 0b, 18, 1a, 7f to be
84 displayed as glyphs. On the other hand, in UTF-8 mode all
85 codes 00-1f are regarded as control characters, regardless
86 of any `display control characters' mode.
87
88
89 If we have a control character, it is acted upon immediately
90 and then discarded (even in the middle of an escape
91 sequence) and the escape sequence continues with the next
92 character. (However, ESC starts a new escape sequence,
93 possibly aborting a previous unfinished one, and CAN and SUB
94 abort any escape sequence.) The recognized control
95 characters are BEL, BS, HT, LF, VT, FF, CR, SO, SI, CAN,
96 SUB, ESC, DEL, CSI. They do what one would
97 expect:
98
99
100 BEL (0x07, ^G) beeps;
101
102
103 BS (0x08, ^H) backspaces one column (but not past the
104 beginning of the line);
105
106
107 HT (0x09, ^I) goes to the next tab stop or to the end of the
108 line if there is no earlier tab stop;
109
110
111 LF (0x0A, ^J), VT (0x0B, ^K) and FF (0x0C, ^L) all give a
112 linefeed;
113
114
115 CR (0x0D, ^M) gives a carriage return;
116
117
118 SO (0x0E, ^N) activates the G1 character set, and if LF/NL
119 (new line mode) is set also a carriage return;
120
121
122 SI (0x0F, ^O) activates the G0 character set;
123
124
125 CAN (0x18, ^X) and SUB (0x1A, ^Z) interrupt escape
126 sequences;
127
128
129 ESC (0x1B, ^[[) starts an escape sequence;
130
131
132 DEL (0x7F) is ignored;
133
134
135 CSI (0x9B) is equivalent to ESC [[.
136
137
138 __ESC- but not CSI-sequences__
139
140
141 __ECMA-48 CSI sequences__
142
143
144 CSI (or ESC [[) is followed by a sequence of parameters, at
145 most NPAR (16), that are decimal numbers separated by
146 semicolons. An empty or absent parameter is taken to be 0.
147 The sequence of parameters may be preceded by a single
148 question mark.
149
150
151 However, after CSI [[ (or ESC [[ [[) a single character is read
152 and this entire sequence is ignored. (The idea is to ignore
153 an echoed function key.)
154
155
156 The action of a CSI sequence is determined by its final
157 character.
158
159
160 __ECMA-48 Set Graphics Rendition__
161
162
163 The ECMA-48 SGR sequence ESC [[
164
165
166 __ECMA-48 Mode Switches__
167
168
169 ESC [[ 3 h
170
171
172 DECCRM (default off): Display control chars.
173
174
175 ESC [[ 4 h
176
177
178 DECIM (default off): Set insert mode.
179
180
181 ESC [[ 20 h
182
183
184 LF/NL (default off): Automatically follow echo of LF, VT or
185 FF with CR.
186
187
188 __ECMA-48 Status Report Commands__
189
190
191 ESC [[ 5 n
192
193
194 Device status report (DSR): Answer is ESC [[ 0 n (Terminal
195 OK).
196
197
198 ESC [[ 6 n
199
200
201 Cursor position report (CPR): Answer is ESC [[ ''y'' ;
202 ''x'' R, where ''x,y'' is the cursor
203 location.
204
205
206 __DEC Private Mode (DECSET/DECRST)
207 sequences.__
208
209
210 These are not described in ECMA-48. We list the Set Mode
211 sequences; the Reset Mode sequences are obtained by
212 replacing the final `h' by `l'.
213
214
215 ESC [[ ? 1 h
216
217
218 DECCKM (default off): When set, the cursor keys send an ESC
219 O prefix, rather than ESC [[.
220
221
222 ESC [[ ? 3 h
223
224
225 DECCOLM (default off = 80 columns): 80/132 col mode switch.
226 The driver sources note that this alone does not suffice;
227 some user-mode utility such as resizecons(8) has to
228 change the hardware registers on the console video
229 card.
230
231
232 ESC [[ ? 5 h
233
234
235 DECSCNM (default off): Set reverse-video mode.
236
237
238 ESC [[ ? 6 h
239
240
241 DECOM (default off): When set, cursor addressing is relative
242 to the upper left corner of the scrolling
243 region.
244
245
246 ESC [[ ? 7 h
247
248
249 DECAWM (default on): Set autowrap on. In this mode, a
250 graphic character emitted after column 80 (or column 132 of
251 DECCOLM is on) forces a wrap to the beginning of the
252 following line first.
253
254
255 ESC [[ ? 8 h
256
257
258 DECARM (default on): Set keyboard autorepreat
259 on.
260
261
262 ESC [[ ? 9 h
263
264
265 X10 Mouse Reporting (default off): Set reporting mode to 1
266 (or reset to 0) - see below.
267
268
269 ESC [[ ? 25 h
270
271
272 DECCM (default on): Make cursor visible.
273
274
275 ESC [[ ? 1000 h
276
277
278 X11 Mouse Reporting (default off): Set reporting mode to 2
279 (or reset to 0) - see below.
280
281
282 __Linux Console Private CSI Sequences__
283
284
285 The following sequences are neither ECMA-48 nor native
286 VT102. They are native to the Linux console driver. Colors
287 are in SGR parameters: 0 = black, 1 = red, 2 = green, 3 =
288 brown, 4 = blue, 5 = magenta, 6 = cyan, 7 =
289 white.
290 !!CHARACTER SETS
291
292
293 The kernel knows about 4 translations of bytes into console-screen symbols. The four tables are: a) Latin1 -
294
295
296 There are two character sets, called G0 and G1, and one of
297 them is the current character set. (Initially G0.) Typing ^N
298 causes G1 to become current, ^O causes G0 to become
299 current.
300
301
302 These variables G0 and G1 point at a translation table, and
303 can be changed by the user. Initially they point at tables
304 a) and b), respectively. The sequences ESC ( B and ESC ( 0
305 and ESC ( U and ESC ( K cause G0 to point at translation
306 table a), b), c) and d), respectively. The sequences ESC ) B
307 and ESC ) 0 and ESC ) U and ESC ) K cause G1 to point at
308 translation table a), b), c) and d),
309 respectively.
310
311
312 The sequence ESC c causes a terminal reset, which is what
313 you want if the screen is all garbled. The oft-advised
314 reset__(1) that just
315 does
316 __
317
318
319 The user-defined mapping table can be set using
320 mapscrn(8). The result of the mapping is that if a
321 symbol c is printed, the symbol s = map[[c] is sent to the
322 video memory. The bitmap that corresponds to s is found in
323 the character ROM, and can be changed using
324 __setfont(8).__
325 !!MOUSE TRACKING
326
327
328 The mouse tracking facility is intended to return
329 xterm-compatible mouse status reports. Because the console
330 driver has no way to know the device or type of the mouse,
331 these reports are returned in the console input stream only
332 when the virtual terminal driver receives a mouse update
333 ioctl. These ioctls must be generated by a mouse-aware
334 user-mode application such as the __gpm(8)__
335 daemon.
336
337
338 Parameters for all mouse tracking escape sequences generated
339 by ''xterm'' encode numeric parameters in a single
340 character as ''value''+040. For example, `!' is 1. The
341 screen coordinate system is 1-based.
342
343
344 The X10 compatibility mode sends an escape sequence on
345 button press encoding the location and the mouse button
346 pressed. It is enabled by sending ESC [[ ? 9 h and disabled
347 with ESC [[ ? 9 l. On button press, ''xterm'' sends ESC [[
348 M ''bxy'' (6 characters). Here ''b'' is button-1, and
349 ''x'' and ''y'' are the x and y coordinates of the
350 mouse when the button was pressed. This is the same code the
351 kernel also produces.
352
353
354 Normal tracking mode (not implemented in Linux 2.0.24) sends
355 an escape sequence on both button press and release.
356 Modifier information is also sent. It is enabled by sending
357 ESC [[ ? 1000 h and disabled with ESC [[ 1000 l. On button
358 press or release, ''xterm'' sends ESC [[ M ''bxy''. The
359 low two bits of ''b'' encode button information: 0=MB1
360 pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release. The upper
361 bits encode what modifiers were down when the button was
362 pressed and are added together: 4=Shift, 8=Meta, 16=Control.
363 Again ''x'' and ''y'' are the x and y coordinates of
364 the mouse event. The upper left corner is
365 (1,1).
366 !!COMPARISONS WITH OTHER TERMINALS
367
368
369 Many different terminal types are described, like the Linux
370 console, as being `VT100-compatible'. Here we discuss
371 differences vbetween the Linux console an the two most
372 important others, the DEC VT102 and
373 xterm(1).
374
375
376 __Control-character handling__
377
378
379 The vt102 also recognized the following control
380 characters:
381
382
383 NUL (0x00) was ignored;
384
385
386 ENQ (0x05) triggered an answerback message;
387
388
389 DC1 (0x11, ^Q, XON) resumed transmission;
390
391
392 DC3 (0x13, ^S, XOFF) caused vt100 to ignore (and stop
393 transmitting) all codes except XOFF and XON.
394
395
396 VT100-like DC1/DC3 processing may be enabled by the tty
397 driver.
398
399
400 The ''xterm'' program (in vt100 mode) recognizes the
401 control characters BEL, BS, HT, LF, VT, FF, CR, SO, SI,
402 ESC.
403
404
405 __Escape sequences__
406
407
408 VT100 console sequences not implemented on the Linux
409 console:
410
411
412 The program ''xterm'' (in vt100 mode) recognizes ESC c, ESC # 8, ESC ''
413
414
415 It recognizes the following with slightly modified meaning:
416
417
418 It also recognizes
419
420
421 It does not recognize ESC % ...
422
423
424 __CSI Sequences__
425
426
427 The ''xterm'' program (as of XFree86 3.1.2G) does not
428 recognize the blink or invisible-mode SGRs. Stock X11R6
429 versions do not recognize the color-setting SGRs. All other
430 ECMA-48 CSI sequences recognized by Linux are also
431 recognized by ''xterm'', and vice-versa.
432
433
434 The ''xterm'' program will recognize all of the DEC
435 Private Mode sequences listed above, but none of the Linux
436 private-mode sequences. For discussion of ''xterm'''s own
437 private-mode sequences, refer to the ''Xterm Control
438 Sequences'' document by Edward Moy and Stephen Gildea,
439 available with the X distribution.
440 !!BUGS
441
442
443 In 2.0.23, CSI is broken, and NUL is not ignored inside
444 escape sequences.
445 !!SEE ALSO
446
447
4 perry 448 console(4), console_ioctl(4),
1 perry 449 charsets(7)
450 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.