READ * Command for Terminals

If the terminal has ESCAPE sequencing enabled, and the input contains a valid escape sequence or a terminator character, the terminal device driver stores the entire sequence in $ZB and returns the ASCII representation of the first character.

Example:

    GTM> KILL
    GTM> USE $P:ESCAPE
    GTM> READ *X SET ZB=$ZB ZWRITE
    (Press the F11 key on the VT220 terminal keyboard)
    x=27
    zb=$C(27)_"[23~"
    

This enters an escape sequence in response to a READ *. The READ * assigns the code for <ESC> to the variable X. The terminal handler places the entire escape sequence in $ZB. Because some of the characters are not graphic, that is, visible on a terminal, the example transfers the contents of $ZB to the local variable ZB and uses a ZWRITE so that the non-graphic characters appear in $CHAR() format.

The READ * command for terminals does not affect $ZB when escape sequencing is not enabled. If the input contains a valid escape sequence and escape sequencing is not enabled, the variable for the READ * command returns the first character of the escape sequence, for example, ASCII 27. The terminal device driver stores the remaining characters of the escape sequence in the read buffer. A READ command following a READ * command returns the remaining characters of the escape sequence. An application that operates with NOESCAPE must provide successive READ * commands to remove the remaining escape characters from the buffer.

Example:

    GTM> KILL
    GTM> USE $P:(NOESCAPE:TERM=$C(13))
    GTM> READ *X SET ZB=$ZB READ Y:0 ZWRITE
    (Press the F11 key on the terminal keyboard)
    [23~i=5
    x=27
    y="[23~"
    zb=""
    GTM> USE $P:NOECHO READ *X S ZB=$ZB READ Y:0 USE $P:ECHO ZW
    i=5
    x=27
    y="[23~"
    zb=""
    GTM> READ *X SET ZB=$ZB USE $P:FLUSH READ Y:0 ZWRITE
    i=5
    x=27
    y=""
    zb=""    
    

While the first READ Y:0 picks up the sequence after the first character, notice how the graphic portion of the sequence appears on the terminal – this is because the READ *X separated the escape character from the rest of the sequence thus preventing the terminal driver logic from recognizing it as a sequence, and suppressing its echo. The explicit suppression of echo removes this visual artifact. In the case of the final READ *X, the FLUSH clears the input buffer so that it is empty by the time of the READ Y:0.