vtterm escape codes
What vtterm.Parser does with each byte and sequence. ESC is \x1b, and
CSI is ESC [. n is a number that defaults to 1, and positions count
from 1. Anything not listed is read and ignored, so a program that sends it
doesn’t break the screen.
Controls
Byte |
Name |
What it does |
|---|---|---|
|
BS |
Cursor left one column |
|
HT |
Cursor to the next tab stop, every 8 columns, or the last column |
|
LF, VT, FF |
Cursor down one row, scrolling at the bottom of the region |
|
CR |
Cursor to column 1 |
|
SO, SI |
Use character set G1, or go back to G0 |
|
CAN, SUB |
Cancel the sequence in progress |
|
BEL |
Ignored |
ESC sequences
Sequence |
What it does |
|---|---|
|
Save and restore the cursor, its pen, origin mode and the character sets |
|
Index: down one row, scrolling at the bottom |
|
Reverse index: up one row, scrolling at the top |
|
Next line: CR and LF |
|
Reset the terminal |
|
Fill the screen with |
|
Make character set G0 or G1 the line-drawing set |
|
Make G0 or G1 ASCII again; so does any other set |
|
Character sets G2 and G3, read and ignored |
|
A string (OSC, DCS and the rest), read up to BEL or |
CSI sequences
Sequence |
What it does |
|---|---|
|
Cursor up |
|
Cursor down |
|
Cursor right |
|
Cursor left |
|
Cursor to column 1, down or up |
|
Cursor to column |
|
Cursor to row |
|
Cursor to row |
|
Erase the display: 0 from the cursor, 1 up to it, 2 all |
|
Erase the row: 0 from the cursor, 1 up to it, 2 all |
|
Erase |
|
Insert or delete |
|
Insert or delete |
|
Scroll the region up or down |
|
Set the scroll region |
|
Save and restore the cursor |
|
Colors and styles (below) |
|
Insert mode on or off |
|
Newline mode: LF also returns to column 1 |
|
Application cursor keys on or off |
|
Origin mode: rows count from the top of the region |
|
Autowrap on or off |
|
Show or hide the cursor |
|
Show or leave the alternate screen: blank on entry, the main screen kept as it was |
|
The same, and the cursor and pen saved on entry and restored on exit |
|
Ask for mouse reports, or stop them |
|
Mouse reports in the SGR form, or the short one |
|
Status report: answers |
|
Cursor position report: answers |
|
Device attributes: answers |
Answers go to the answer function given to Parser; a Terminal keeps
them for Terminal.answers(), and run and Console send them on.
Colors and styles
Code |
What it does |
|---|---|
|
Back to the default colors, no styles |
|
Bold on, off. Bold draws colors 0 to 7 as their bright versions |
|
Underline on, off |
|
Reverse on, off |
|
Foreground: one of the eight colors, or the default |
|
Background: one of the eight colors, or the default |
|
Bright foreground, bright background |
|
Foreground or background: color |
|
24-bit color, kept as the nearest of the 256 |
Characters
Printable ASCII is drawn as is. UTF-8 is decoded, and a character the 8-pixel
fonts don’t have is drawn as the ASCII that looks most like it (box-drawing
lines become -, | and +) or as ?.
The line-drawing set
While G0 or G1 is the DEC line-drawing set and in use, these bytes draw
something else. Every other byte is itself. Both sets start as ASCII, and
ESC c returns them to it.
Byte |
Draws |
|---|---|
|
The corners |
|
The cross |
|
The lines |
|
The tees |
|
A horizontal line at the top of the cell, a quarter down, three quarters down, and at the bottom |
|
A diamond |
|
A checkerboard |
|
A dot in the middle of the cell |
|
Degree and plus-or-minus, as |
|
Less-or-equal and greater-or-equal, as |
|
Pi, not-equal and the pound sign, as |
|
A blank |
In UTF-8, the box-drawing characters U+2500 to U+257F draw the same lines:
light, heavy, double and rounded ones as the single line of the same shape,
dashed ones as solid, and a joint of mixed weights as +. U+25C6 draws the
diamond.
Mouse reports
What vtterm.mouse.mouse_bytes and Mouse send once a program has asked.
Columns and rows count from 1.
Mode |
What is reported |
|---|---|
|
Presses of the left, middle and right buttons |
|
Presses and releases, and the wheel |
|
The same, and each cell the pointer crosses while a button is held |
|
The same, and each cell it crosses with no button held |
The latest of these modes asked for is the one in use, and turning it off stops the reports.
Form |
Bytes |
|---|---|
Short |
|
SGR ( |
|
The button code is 0 for the left button, 1 for the middle, 2 for the right, 64 for the wheel turned away from you and 65 toward you, plus 32 for a move. A move with no button held has code 3 plus 32. A touch is the left button. Shift, Alt and Ctrl aren’t added to the code.