console_codes(4) Device Drivers Manual console_codes(4) console_codes - Linux The Linux console implements a large subset of the VT102 and ECMA-48 / ISO/IEC 6429 / ANSI X3.64 terminal controls, plus certain private-mode sequences for changing the color palette, character-set mapping, and so on. In the tabular descriptions below, the second column gives ECMA-48 or DEC mnemonics (the latter if prefixed with DEC) for the given function. Sequences without a mnemonic are neither ECMA-48 nor VT102. , ( ), , , , . UTF-8, 16- . ( ). ). , , ( -) . , ( ) 512 . , . , , (, ) . Linux. . Linux terminfo(5). , , , , , terminfo, , ncurses(3), tput(1) reset(1). Linux , (.., , ) Linux. A character is a control character if (before transformation according to the mapping table) it has one of the 14 codes 00 (NUL), 07 (BEL), 08 (BS), 09 (HT), 0a (LF), 0b (VT), 0c (FF), 0d (CR), 0e (SO), 0f (SI), 18 (CAN), 1a (SUB), 1b (ESC), 7f (DEL). One can set a "display control characters" mode (see below), and allow 07, 09, 0b, 18, 1a, 7f to be displayed as glyphs. On the other hand, in UTF-8 mode all codes 00-1f are regarded as control characters, regardless of any "display control characters" mode. , , ( ), . , ESC, , , , CAN SUB . : BEL, BS, HT, LF, VT, FF, CR, SO, SI, CAN, SUB, ESC, DEL, CSI. : BEL (0x07, ^G) beeps; BS (0x08, ^H) ( , , ); HT (0x09, ^I) , ; LF (0x0A, ^J) VT (0x0B, ^K) FF (0x0C, ^L) , LF/NL ( ) ; CR (0x0D, ^M) ; SO (0x0E, ^N) G1; SI (0x0F, ^O) G0; CAN (0x18, ^X) SUB (0x1A, ^Z) abort escape sequences; ESC (0x1B, ^[) ; DEL (0x7F) is ignored; CSI (0x9B) is equivalent to ESC [. ESC- CSI- ESC c RIS ESC D IND ESC E NEL ESC H HTS ESC M RI ESC Z DECID DEC. ESC [ ? 6 c, VT102. ESC 7 DECSC ( , , , G0, G1). ESC 8 DECRC ESC 7 ESC % ESC % @ Select default (ISO/IEC 646 / ISO/IEC 8859-1) ESC % G UTF-8 ESC % 8 UTF-8 () ESC # 8 DECALN DEC: E ESC ( Start sequence defining G0 character set (followed by one of B, 0, U, K, as below) ESC ( B Select default (ISO/IEC 8859-1 mapping). ESC ( 0 VT100 ESC ( U null- -- ROM ESC ( K Select user mapping - the map that is loaded by the utility mapscrn(8). ESC ) Start sequence defining G1 (followed by one of B, 0, U, K, as above). ESC > DECPNM ESC = DECPAM ESC ] OSC Operating System Command prefix. ESC ] R Reset palette. ESC ] P Set palette, with parameter given in 7 hexadecimal digits nrrggbb after the final P. Here n is the color (0-15), and rrggbb indicates the red/green/blue values (0-255). CSI- ECMA-48 CSI ( ESC [) , , ( -- NPAR (16)). . . , CSI [ ( ESC [ [) . ( , ). CSI- . @ ICH N A CUU N B CUD N C CUF N D CUB N CNL N 1 F CPL N 1 CHA H CUP ( 1,1) J ED ( ) ESC [ 1 J: ESC [ 2 J: ESC [ 3 J: erase whole display including scroll-back buffer (since Linux 3.0). K EL ( ) ESC [ 1 K: ESC [ 2 K: L IL N DL N DCH N X ECH N HPR N DA ESC [ ? 6 c: << VT102>> VPA e VPR N HVP g TBC : ESC [ 3 g: SM ( ) l RM ( ) SGR ( ) DSR ( ) q DECLL ESC [ 0 q: ESC [ 1 q: Scroll Lock ESC [ 2 q: Num Lock ESC [ 3 q: Caps Lock r DECSTBM ; s ? u ? ` HPA ECMA-48 Select Graphic Rendition ECMA-48 SGR ESC [ parameters m . . ( ) . 0 1 2 ( ) 3 set italic (since Linux 2.6.22; simulated with color on a color display) 4 ( ) (, , ESC ] ) 5 7 10 , ( ECMA-48 << >>). 11 null-, , ( ECMA-48 << >>). 12 null-, , ( ECMA-48 << >>). . 21 set underline; before Linux 4.17, this value set normal intensity (as is done in many other terminals) 22 23 italic off (since Linux 2.6.22) 24 25 27 30 31 32 33 34 35 36 37 38 256/24-bit foreground color follows, shoehorned into 16 basic colors (before Linux 3.16: set underscore on, set default foreground color) 39 set default foreground color (before Linux 3.16: set underscore off, set default foreground color) 40 41 42 43 44 45 46 47 48 256/24-bit background color follows, shoehorned into 8 basic colors 49 90..97 set foreground to bright versions of 30..37 100..107 set background, same as 40..47 (bright not supported) Commands 38 and 48 require further arguments: ;5;x 256 color: values 0..15 are IBGR (black, red, green, ... white), 16..231 a 6x6x6 color cube, 232..255 a grayscale ramp ;2;r;g;b 24-bit color, r/g/b components are in the range 0..255 ECMA-48 ESC [ 3 h DECCRM ( ): . ESC [ 4 h DECIM ( ): . ESC [ 20 h LF/NL ( ): CR LF, VT FF. ECMA-48 ESC [ 5 n (DSR): ESC [ 0 n ( ). ESC [ 6 n (CPR): ESC [ y ; x R, x,y . - DEC (DECSET/DECRST) These are not described in ECMA-48. We list the Set Mode sequences; the Reset Mode sequences are obtained by replacing the final 'h' by 'l'. ESC [ ? 1 h DECCKM ( ): , ESC O, ESC [. ESC [ ? 3 h DECCOLM ( = 80 ): 80/132. , ; , , resizecons(8), . ESC [ ? 5 h DECSCNM ( ): . ESC [ ? 6 h DECOM ( ): , . ESC [ ? 7 h DECAWM ( ): . , 80- ( 132-, DECCOLM ), . ESC [ ? 8 h DECARM ( ): . ESC [ ? 9 h X10 Mouse Reporting (default off): Set reporting mode to 1 (or reset to 0)--see below. ESC [ ? 25 h DECTECM ( ): . ESC [ ? 1000 h X11 Mouse Reporting (default off): Set reporting mode to 2 (or reset to 0)--see below. CSI- Linux The following sequences are neither ECMA-48 nor native VT102. They are native to the Linux console driver. Colors are in SGR parameters: 0 = black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 = cyan, 7 = white; 8-15 = bright versions of 0-7. ESC [ 1 ; n ] n . ESC [ 2 ; n ] n . ESC [ 8 ] ESC [ 9 ; n ] n ESC [ 10 ; n ] ( ) ESC [ 11 ; n ] ( ) ESC [ 12 ; n ] ESC [ 13 ] (blank screen) ESC [ 14 ; n ] VESA ( ) ESC [ 15 ] ( Linux 2.6.0) ESC [ 16 ; n ] ( ) ( Linux 4.2). 4- . : a) Latin1 -> PC, b) VT100 -> PC, c) PC -> PC, d) . There are two character sets, called G0 and G1, and one of them is the current character set. (Initially G0.) Typing ^N causes G1 to become current, ^O causes G0 to become current. G0 G1 . a) b) . ESC ( B, ESC ( 0, ESC ( U ESC ( K G0 a), b), c) d), . ESC ) B, ESC ) 0, ESC ) U, ESC ) K G1 a), b), c) d), . The sequence ESC c causes a terminal reset, which is what you want if the screen is all garbled. The oft-advised "echo ^V^O" will make only G0 current, but there is no guarantee that G0 points at table a). In some distributions there is a program reset(1) that just does "echo ^[c". If your terminfo entry for the console is correct (and has an entry rs1=\Ec), then "tput reset" will also work. mapscrn(8). , c s = [c] . , s, setfont(8). xterm(1)- . , ( ), , ioctl . ioctl , , gpm(8). The mouse tracking escape sequences generated by xterm(1) encode numeric parameters in a single character as value+040. For example, '!' is 1. The screen coordinate system is 1-based. X10 , , . ESC [ ? 9 h ESC [ ? 9 l. xterm(1) ESC [ M bxy (6 ), b -- 1, x y x y . , . ( Linux 2.0.24) . . ESC [ ? 1000 h ESC [ 1000 l. xterm(1) ESC [ M bxy. b : 0=MB1 , 1=MB2 , 2=MB3 , 3=. , , . : 4=Shift, 8=Meta, 16=Control. : x y x y . (1,1). , Linux, VT100-. Linux -- DEC VT102 xterm(1). VT102 : NUL (0x00) was ignored; ENQ (0x05) ; DC1 (0x11, ^Q, XON) ; DC3 (0x13, ^S, XOFF) VT100 ( ) XOFF XON. VT100- DC1/DC3 . xterm(1) ( VT100) BEL, BS, HT, LF, VT, FF, CR, SO, SI, ESC. VT100, Linux: ESC N SS2 Single shift 2. (Select G2 character set for the next character only.) ESC O SS3 Single shift 3. (Select G3 character set for the next character only.) ESC P DCS ( ESC \) ESC X SOS ESC ^ PM ( ESC \) ESC \ ST ESC * ... G2 ESC + ... G3 The program xterm(1) (in VT100 mode) recognizes ESC c, ESC # 8, ESC >, ESC =, ESC D, ESC E, ESC H, ESC M, ESC N, ESC O, ESC P ... ESC \, ESC Z (it answers ESC [ ? 1 ; 2 c, "I am a VT100 with advanced video option") and ESC ^ ... ESC \ with the same meanings as indicated above. It accepts ESC (, ESC ), ESC *, ESC + followed by 0, A, B for the DEC special character and line drawing set, UK, and US-ASCII, respectively. xterm(1) , VT220, VT52, VT100 , . ESC ] (OSC). (ST) ECMA-48, xterm(1) OSC- BEL. OSC, xterm(1): ESC ] 0 ; txt ST txt ESC ] 1 ; txt ST txt ESC ] 2 ; txt ST txt ESC ] 4 ; num; txt ST ANSI num txt ESC ] 10 ; txt ST txt ESC ] 4 6 ; name ST Change log file to name (normally disabled by a compile-time option). ESC ] 5 0 ; fn ST fn. ( , VT100/VT220): ESC 7 DECSC ESC 8 DECRC ESC F Cursor to lower left corner of screen (if enabled by xterm(1)'s hpLowerleftBugCompat resource). ESC l ( HP) ESC m ( HP) ESC n LS2 G2 ESC o LS3 G3 ESC | LS3R G3 GR ESC } LS2R G2 GR ESC ~ LS1R G1 GR ESC % UTF-8 Linux. CSI xterm(1), X11R5, SGR SGR. , ANSI, XFree86 3.1.2A 1995 , . xterm SGR , SGR. X11R6 SGR X11R6.8, XFree86 xterm. CSI ECMA-48 CSI, Linux, xterm, xterm(1) ECMA-48 DEC, Linux. xterm(1) - DEC, , - Linux. - xterm(1) Xterm, Edward Moy, Stephen Gildea Thomas E. Dickey X. , . xterm. vttest . xterm(1) , . ESC 8 (DECRC) , ESC %. In Linux 2.0.23, CSI is broken, and NUL is not ignored inside escape sequences. Some older kernel versions (after Linux 2.0) interpret 8-bit control sequences. These "C1 controls" use codes between 128 and 159 to replace ESC [, ESC ] and similar two-byte control sequence initiators. There are fragments of that in modern kernels (either overlooked or broken by changes to support UTF-8), but the implementation is incomplete and should be regarded as unreliable. "-" Linux ECMA-48 -. , ] . OSC ( ) -- , xterm(1) , (ST). setterm(1), ( ), xterm(1) ( return ). , Linux, xterm(1) brokenLinuxOSC true. , Linux ECMA-48 . . . ioctl_console(2), charsets(7) Azamat Hackimov , Dmitriy S. Seregin , Dmitry Bolkhovskikh , Katrin Kutepova , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 28 2024 . console_codes(4)