Console ESC-Codes
Aus Si:Wiki von Siegrist SystemLösungen - Informatik und Rezepte
Version vom 12. Mai 2021, 17:23 Uhr von Sigi (Diskussion | Beiträge) (Die Seite wurde neu angelegt: « :Terminal Codes und Steuersequenzen sowie bestimmte Sequenzen im privaten Modus zum Ändern der Farbpalette, der Zeichensatzzuordnung usw. für die Linux Consol…»)
- Terminal Codes und Steuersequenzen sowie bestimmte Sequenzen im privaten Modus zum Ändern der Farbpalette, der Zeichensatzzuordnung usw. für die Linux Console. Alle beginnen sie mit einem ESC[ also einem \033[
- Zum Beispiel:
echo -e "\033[2J\033[16;43H\033[36;1mHallo\033[00m"
- - löscht den Bildschirm ( \033[2J )
- - positioniert den Cursor Zeile 16 / Reihe 3 ( \033[16;43H )
- - färbt nachfolgenden Text Cyan Fett ( \033[36;1 )
- - schreibt das Wort Hallo
- - setzt die Formatierung Cyan/Fett wieder zurück ( \033[00m )
ECMA-48 CSI sequences
CSI (or ESC [) is followed by a sequence of parameters, at most NPAR (16), that are decimal numbers separated by semicol ons. An empty or absent parameter is taken to be 0. The sequence of parameters may be preceded by a single question mark .
However, after CSI [ (or ESC [ [) a single character is read and this entire sequence is ignored. (The idea is to ignore an echoed function key.)
The action of a CSI sequence is determined by its final character. @ ICH Insert the indicated # of blank characters. A CUU Move cursor up the indicated # of rows. B CUD Move cursor down the indicated # of rows. C CUF Move cursor right the indicated # of columns. D CUB Move cursor left the indicated # of columns. E CNL Move cursor down the indicated # of rows, to column 1. F CPL Move cursor up the indicated # of rows, to column 1. G CHA Move cursor to indicated column in current row. H CUP Move cursor to the indicated row, column (origin at 1,1). J ED Erase display (default: from cursor to end of display). ESC [ 1 J: erase from start to cursor. ESC [ 2 J: erase whole display. ESC [ 3 J: erase whole display including scroll-back buffer (since Linux 3.0). K EL Erase line (default: from cursor to end of line). ESC [ 1 K: erase from start of line to cursor. ESC [ 2 K: erase whole line. L IL Insert the indicated # of blank lines. M DL Delete the indicated # of lines. P DCH Delete the indicated # of characters on current line. X ECH Erase the indicated # of characters on current line. a HPR Move cursor right the indicated # of columns. c DA Answer ESC [ ? 6 c: "I am a VT102". d VPA Move cursor to the indicated row, current column. e VPR Move cursor down the indicated # of rows. f HVP Move cursor to the indicated row, column. g TBC Without parameter: clear tab stop at current position. ESC [ 3 g: delete all tab stops. h SM Set Mode (see below). l RM Reset Mode (see below). m SGR Set attributes (see below). n DSR Status report (see below). q DECLL Set keyboard LEDs. ESC [ 0 q: clear all LEDs ESC [ 1 q: set Scroll Lock LED ESC [ 2 q: set Num Lock LED ESC [ 3 q: set Caps Lock LED r DECSTBM Set scrolling region; parameters are top and bottom row. s ? Save cursor location. u ? Restore cursor location. ` HPA Move cursor to indicated column in current row.
ECMA-48 Set Graphics Rendition
The ECMA-48 SGR sequence ESC [ parameters m sets display attributes. Several attributes can be set in the same sequence, separated by semicolons. An empty parameter (between semicolons or string initiator or terminator) is interpreted as a zero.
param result 0 reset all attributes to their defaults 1 set bold 2 set half-bright (simulated with color on a color display) 4 set underscore (simulated with color on a color display) (the colors used to simulate dim or underline are set using ESC ] ...) 5 set blink 7 set reverse video 10 reset selected mapping, display control flag, and toggle meta flag (ECMA-48 says "primary font"). 11 select null mapping, set display control flag, reset toggle meta flag (ECMA-48 says "first alternate font"). 12 select null mapping, set display control flag, set toggle meta flag (ECMA-48 says "second alternate font"). The toggle meta flag causes the high bit of a byte to be toggled before the mapping table translation is done. 21 set underline; before Linux 4.17, this value set normal intensity (as is done in many other terminals) 22 set normal intensity 24 underline off 25 blink off 27 reverse video off 30 set black foreground 31 set red foreground 32 set green foreground 33 set brown foreground 34 set blue foreground 35 set magenta foreground 36 set cyan foreground 37 set white foreground 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 set black background 41 set red background 42 set green background 43 set brown background 44 set blue background 45 set magenta background 46 set cyan background 47 set white background 48 256/24-bit background color follows, shoehorned into 8 basic colors 49 set default background color 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 Mode Switches
ESC [ 3 h DECCRM (default off): Display control chars. ESC [ 4 h DECIM (default off): Set insert mode. ESC [ 20 h LF/NL (default off): Automatically follow echo of LF, VT or FF with CR. ECMA-48 Status Report Commands ESC [ 5 n Device status report (DSR): Answer is ESC [ 0 n (Terminal OK). ESC [ 6 n Cursor position report (CPR): Answer is ESC [ y ; x R, where x,y is the cursor location. DEC Private Mode (DECSET/DECRST) sequences These are not described in ECMA-48. We list the Set Mode sequences; the Reset Mode sequences are obtained by replacing t he final 'h' by 'l'. ESC [ ? 1 h DECCKM (default off): When set, the cursor keys send an ESC O prefix, rather than ESC [. ESC [ ? 3 h DECCOLM (default off = 80 columns): 80/132 col mode switch. The driver sources note that this alone does not suffice; some user-mode utility such as resizecons(8) has to change the hardware registers on the console video card. ESC [ ? 5 h DECSCNM (default off): Set reverse-video mode. ESC [ ? 6 h DECOM (default off): When set, cursor addressing is relative to the upper left corner of the scrolling region. ESC [ ? 7 h DECAWM (default on): Set autowrap on. In this mode, a graphic character emitted after column 80 (or column 132 of DECCOLM is on) forces a wrap to the beginning of the following line first. ESC [ ? 8 h DECARM (default on): Set keyboard autorepeat on. ESC [ ? 9 h X10 Mouse Reporting (default off): Set reporting mode to 1 (or reset to 0)---see below. ESC [ ? 25 h DECTECM (default on): Make cursor visible. ESC [ ? 1000 h X11 Mouse Reporting (default off): Set reporting mode to 2 (or reset to 0)---see below.