Your computer terminals and terminal emulators support color and cursor control through a system of escape sequences. One such standard is commonly referred to as ANSI colour. Several terminal specifications are
Based on the ANSI color standard, including vt100.
The following is a partial listing of the VT100 control set.
<ESC>
Represents the ASCII "escape" character, 0x1b. Bracketed tags represent modifiable decimal parameters; eg.{ROW}
Wocould be replaced by a row number.
Device status
The following codes are used for reporting terminal/display settings, and vary depending on the implementation:
Query Device Code<ESC>[c
- Requests
Report Device Code
Response from the device.
Report Device Code<ESC>[{code}0c
- Generated by the device in response
Query Device Code
Request.
Query Device Status<ESC>[5n
- Requests
Report Device Status
Response from the device.
Report Device OK<ESC>[0n
- Generated by the device in response to
Query Device Status
Request; indicates that device is functioning correctly.
Report Device Failure<ESC>[3n
- Generated by the device in response to
Query Device Status
Request; indicates that device is functioning improperly.
Query Cursor Position<ESC>[6n
- Requests
Report Cursor Position
Response from the device.
Report Cursor Position<ESC>[{ROW};{COLUMN}R
- Generated by the device in response to
Query Cursor Position
Request; Reports current cursor position.
Terminal setup
Theh
Andl
Codes
Are used for setting Terminal/display mode, and vary depending on the implementation. Line wrap is one of the few setup codes that tend to be used consistently:
Reset Device<ESC>c
- Reset all terminal settings to default.
Enable Line Wrap<ESC>[7h
- Text wraps to next line if longer than the length of the display area.
Disable Line Wrap<ESC>[7l
Fonts
Some terminals support multiple fonts: normal/bold, Swiss/italic, etc. There are a variety of special codes for certain terminals; The following are fairly standard:
Font Set G0<ESC>(
Font Set G1<ESC>)
Cursor control
Cursor Home <ESC>[{ROW};{COLUMN}H
- Sets the cursor position where subsequent text will begin. If no row/column parameters are provided (ie.
<ESC>[H
), The cursor will move toHomePosition, at the upper left of the screen.
Cursor Up<ESC>[{COUNT}A
- Moves the cursor upCountRows; the default count is 1.
Cursor Down<ESC>[{COUNT}B
- Moves the cursor downCountRows; the default count is 1.
Cursor Forward<ESC>[{COUNT}C
- Moves the cursorForwardByCountColumns; the default count is 1.
Cursor Backward<ESC>[{COUNT}D
- Moves the cursorBackwardByCountColumns; the default count is 1.
Force Cursor Position<ESC>[{ROW};{COLUMN}f
Save Cursor<ESC>[s
- Save current cursor position.
Unsave Cursor<ESC>[u
- Restores cursor position after
Save Cursor
.
Save Cursor & Attrs<ESC>7
- Save current cursor position.
Restore Cursor & Attrs<ESC>8
- Restores cursor position after
Save Cursor
.
Scrolling
Scroll Screen<ESC>[r
- Enable scrolling for entire display.
Scroll Screen<ESC>[{start};{end}r
- Enable scrolling from row
{start}
To row{end}
.
Scroll Down<ESC>D
- Scroll display down one line.
Scroll Up<ESC>M
- Scroll display up one line.
Tab Control
Set Tab <ESC>H
- Sets a tab at the current position.
Clear Tab <ESC>[g
- Clears tab at the current position.
Clear All Tabs <ESC>[3g
Erasing text
Erase End of Line<ESC>[K
- Erases from the current cursor position to the end of the current line.
Erase Start of Line<ESC>[1K
- Erases from the current cursor position to the start of the current line.
Erase Line<ESC>[2K
- Erases the entire current line.
Erase Down<ESC>[J
- Erases the screen from the current line down to the bottom of the screen.
Erase Up<ESC>[1J
- Erases the screen from the current line up to the top of the screen.
Erase Screen<ESC>[2J
- Erases the screen with the background color and moves the cursorHome.
Printing
Some terminals support local printing:
Print Screen<ESC>[i
- Print the current screen.
Print Line<ESC>[1i
Stop Print Log<ESC>[4i
Start Print Log<ESC>[5i
- Start log; all encoded ed text is echoed to a printer.
Define key
Set Key Definition<ESC>[{key};"{string}"p
- AssociatesStringOf text to a keyboard key.
{key}
Indicates the key by its ASCII value in decimal.
Set display attributes
Set Attribute Mode<ESC>[{attr1};...;{attrn}m
- Sets Multiple display attribute settings. The following lists standard attributes:
0Reset all attributes1Bright2Dim4Underscore5Blink7Reverse8HiddenForeground Colours30Black31Red32Green33Yellow34Blue35Magenta36Cyan37WhiteBackground Colours40Black41Red42Green43Yellow44Blue45Magenta46Cyan47White
Address: http://www.termsys.demon.co.uk/vtansi.htm