$Y with Terminal I/O
The following table shows the effects of different characters on $Y.
||Effect on $Y
|Any printable ASCII character
The S(ecret) protocol of the OPEN and USE commands turns off echoing. It also prevents $Y from being changed during input, so it indicates the true cursor position.
A WRITE $CHAR() that changes vertical position also changes $Y. A WRITE * that changes vertical position does not change $Y. For example, WRITE $Y,$CHAR(10),$Y performs the line feed and increments $Y. In contrast, WRITE $Y,*10,$Y performs the line feed but does not increment $Y. (See the WRITE command for further details.)
Because WRITE * does not change $Y, you can send a control sequence to your terminal and $Y will still reflect the true cursor position. Since some control sequences do move the cursor, you can use the SET command to set $Y directly. For example, the following commands move the cursor to column 20 and line 10 on a VT100-type terminal and set $X and $Y accordingly:
ANSI standard control sequences (such as escape sequences) that the device acts on but does not output can produce a discrepancy between the $X and $Y values and the true cursor position. To avoid this problem, use the WRITE * statement and specify the ASCII value of each character in the string. For example, instead of using the following code:
use this equivalent form:
As a rule, after any escape sequence that explicitly moves the cursor, you should update $X and $Y to reflect the actual cursor position.