Terminal control/Cursor movement: Difference between revisions

m (→‎{{header|C}}: Remove vanity tags)
Line 358:
}
</lang>
 
 
=={{header|Forth}}==
ANS/ISO Forth has a cursor positioning function called AT-XY. The standard language does not define how the cursor is managed however most systems give the programmer direct access to a pair of variables for cursor row and column position.
 
The following example assumes we are using a terminal that accepts ANSI escape codes. It defines the ANSI codes as Forth words with a markup language look. With this code compiled into the Forth system, the commands are used like native Forth commands.
<LANG FORTH>( ANSI terminal control lexicon )
DECIMAL
 
( support routines)
27 CONSTANT ESC
: <##> ( n -- ) ( sends n, radix 10, no spaces)
BASE @ >R 0 <# #S #> TYPE R> BASE ! ;
 
: ESC[ ( -- ) ESC EMIT ." [" ;
 
( ANSI terminal commands as Forth words)
: <CUU> ( row --) ESC[ <##> ." A" ;
: <CUD> ( row --) ESC[ <##> ." B" ;
: <CUF> ( col --) ESC[ <##> ." C" ;
: <CUB> ( col --) ESC[ <##> ." D" ;
: <CPL> ( -- ) ESC[ ." F" ;
: <EL> ( -- ) ESC[ ." K" ;
: <ED> ( -- ) ESC[ ." 2J" ;
: <CUP> ( row col -- ) SWAP ESC[ <##> ." ;" <##> ." H" ;
 
( Define ANSI Forth names for these functions using our markup words)
: AT-XY ( col row -- ) SWAP <CUP> ;
: PAGE ( -- ) <ED> 1 1 <CUP> ;</LANG>
 
 
Anonymous user