Skip to content

Instantly share code, notes, and snippets.

@czipperz
Last active November 16, 2021 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save czipperz/e177dee0d1dcb8db6a85fdcacb6fc696 to your computer and use it in GitHub Desktop.
Save czipperz/e177dee0d1dcb8db6a85fdcacb6fc696 to your computer and use it in GitHub Desktop.
Virtual Terminal Sequences in a condenced table.

Reference: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences

Format

<n>,<x>,<y> are bounded to [1, 32767], defaults to 1 if not specified.
<m> defaults to 0 if not specified.
<b> defaults to the current viewport height.
<h> is a hex number between 0 and ff

<o> can be: 0 -- erases from current cursor position to end
            1 -- erases from start to current cursor position
            2 -- erases from start to end
<o> defaults to 0 if not specified.

<ns> is a series of <n> of the form (<n> ; <n> ; ...) between 0 and 16 parameters.
     No parameters an a single 0 parameter are equivalent.
     See Graphics Rendition Codes section.

ESC = 0x1b
BEL = 0x7
<ST> = ESC \ or BEL

Output Sequences

ESC M                Reverse Index
ESC 7                Save Cursor Position
ESC 8                Restore Cursor Position
ESC =                Enable numlock (7 = Home)
ESC >                Disable numlock (7 = 7)
ESC H                Set Tab Stop at Column

ESC [ s              Save Cursor
ESC [ u              Restore Cursor

ESC [ <n> A          Cursor Up
ESC [ <n> B          Cursor Down
ESC [ <n> C          Cursor Forward
ESC [ <n> D          Cursor Backward
ESC [ <n> E          Cursor Down Lines
ESC [ <n> F          Cursor Up Lines
ESC [ <n> G          Cursor Set Column
ESC [ <n> d          Cursor Set Row
ESC [ <n> l          Cursor Forward to Tabstop
ESC [ <n> Z          Cursor Backwards to Tabstop
ESC [ <n> S          Scroll Up
ESC [ <n> T          Scroll Down

ESC [ <m> @          Insert Character (insert n spaces shifting to right text after)
ESC [ <m> P          Delete Character (shift left n characters)
ESC [ <m> X          Erase Character (overwrite n characters with space)
ESC [ <m> L          Insert Line (shift down lines below n times)
ESC [ <m> M          Delete Line (delete n lines and shift up lines below them)
ESC [ <o> J          Erase in Display (the part specified by o)
ESC [ <o> K          Erase in Line (the part specified by o)

ESC [ 6 n            Report Cursor Position (term should print ESC [ <y> ; <x> R)
ESC [ 0 c            Report Device Attributes (term should print ESC [ ? 1 ; 0 c)
ESC [ 0 g            Clear Tab Stop at Column
ESC [ 3 g            Clear All Tab Stops

ESC [ <y> ; <x> H    Cursor Set Position
ESC [ <y> ; <x> f    Cursor Set Position
ESC [ <n> ; <b> r    Set Scrolling Region between n and b (row numbers).

ESC [ <ns> m         Set Graphics Rendition (series of commands to change how future characters are rendered)

ESC [ ? 12 h         Start Blinking
ESC [ ? 12 l         Stop Blinking
ESC [ ? 25 h         Show Cursor
ESC [ ? 25 l         Hide Cursor
ESC [ ? 1 h          Enable numlock (7 = Home)
ESC [ ? 1 l          Disable numlock (7 = 7)
ESC [ ? 3 h          Set Number of Columns to 132
ESC [ ? 3 l          Set Number of Columns to 80
ESC [ ? 1049 h       Use Alternate Screen Buffer (inside a graphical app like vim)
ESC [ ? 1049 l       Use Main Screen Buffer (shell)

ESC [ ! p            Soft Reset (visibility, numlock, scrolling region, character set, graphics rendition, saved cursor position)

ESC ] 0 ; <string> <ST>      Set Window Title to string
ESC ] 2 ; <string> <ST>      Set Window Title to string

ESC ] 4 ; <i> ; rgb : <h> / <h> / <h> <ST>       Set color i to the rgb value

ESC ( 0              Designate Character Set as DEC (line art)
ESC ( B              Designate Character Set as ASCII (text)

Graphics Rendition Codes

0      Default
1      Enable Bold
22     Disable Bold
4      Enable Underline
24     Disable Underline
7      Enable Reverse
27     Disable Reverse
3*     Foreground Color
4*     Background Color
9*     Bright Foreground Color
10*    Bright Background Color

Colors:

0      Black
1      Red
2      Green
3      Yellow
4      Blue
5      Magenta
6      Cyan
7      White
8      Extended
9      Default

Extended color format: (unclear if terminated or just stop when no longer a digit)

*8 ; 2 ; <n> ; <n> ; <n>      RGB Color (unclear if hex or numeric)
*8 ; 5 ; <n>                  Index Color (88 or 256 color table)

Input Sequences

0x7f                 Backspace
0x1a                 Pause
0x1b                 Escape
0x00                 Ctrl + Space

ESC [ A              Up Arrow
ESC [ B              Down Arrow
ESC [ C              Right Arrow
ESC [ D              Left Arrow
ESC [ H              Home
ESC [ F              End

ESC [ 1 ; 5 A        Ctrl + Up Arrow
ESC [ 1 ; 5 B        Ctrl + Down Arrow
ESC [ 1 ; 5 C        Ctrl + Right Arrow
ESC [ 1 ; 5 D        Ctrl + Left Arrow

ESC [ 2 ~            Insert
ESC [ 3 ~            Delete
ESC [ 5 ~            Page Up
ESC [ 6 ~            Page Down

ESC O P              F1
ESC O Q              F2
ESC O R              F3
ESC O S              F4
ESC [ 1 5 ~          F5
ESC [ 1 7 ~          F6
ESC [ 1 8 ~          F7
ESC [ 1 9 ~          F8
ESC [ 2 0 ~          F9
ESC [ 2 1 ~          F10
ESC [ 2 2 ~          F11
ESC [ 2 3 ~          F12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment