Skip to main content

Programming Your Terminal

Programming Your Terminal

Using InterSystems IRIS to Program Formatted CRT Screens

Several features of Terminal I/O aid in programming formatted screens:

  • Use WRITE * to send control sequences easily.

  • Use READ to receive escape-sequence responses.

  • Use SET $X = expression and SET $Y = expression to update the current cursor position.

Fixed-length READ and programmer-specified termination characters make it convenient to read individual fields. You can use the Secret protocol to make passwords invisible.

Remember that WRITE * does not change $X or $Y. If you want to change them, use WRITE $C(X), or simply set them explicitly.

Example

This example sets the VT100 cursor to line 10, column 20

%SYS>SET DY=10,DX=20
%SYS>WRITE *27,*91,DY+1,*59,DX+1,*72 SET $Y=DY,$X=DX

Use CURRENT^%IS to Set Variables

The utility routine CURRENT^%IS sets some useful local variables to work for the current device. To call this routine, enter:

%SYS>DO CURRENT^%IS

This command sets the variables indicated in the following table.

Features Enabled By CURRENT^%IS
Code Definition
W @FF Clears the screen and moves the cursor to the upper left corner (column 0, line 0) leaving $X=0, $Y=0.
S DX=42,DY=10 X XY Moves the cursor directly to column 42, line 10, leaving $X=42, $Y=10.

Programming Escape Sequences

The ANSI standard for escape sequences makes programming of smart terminals practical. The Escape character and all characters after it in a string do not display on the screen, but do update $X and $Y. Send escape sequences to the terminal with WRITE * statements and keep $X and $Y up to date by setting them directly.

The ANSI standard establishes a standard syntax for escape sequences. The effect of a particular escape sequence depends on the type of terminal you are using.

Look for incoming escape sequences in $ZB after each READ. InterSystems IRIS puts ANSI-standard escape sequences and any others that use the ANSI forms in $ZB. InterSystems IRIS recognizes two forms of escape sequence:

Regular form

  • An ESC.

  • Optionally the character “O” (the letter), decimal value 79.

  • Zero or more characters with decimal values 32–47.

  • One character with decimal value 48–126.

Control form

  • The ESC character, decimal value 27.

  • The “[” character, decimal value 91.

  • Zero or more characters with decimal values 48–63.

  • Zero or more characters with decimal values 32–47.

  • One character with decimal value 64–126.

Furthermore, the sequence can be no longer than 16 characters. Escape sequences that violate these forms or rules set bit 8 of $ZA, whose value is 256.

Example

Assume that you are programming a terminal whose Help key sends the two-character sequence Escape-? (? has a decimal value of 63)

%SYS>SET HELP=$C(27,63)
ASK READ !,"Enter ID: ",X I $ZB=HELP Do GIVEHELP GoTo ASK

Your routine can detect nonstandard escape sequences as follows:

  1. Make ESC a terminator.

  2. When ESC appears in $ZB:

    1. Disable echo with the Secret protocol to prevent modification of $X/$Y.

    2. Read the rest of the sequence with READ *;

    3. Turn off Secret to re-enable echo.

      In the following figure, the user is asked to enter an ID. If the user presses Esc-?, a Help screen appears. The subroutine ESCSEQ assumes that nonstandard escape sequences end with an asterisk “*”.

DEMOS 
  SET HELP=$C(27,63) ;Get Help with <ESC>?
    SET ESC=$C(27) USE 0:("":"":ESC) ; Make <ESC> a READ terminator
                                     ; character
ASK READ !,"Enter ID: ",X I $ZB=ESC Do ESCSEQ G:SEQ=HELP ASK 
    . ;Input ID. Handle Help request. 
    .
    Quit
HELPSCR  ;Process Help request 
    . 
    Quit
ESCSEQ  USE 0:("":"S") SET SEQ=ESC ;Set terminal to no echo,init SEQ 
    FOR I=1:1 {
      READ *Y 
      SET SEQ=SEQ_$C(Y)
      QUIT:Y=42 }
    ; Read in Escape sequence, 
    ; end at "*" 
    USE 0:("":"":ESC) Quit ;Redefine terminator

InterSystems IRIS Supports Full or Half Duplex and Echo

InterSystems IRIS prefers that you use full duplex terminals; in other words, your keyboard should operate independently from your printer or screen.

Full duplex means simultaneous and independent transmission in both directions. Half duplex means transmission in only one direction at a time. Duplex has nothing to do with echo, although you may see a terminal marked full duplex for remote echo and half duplex for local echo. This designation means that the terminal displays the characters you type and does not expect InterSystems IRIS to echo them.

Set your terminal to local echo off or full duplex, letting InterSystems IRIS provide the echo. The echo comes not when the computer receives the character, but when the READ command takes it from the input buffer; therefore, the prompts and answers of a dialog keep their intended positions on the screen regardless of whether the user types ahead.

Some public networks provide their own echo to the terminal.

On Windows systems, consoles do not permit local echo setup changes. For terminals attached via a terminal emulator (e.g., VT220), refer to your terminal emulator documentation for instructions to disable local echo.

On UNIX® systems, use the stty command to avoid double echoes while keeping $X and $Y in agreement with the cursor’s position.

InterSystems IRIS Supports Intercomputer Links and Special Devices

InterSystems IRIS provides flexible protocols and large independent buffers enable routines to deal with unusual devices and their protocols. For example, InterSystems IRIS easily supports full duplex communication between two computers on a terminal-to-terminal link. Two InterSystems IRIS systems require only a physical connection, the right protocols, and identical settings of speed, parity, and character length. With the aid of external converters, InterSystems IRIS communicates with IBM ports as a synchronous EBCDIC terminal.

Keep these points in mind when designing an intercomputer link:

  • Turn off echo at both ends by including the S protocol in OPEN or USE, or by using the operating system’s terminal parameters.

  • Unless your communication protocol supports XON/XOFF flow control (Ctrl-Q and Ctrl-S), be sure it limits unacknowledged transmissions to the limit of the operating system’s input buffering; otherwise you may lose data.

  • In image mode, InterSystems IRIS does not support XON/XOFF. In nonimage (normal) mode, the operating system’s terminal parameters determine whether the computer issues an XOFF if the operating system’s input buffer is almost full. If XOFF and XON are not supported, make the buffer large enough that you do not need them.

  • Test $ZA after read operations to detect transmission errors such as parity or data overrun conditions.

FeedbackOpens in a new tab