Skip to content

VT100 Escape Codes

Peter Wilson edited this page May 3, 2023 · 16 revisions

VT100/ANSI escape codes interpreted by the libvdu.asm library are summarised on this page. Note that I've not been able to find a concise definition of the behaviour of some of these commands and so the implementation may differ from other emulations. In particular I can find no clear definition of how the scrollable region interacts with other command, for example whether clearing the screen clears the region.

The best reference for these escape sequences would (probably) be ECMA-48, 1991. In practice that's a weighty tome so the best usable references I've found are this Wikipedia article and the VT220 manual. At some point I hope to go through ECMA-48 and make sure what I'm doing is correct.

In the following sequences, representations displayed as n represents potentially multi-character decimal values.

Note in the following table CSI represents the 0x9b 8 bit control character. The emulation will accept both CSI and the 7 bit, two character equivalent of ESC [.

Sequence Description
TAB (0x09) Move the cursor to the next tab position within the page. By default tabs are every 8th character. (1)
LF (0x0A) Line Feed (CTRL-J) - move cursor down one line leaving column unchanged, scroll if required and within the scroll region.
FF (0x0C) Form Feed. Clear screen and return cursor to home position.
CR (0x0D) Carriage return (CTRL-M) - move cursor to the start of the current line
ESC 7 Save current cursor position
ESC 8 Restore cursor to saved position (default to Home if not save)
ESC M Move the cursor up one line. If, prior to the move, the cursor is at the top of the scroll region then scroll the region down one line
ESC D Move the cursor down one line. If, prior to the move, the cursor is at the bottom of the scroll region then scroll the region up one line
CSI n A Move cursor up n lines. If n is missing then default to 1. Do not scroll off the top of the scrollable region (ESC M is an alternative that will scroll)
CSI n B Move cursor down n lines. If cursor starts within scrollable region then scroll as necessary. If n is missing then default to 1.
CSI n C Move cursor right n characters. If n is missing then default to 1.
CSI n D Move cursor left n characters. If n is missing then default to 1.
CSI J Erase from current cursor position to end of screen (including current position)
CSI 1 J Erase from start of screen to current cusor position (incliding current position)
CSI 2 J Erase entire screen and move cursor to home position.
CSI K Erase from start of current line to cursor position, including current position
CSI 1 K Erase from current cursor position to end of line, including current position
CSI 2 K Erase entire line (don't change cursor position
CSI n L Inserts n lines at the cursor. If fewer than n lines remain from the current line to the end of the scrolling region, the number of lines inserted is the lesser number. Lines within the scrolling region at and below the cursor move down. Lines moved past the bottom margin are lost. The cursor is reset to the first column. This sequence is ignored when the cursor is outside the scrolling region.
CSI n M Deletes n lines starting at the line with the cursor. If fewer than n lines remain from the current line to the end of the scrolling region, the number of lines deleted is the lesser number. As lines are deleted, lines within the scrolling region and below the cursor move up, and blank lines are added at the bottom of the scrolling region. The cursor is reset to the first column. This sequence is ignored when the cursor is outside the scrolling region.
CSI n @ Insert n blank characters at the cursor position. The cursor does not move and remains at the beginning of the inserted blank characters. A parameter of 0 or 1 inserts one blank character. Data on the line is shifted forward as in character insertion.
CSI n P Deletes n characters starting with the character at the cursor position. When a character is deleted, all characters to the right of the cursor move to the left. This creates a space character at the right margin for each character deleted. The spaces created at the end of the line are filled with spaces.
CSI ln;col H
Move current cursor position to the line and column address specified.
CSI n S Scroll whole screen up n lines (default 1). Ignores scroll region.
CSI n T Scroll whole screen down n lines (default 1). Ignores scroll region.
CSI top;bot r Define the scrollable regions to be between of the top and bot lines inclusive of both values. The minimum scrollable region is two lines so b must be at least one greater that t.
CSI 4  h Selects insert mode. New display characters move old display characters to the right. Characters moved past the right margin are lost.
CSI 4  l Selects replacement mode. New display characters replace old display characters at the cursor position. The old character is erased. (lowercase 'L')
CSI a m Set character attributes. The ONLY SUPPORTED attribute value is 7 - switching ON inverse video.
CSI 0 m Normal video (reset attributes)
CSI ? 25 h Show the cursor
CSI ? 25 h Hide the cursor

Notes

  1. Although the ANSI/VT100 definitions allow for use defined tab positions, this is not currently implemented.