Micro Vibe

My Micro Hobby Projects

  • Increase font size
  • Default font size
  • Decrease font size
Home PropTerm Documents ANSI Protocol

ANSI Protocol


The PropTerm implements a subset of the ANSI Terminal control protocol.  I attempted to support the most commonly used ANSI control sequences, escape codes and control codes.  The terminal supports all the printable ANSI characters (ANSI codes 32..127, 160..255).  Each character cell has a 6 bit text color and a 6 bit background color.  The default terminal software can be altered to support up to 100 characters on a line with up to 50 display lines. The font size is 8 pixels wide and 12 pixels height.

The terminal screen uses a column/row coordinate system.  The upper left of the screen is column = 1, row = 1. The row number increases as it moves down the display and the column number increases as it moves right.

To provide a robust control protocol parameters for ANSI control sequences sent as a double quoted string are not supported.

There are four types of ANSI terminal commands supported by the PropTerm terminal; single character control codes, escape codes, and control sequences and selective control sequences.

ANSI Control Codes:

ANSI control codes are single character terminal commands.  The ANSI characters 0..31, and 128..159 are reserved as non visual control codes.  The PropTerm supports a small number of 7 bit and 8 bit control codes.  Any ANSI control code not implemented by the PropTerm will be ignored.

ANSI Escape Codes:

ANSI escape codes are two character terminal commands where the first character is always the escape control code (ESC, Hex 1B, Dec 27).  The ANSI character following the escape control code is the command identifier.  The PropTerm supports a small number of escape codes.  Any ANSI escape code not implemented by the PropTerm will be ignored.  All 8 bit control codes have an escape code equivalent to allow 8 bit control codes to be accessed using seven bit serial communications. As an example the escape code "Esc@" is control code 128 decimal, "EscA" is control code 129 decimal...

ANSI Control Sequences:

All ANSI control sequences have the same format CSI Param1; Param2; ...ParamN Code.

The CSI, control sequence indicator can be sent to the terminal in two formats.  The 7 bit control code version is an escape code composed of the "Escape" control character followed by the left bracket "[" ANSI character.  The 8 bit control code version  of the CSI is simply the ANSI 8 bit CSI control character.  The PropTerm supports both formats of the CSI.

If the ANSI control sequence supports parameters (ParamX) they immediately follow the CSI.  A parameter is always a decimal number represented as one to three ANSI numeric characters (0..9).  If the control sequence supports more then one parameter each parameter is separated by an ANSI  semicolon (";")character.  If an ANSI control sequence supports a repeat count as its first parameter and the desired repeat count is one, the parameter can be omitted and a repeat count value of one will be assumed.

The Code immediately follows the CSI or the last parameter.  The Codeis always a single ANSI alpha character (@...Z,  a...z) and terminates the ANSI control sequence.  This allows for 53 ANSI control sequences.  Any ANSI control sequence not implemented by the PropTerm will be ignored.

ANSI Selective Control Sequences:

ANSI selective control sequences have the exact same format as ANSI control sequences with one exception, a question mark character proceeds the first parameter position.

All ANSI selective control sequences have the same format CSI ?Param1; Param2; ...ParamN Code.

As with all control sequences no white space characters are allowed.

 ANSI Terminal Commands:

The ANSI terminal commands can be broken down into five main groups.  Follow the link in each of the short descriptions for a list of the supported ANSI terminal commands in the group.

1) ANSI Cursor control codes are used to position the terminal's display cursor. The cursor control codes never modify the displayed information, they only move the display cursor.  Most cursor control sequences support a repeat count as there first parameter.  If the repeat count is not supplied a value of one is assumed.

2) ANSI Scroll control codes are used to set and control a range of display rows as a scrolling region.  An example of some scroll commands are the "set scroll region" and "insert row" ANSI control sequences, and the "LF" control code.  Some ANSI scroll commands only apply to the currently selected scroll region and will have no effect on rows outside the current scroll region.

3) ANSI Terminal control codes act on a global basis.  As an example the "auto line wrap" ANSI control sequence effects the behavior of the terminal when at the end of a display line. The "reset terminal" ANSI escape code is another example of a terminal control code.

4) ANSI Attribute control codes are used to control the presentation of the characters displayed.  As an example the "invert" ANSI control sequence causes all subsequent characters to be displayed in reverse colors from normal. Character color and font set are also controlled by various attribute commands.

5) ANSI Erase control codes are used to erase/blank specified regions of the display.  The erase commands include commands such as; clear screen, clear to end of line, and the erase characters.  The erased area of the display is set to the current default background color and a text space character is written to each character position erased.

6) Font control codes can be used to upload a font glyph, reload the default font, and select one of three custom fonts to load. There is no ANSI control sequence to save the current font in terminal memory. The only way to save the font is to use the PropTerm setup (invoke with WIN-F12).

Last Updated on Friday, 20 February 2009 16:01