Seth Woolley's Man Viewer

console_codes(4) - console_codes, console_codes - Linux console escape and control sequences - man 4 console_codes

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

CONSOLE_CODES(4)           Linux Programmer's Manual          CONSOLE_CODES(4)

       console_codes - Linux console(4,n) escape and control sequences

       The   Linux  console(4,n)  implements  a  large  subset  of  the  VT102  and
       ECMA-48/ISO 6429/ANSI X3.64 terminal controls,  plus  certain  private-
       mode  sequences  for changing the color palette, character-set mapping,
       etc.  In the  tabular  descriptions  below,  the  second  column  gives
       ECMA-48  or  DEC  mnemonics  (the  latter if(3,n) prefixed with DEC) for the
       given function.  Sequences without a mnemonic are neither  ECMA-48  nor

       After  all  the normal output processing has been done, and a stream of
       characters arrives at the console(4,n) driver for actual printing, the first
       thing  that  happens is a translation from the code used for processing
       to the code used for printing.

       If the console(4,n) is in(1,8) UTF-8 mode, then  the  incoming  bytes  are  first
       assembled  into  16-bit  Unicode  codes.  Otherwise each byte is trans-
       formed according to the current mapping table (which translates it to a
       Unicode value).  See the CHARACTER SETS section below for discussion.

       In the normal case, the Unicode value is converted to a font index, and
       this is stored in(1,8) video memory, so that  the  corresponding  glyph  (as
       found  in(1,8)  video ROM) appears on the screen.  Note that the use of Uni-
       code (and the design of the PC hardware) allows us to use 512 different
       glyphs simultaneously.

       If  the  current  Unicode  value is a control character, or we are cur-
       rently processing an escape sequence, the value will treated specially.
       Instead  of  being turned into a font index and rendered as a glyph, it
       may trigger cursor movement or other control functions.  See the  LINUX
       CONSOLE CONTROLS section below for discussion.

       It  is  generally not good practice to hard-wire terminal controls into
       programs.  Linux supports a terminfo(5) database of terminal  capabili-
       ties.   Rather than emitting console(4,n) escape sequences by hand, you will
       almost always want to use a terminfo-aware screen  library  or  utility
       such as ncurses(3), tput(1), or reset(1,7,1 tput)(1).

       This  section describes all the control characters and escape sequences
       that invoke special functions (i.e. anything other than writing a glyph
       at the current cursor location) on the Linux console.

   Control characters
       A  character is a control character if(3,n) (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(7,n,1 builtins)  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(1,8) UTF-8 mode all codes  00-1f
       are  regarded as control characters, regardless of any `display control
       characters' mode.

       If we have a control character, it is acted upon immediately  and  then
       discarded  (even  in(1,8)  the  middle of an escape sequence) and the escape
       sequence continues with the next character.  (However, ESC starts a new
       escape  sequence,  possibly aborting a previous unfinished one, and CAN
       and SUB abort(3,7) any escape sequence.)  The recognized control  characters
       are  BEL, BS, HT, LF, VT, FF, CR, SO, SI, CAN, SUB, ESC, DEL, CSI. They
       do what one would expect:

       BEL (0x07, ^G) beeps;

       BS (0x08, ^H) backspaces one column (but not past the beginning of  the

       HT  (0x09,  ^I)  goes to the next tab stop or to the end of the line if(3,n)
              there is no earlier tab stop;

       LF (0x0A, ^J), VT (0x0B, ^K) and FF (0x0C, ^L) all give a linefeed;

       CR (0x0D, ^M) gives a carriage return;

       SO (0x0E, ^N) activates the G1 character set(7,n,1 builtins), and if(3,n)  LF/NL  (new  line
              mode) is set(7,n,1 builtins) also a carriage return;

       SI (0x0F, ^O) activates the G0 character set(7,n,1 builtins);

       CAN (0x18, ^X) and SUB (0x1A, ^Z) interrupt escape sequences;

       ESC (0x1B, ^[) starts an escape sequence;

       DEL (0x7F) is ignored;

       CSI (0x9B) is equivalent to ESC [.

   ESC- but not CSI-sequences
       ESC c     RIS      Reset.
       ESC D     IND      Linefeed.
       ESC E     NEL      Newline.
       ESC H     HTS      Set tab stop at current column.
       ESC M     RI       Reverse linefeed.
       ESC Z     DECID    DEC private identification. The kernel
                          returns the string(3,n)  ESC [ ? 6 c, claiming
                          that it is a VT102.
       ESC 7     DECSC    Save current state (cursor coordinates,
                          attributes, character sets pointed at by G0, G1).
       ESC 8     DECRC    Restore state most recently saved by ESC 7.
       ESC [     CSI      Control sequence introducer
       ESC %              Start sequence selecting character set(7,n,1 builtins)
       ESC % @               Select default (ISO 646 / ISO 8859-1)
       ESC % G               Select UTF-8
       ESC % 8               Select UTF-8 (obsolete)
       ESC # 8   DECALN   DEC screen alignment test - fill screen with E's.
       ESC (              Start sequence defining G0 character set(7,n,1 builtins)
       ESC ( B               Select default (ISO 8859-1 mapping)
       ESC ( 0               Select vt100 graphics mapping
       ESC ( U               Select null mapping - straight to character 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   Set numeric keypad mode
       ESC =     DECPAM   Set application keypad mode
       ESC ]     OSC      (Should be: Operating system command)
                          ESC ] P nrrggbb: set(7,n,1 builtins) palette, with parameter
                          given in(1,8) 7 hexadecimal digits after the final P :-(.
                          Here n is the color (0-15), and rrggbb indicates
                          the red/green/blue values (0-255).
                          ESC ] R: reset(1,7,1 tput) palette

   ECMA-48 CSI sequences
       CSI  (or  ESC  [) is followed by a sequence of parameters, at most NPAR
       (16), that are decimal numbers separated by  semicolons.  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(2,n,1 builtins)  and  this
       entire  sequence  is ignored. (The idea is to ignore an echoed function

       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(1,8) 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.
       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 the current line.
       X   ECH       Erase the indicated # of characters on the 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(1,3x,3x clrtobot) tab stop at the 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(1,3x,3x clrtobot) all LEDs
                     ESC [ 1 q: set(7,n,1 builtins) Scroll Lock LED
                     ESC [ 2 q: set(7,n,1 builtins) Num Lock LED
                     ESC [ 3 q: set(7,n,1 builtins) 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(1,8) current row.

   ECMA-48 Set Graphics Rendition
       The ECMA-48 SGR sequence ESC [ <parameters> m sets display  attributes.
       Several attributes can be set(7,n,1 builtins) in(1,8) the same sequence.

       par   result
       0     reset(1,7,1 tput) all attributes to their defaults
       1     set(7,n,1 builtins) bold
       2     set(7,n,1 builtins) half-bright (simulated with color on a color display)
       4     set(7,n,1 builtins) underscore (simulated with color on a color display)
             (the colors used to simulate dim or underline are set(7,n,1 builtins)
             using ESC ] ...)
       5     set(7,n,1 builtins) blink
       7     set(7,n,1 builtins) reverse video
       10    reset(1,7,1 tput) selected mapping, display control flag,
             and toggle meta flag.

       11    select(2,7,2 select_tut) null mapping, set(7,n,1 builtins) display control flag,
             reset(1,7,1 tput) toggle meta flag.
       12    select(2,7,2 select_tut) null mapping, set(7,n,1 builtins) display control flag,
             set(7,n,1 builtins) toggle meta flag. (The toggle meta flag
             causes the high bit of a byte to be toggled
             before the mapping table translation is done.)
       21    set(7,n,1 builtins) normal intensity (this is not compatible with ECMA-48)
       22    set(7,n,1 builtins) normal intensity
       24    underline off
       25    blink off
       27    reverse video off
       30    set(7,n,1 builtins) black foreground
       31    set(7,n,1 builtins) red foreground
       32    set(7,n,1 builtins) green foreground
       33    set(7,n,1 builtins) brown foreground
       34    set(7,n,1 builtins) blue foreground
       35    set(7,n,1 builtins) magenta foreground
       36    set(7,n,1 builtins) cyan foreground
       37    set(7,n,1 builtins) white foreground
       38    set(7,n,1 builtins) underscore on, set(7,n,1 builtins) default foreground color
       39    set(7,n,1 builtins) underscore off, set(7,n,1 builtins) default foreground color
       40    set(7,n,1 builtins) black background
       41    set(7,n,1 builtins) red background
       42    set(7,n,1 builtins) green background
       43    set(7,n,1 builtins) brown background
       44    set(7,n,1 builtins) blue background
       45    set(7,n,1 builtins) magenta background
       46    set(7,n,1 builtins) cyan background
       47    set(7,n,1 builtins) white background
       49    set(7,n,1 builtins) default background color

   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(1,3x,1 builtins) 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(1,8) ECMA-48.  We list the Set Mode sequences;
       the Reset Mode sequences are obtained by replacing  the  final  `h'  by

       ESC [ ? 1 h
              DECCKM  (default  off):  When set(7,n,1 builtins), the cursor keys send(2,n) 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(4,n) video card.

       ESC [ ? 5 h
              DECSCNM (default off): Set reverse-video mode.

       ESC [ ? 6 h
              DECOM  (default off): When set(7,n,1 builtins), 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 autorepreat on.

       ESC [ ? 9 h
              X10  Mouse  Reporting (default off): Set reporting mode to 1 (or
              reset(1,7,1 tput) to 0) - see below.

       ESC [ ? 25 h
              DECCM (default on): Make cursor visible.

       ESC [ ? 1000 h
              X11 Mouse Reporting (default off): Set reporting mode to  2  (or
              reset(1,7,1 tput) to 0) - see below.

   Linux Console Private CSI Sequences
       The following sequences are neither ECMA-48 nor native VT102.  They are
       native to the Linux console(4,n) driver.  Colors are in(1,8) SGR parameters: 0  =
       black,  1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 = cyan,
       7 = white.

       ESC [ 1 ; n ]       Set color n as the underline color
       ESC [ 2 ; n ]       Set color n as the dim color
       ESC [ 8 ]           Make the current color pair the default attributes.
       ESC [ 9 ; n ]       Set screen blank timeout(1,3x,3x cbreak) to n minutes.
       ESC [ 10 ; n ]      Set bell frequency in(1,8) Hz.
       ESC [ 11 ; n ]      Set bell duration in(1,8) msec.
       ESC [ 12 ; n ]      Bring specified console(4,n) to the front.
       ESC [ 13 ]          Unblank the screen.
       ESC [ 14 ; n ]      Set the VESA powerdown interval in(1,8) minutes.

       The kernel knows about 4 translations of bytes into console-screen sym-
       bols.   The four tables are: a) Latin1 -> PC,  b) VT100 graphics -> PC,
       c) PC -> PC, d) user-defined.

       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.

       These variables G0 and G1 point at a  translation  table,  and  can  be
       changed  by the user. Initially they point at tables a) and b), respec-
       tively.  The sequences ESC ( B and ESC ( 0 and ESC (  U  and  ESC  (  K
       cause G0 to point at translation table a), b), c) and d), respectively.
       The sequences ESC ) B and ESC ) 0 and ESC ) U and ESC ) K cause  G1  to
       point at translation table a), b), c) and d), respectively.

       The  sequence  ESC c causes a terminal reset(1,7,1 tput), which is what you want if(3,n)
       the screen is all garbled. The oft-advised "echo(1,3x,1 builtins) ^V^O" will  only  make
       G0  current,  but there is no guarantee that G0 points at table a).  In
       some distributions there is a program reset(1,7,1 tput)(1)  that  just  does  "echo(1,3x,1 builtins)
       ^[c".   If  your  terminfo entry for the console(4,n) is correct (and has an
       entry rs1=\Ec), then "tput reset(1,7,1 tput)" will also work.

       The user-defined mapping table can be set(7,n,1 builtins) using mapscrn(8).  The result
       of  the mapping is that if(3,n) a symbol c is printed, the symbol s = map[c]
       is sent to the video memory. The bitmap that corresponds to s is  found
       in(1,8) the character ROM, and can be changed using setfont(8).

       The  mouse  tracking  facility  is  intended to return xterm-compatible
       mouse status reports.  Because the console(4,n) driver has no  way  to  know
       the device or type of the mouse, these reports are returned in(1,8) the con-
       sole(4,n) input stream only when the  virtual(5,8)  terminal  driver  receives  a
       mouse  update(7,n)  ioctl.   These ioctls must be generated by a mouse-aware
       user-mode application such as the gpm(8) daemon.

       Parameters for all mouse tracking escape sequences generated  by  xterm
       encode  numeric  parameters  in(1,8)  a  single character as value+040.  For
       example, `!' is 1.  The screen coordinate system is 1-based.

       The X10 compatibility mode sends an escape  sequence  on  button  press
       encoding(3,n)  the  location and the mouse button pressed.  It is enabled by
       sending ESC [ ? 9 h and disabled with ESC [ ? 9 l.   On  button  press,
       xterm  sends ESC [ M bxy (6 characters).  Here b is button-1, and x and
       y are the x and y coordinates of the mouse when the button was pressed.
       This is the same code the kernel also produces.

       Normal  tracking mode (not implemented in(1,8) Linux 2.0.24) sends an escape
       sequence on both button press and  release.   Modifier  information  is
       also  sent.   It is enabled by sending ESC [ ? 1000 h and disabled with
       ESC [ 1000 l.  On button press or release, xterm sends  ESC  [  M  bxy.
       The  low  two bits of b encode button information: 0=MB1 pressed, 1=MB2
       pressed, 2=MB3 pressed, 3=release.  The upper bits  encode  what  modi-
       fiers  were  down  when  the button was pressed and are added together:
       4=Shift, 8=Meta, 16=Control.  Again x and y are the x and y coordinates
       of the mouse event.  The upper left corner is (1,1).

       Many different terminal types are described, like the Linux console(4,n), as
       being `VT100-compatible'.  Here we  discuss  differences  vbetween  the
       Linux  console(4,n)  an  the  two  most  important others, the DEC VT102 and

   Control-character handling
       The vt102 also recognized the following control characters:

       NUL (0x00) was ignored;

       ENQ (0x05) triggered an answerback message;

       DC1 (0x11, ^Q, XON) resumed transmission;

       DC3 (0x13, ^S, XOFF) caused vt100 to ignore (and stop transmitting) all
              codes except XOFF and XON.

       VT100-like DC1/DC3 processing may be enabled by the tty(1,4) driver.

       The  xterm  program  (in(1,8)  vt100 mode) recognizes the control characters
       BEL, BS, HT, LF, VT, FF, CR, SO, SI, ESC.

   Escape sequences
       VT100 console(4,n) sequences not implemented on the Linux console:

       ESC N       SS2   Single shift 2. (Select G2 character set(7,n,1 builtins) for the next
                         character only.)
       ESC O       SS3   Single shift 3. (Select G3 character set(7,n,1 builtins) for the next
                         character only.)
       ESC P       DCS   Device control string(3,n) (ended by ESC \)
       ESC X       SOS   Start of string.
       ESC ^       PM    Privacy message (ended by ESC \)
       ESC \       ST    String terminator

       ESC * ...         Designate G2 character set(7,n,1 builtins)
       ESC + ...         Designate G3 character set(7,n,1 builtins)

       The program xterm (in(1,8) 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(7,n,1 builtins),  UK, and USASCII, respectively.  It
       accepts ESC ] for the setting of certain resources:

       ESC ] 0 ; txt BEL      Set icon name and window title to txt.
       ESC ] 1 ; txt BEL      Set icon name to txt.
       ESC ] 2 ; txt BEL      Set window title to txt.
       ESC ] 4 6 ; name BEL   Change log file(1,n) to name (normally disabled
                              by a compile-time option)
       ESC ] 5 0 ; fn BEL     Set font to fn.

       It recognizes the following with slightly modified meaning:

       ESC 7  DECSC   Save cursor
       ESC 8  DECRC   Restore cursor

       It also recognizes

       ESC F          Cursor to lower left corner of screen (if(3,n) enabled by
                      the hpLowerleftBugCompat resource)
       ESC l          Memory lock (per HP terminals).
                      Locks memory above the cursor.
       ESC m          Memory unlock (per HP terminals).
       ESC n   LS2    Invoke the G2 character set.
       ESC o   LS3    Invoke the G3 character set.
       ESC |   LS3R   Invoke the G3 character set(7,n,1 builtins) as GR.
                      Has no visible effect in(1,8) xterm.
       ESC }   LS2R   Invoke the G2 character set(7,n,1 builtins) as GR.
                      Has no visible effect in(1,8) xterm.
       ESC ~   LS1R   Invoke the G1 character set(7,n,1 builtins) as GR.
                      Has no visible effect in(1,8) xterm.

       It does not recognize ESC % ...

   CSI Sequences
       The xterm program (as of XFree86 3.1.2G) does not recognize  the  blink
       or  invisible-mode  SGRs.  Stock  X11R6  versions  do not recognize the
       color-setting SGRs.  All other  ECMA-48  CSI  sequences  recognized  by
       Linux are also recognized by xterm, and vice-versa.

       The  xterm program will recognize all of the DEC Private Mode sequences
       listed above, but none of the Linux private-mode sequences.   For  dis-
       cussion  of xterm's own private-mode sequences, refer to the Xterm Con-
       trol Sequences document by Edward Moy  and  Stephen  Gildea,  available
       with the X distribution.

       In  2.0.23,  CSI  is  broken,  and  NUL  is  not  ignored inside escape

       console(4,n)(4), console_ioctl(4), charsets(7)

Linux                             1996-10-31                  CONSOLE_CODES(4)

References for this manual (incoming links)