Required Functions

In order for the Terminal Manager to run, four functions must be defined for the terminal; all of the remaining functions are optional. These required functions are Cursor-positioning (cm), Clear-screen (cl), Clear-to-end-of-line (ce), and Clear-to-end-of-screen (cd). If these functions are not present when the Terminal Manager tries to run, an error will be printed and the program halted.

The Clear-screen function should clear the entire screen and home the cursor. The clear-to-end-of-line function should clear from the cursor position to the end of the current line. The clear-to-end-of-screen function should clear from the cursor position to the end of the screen.

The Terminal Manager starts by establishing a window that is the size of the screen. By default, a screen size of 24 by 80 is assumed. If this is not correct, you can set the Lines (li) and Columns (co) fields to the correct size. These settings are made with a "#" instead of an "=". For example, if you have a 25-line terminal, the proper setting is li#25.

Continuing with our example, the DEC VT-100 clears the screen by sending an ESC[2J. Unfortunately, this does not home the cursor. This can be accomplished by sending ESC[;H. These can be sent in either order. Clearing to the end of line is done by sending ESC[K and clearing to the end of the screen by ESC[J. The terminal has the default screen dimensions, so we do not need to add the co or li options. Our entry now reads:

vt100|vt-100|DEC VT-100:\
:cl=\E[;H\E[2J:ce=\E[K:cd=\E[J:

Cursor positioning is accomplished by a special encoded form. The program must specify varying information in the control-sequence (the row and column numbers). Special abbreviations are allowed to encode this information. These abbreviations and their meanings are:

%d Inserts the row or column number here in ASCII. For example, row 5 would be inserted here as "5".
%2 Acts like "%d" except that it always prints as two digits. Row 5 is inserted as "05".
%3 Acts like %2 except that three digits are used.
%. Inserts the row or column number here literally. Row 5 would be inserted here as a decimal 5 (ASCII control-E). Note that if this type is used, then Cursor-up (up) and Backspace-cursor (bc) must also be defined.
%+x      Acts like "%." except that x is added to the row or column number first. If the sequence were "%+  " (note the trailing space), then row 5 would be inserted here as the sum of the space character and 5, "%" in ASCII. This form is quite common.
%>xy This does not insert anything in the string. If the row or column number is greater then x, then y is added, otherwise this has no effect.
%r Normally the row is inserted first, and then the column. This reverses the order.
%i Normally the row and column numbers are relative to zero. Including this causes them to be relative to 1.
%% Sends a literal "%".

For example, the ADM-3A terminal positions the cursor by sending an ESC= followed by the row and column offset by a space character. The code for this is \E=%+  %+   (note spaces).

The VT-100 positions the cursor by sending an ESC[ followed by the row, a semicolon, the column and then an "H". The row and column are sent as ASCII strings and the home position is row 1, column 1. The correct string is \E[%i%d;%dH.

vt100|vt-100|DEC VT-100 :\
:cl=\E[;H\E[2J:ce=\E[K:cd=\E[J:\
:cm=\E[%i%d;%dH: