11.2.2 Defining Terminal Escape Sequences

The second section of termset defines escape sequences sent to the terminal by the computer to perform a particular function. This section repeats several of the functions mentioned in the first section along with additional terminal functions. These functions should be specified in the same manner (i.e., by typing the escape sequence necessary to perform the function, and then typing the delimiter), however they require a technical knowledge of the terminal itself, and thus are usually entered only by the system administrator.

Any of the escape sequences entered can have 'padding' specified for the escape sequence. Some terminals require such delays when performing operations such as CLEAR ENTIRE SCREEN or HOME CURSOR. This delay is specified by preceding the escape sequence with a number that represents the number of milliseconds of delay.

Note that the sequence sent to perform a function does not have to match what is received when a certain key is pressed. In the first section, the escape sequence sent when the Home key is pressed is defined. In the second section, the escape sequence to home the cursor is defined. These two sequences do not have to be identical. Splitting the terminal escape sequence definitions in this way can be very useful when the terminal does not respond in the desired way to a particular special key. For example, on some terminals, homing the cursor sends it to the lower left corner of the terminal screen rather than to the upper left corner. The escape sequence for performing HOME CURSOR can instead be defined as the sequence to move the cursor to the upper left corner rather than issuing the home cursor escape sequence. This would be done by literally typing each keystroke necessary for the escape sequence. After the entire sequence has been entered, it is terminated with the delimiter.

As an example, the HOME CURSOR escape sequence on a DEC VT100 terminal is ESC [ H which means you would press the Escape key, followed by the Open Bracket key, and, finally, the H key. As this is done, the terminal screen would display the characters:


after which you would hold down the Control key and press the X key (or the key you specified as the delimiter when termset was invoked) in order to terminate the definition of the HOME CURSOR escape sequence.

The termset program may ask for functions that cannot be performed by the terminal. In that case, simply respond by keying the delimiter as was done in the previous section. Additionally, several of the functions in this section require further explanation, and this is given in the following paragraphs.

The INITIALIZE TERMINAL function is sent at the beginning of every program that uses the terminal escape sequences. It is not meant to perform a terminal reset function or to clear the screen. Rather, it is intended to perform special terminal functions such as enabling terminal function keys, or setting a particular terminal mode which might be necessary before any of the other special escape sequences are used. RESTORE TERMINAL is used at the end of each of these same programs to reverse whatever INITIALIZE TERMINAL might have done.

SCROLL SCREEN UP moves the contents of the screen up one line and leaves a blank line at the bottom. SCROLL SCREEN DOWN moves the contents of the screen down one line and leaves a blank line at the top. The location of the cursor after either of these two functions is performed is undefined. If the terminal does not have a scroll up escape sequence, it can be imitated by moving to the last line of the display and performing a line feed. It also can be imitated by moving to the top line of the display and deleting one line. The SCROLL SCREEN DOWN can be imitated by positioning to the top of the display and inserting one line.

HOME CURSOR always sends the cursor to the upper left-hand corner of the screen.

This section of termset also defines the escape sequences necessary for terminal display attributes. A brief description of how the various C/Base programs use these display attribute functions is included in the final section of this chapter; also see C/Base Utilities Manual Chapter 2, Terminal Independent I/O for more information.

When keying in a terminal escape sequence, there is no means provided for erasing characters. Since all characters are valid for defining escape sequences, no characters other than the delimiter have any special meaning to termset at this point. Therefore, if an error is made, another cycle through termset must be made, and the incorrect escape sequence must be retyped.