ANSI ESC Sequences - also called ANSI commands - are useful for doing some display I/O control in REXX.
To use ANSI commands the OS/2 ANSI support must be active. To activate the ANSI support use the OS/2 command ANSI ON and to deactivate the ANSI support use the OS/2 command ANSI OFF. To get the current status of the ANSI support use the OS/2 command ANSI without a parameter. The default for the ANSI support is ON. (see Check if ANSI is active - 1 - or Check if ANSI is active - 2 - for REXX source to detect if ANSI support is active from within a REXX program)
Each ANSI command begins with the sequence ESC[. where ESC represents the ASCII code 1Bh (= 27 decimal). If there is more than one parameter for an ANSI command, use a semicolon (;) to separate the parameter.
To output ANSI commands you can use the functions LINEOUT and CHAROUT or the statement SAY. Example:
say "1B"x || "[30;41m" || "This text is black on red" call lineOut , "1B"x || "[31;40m" || "This text is red on black" call charOut , "1B"x || "[0m" || "This text is in default color"
(see Using ANSI sequences for some sample code using ANSI sequences and RxLBox - menu routine in REXX is a menu program using only ANSI sequences to implement the navigation with cursor keys and function keys)
Note: To use the ANSI commands to set or get the cursor position you must use the function CHAROUT! (see SysCls for another minor restriction)
Further Note: Almost all ANSI Control Characters are documented in the command reference of WARP version 9.99 (Merlin Beta).
ANSI Commands
┌────────────────────┬───────────────────────────────────────────┐ │Command │Function │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[colsA │Cursor up # lines │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[colsB │Cursor down # lines │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[rowsC │Cursor right # columns │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[rowsD │Cursor left # columns │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[row;colH │Position the cursor (the upper left corner │ │ │is 1,1) │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[2J │Clear the whole screen │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[K │Clear the rest of the line │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[6n │Get the current cursor position (see Get │ │ │the current cursor position) │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[row;colf │Position the cursor (like "H") │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[row;colR │Report current cursor line and column (*) │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[=modeh │Set the display mode (see below) │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[=model │Set the display mode (see below) │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[attr;attr;..m │Set the color attribute (see below) │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[key;"str"p │Redefine the key "key" with the string │ │ │"str" (see Key redefinitions and Key Codes │ │ │for key redefinitions) │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[s │Save the current cursor position (nested │ │ │calls are not allowed) │ ├────────────────────┼───────────────────────────────────────────┤ │ESC[u │Restore the cursor position (nested calls │ │ │are not allowed) │ └────────────────────┴───────────────────────────────────────────┘
Display attributes
┌──────────┬────────────────────────────────────────┐ │Attribute │Description │ ├──────────┼────────────────────────────────────────┤ │0 │all attributes off (white on black) │ ├──────────┼────────────────────────────────────────┤ │1 │bold │ ├──────────┼────────────────────────────────────────┤ │2 │normal │ ├──────────┼────────────────────────────────────────┤ │4 │underline (only on b/w displays) │ ├──────────┼────────────────────────────────────────┤ │5 │blink │ ├──────────┼────────────────────────────────────────┤ │7 │reverse video │ ├──────────┼────────────────────────────────────────┤ │8 │invisible │ ├──────────┼────────────────────────────────────────┤ │30-37 │set the foreground color: │ │ │30=Black, 31=Red, 32=Green, 33=Yellow │ │ │34=Blue, 35=Magenta, 36=Cyan, 37=White │ ├──────────┼────────────────────────────────────────┤ │40-47 │set the background color: │ │ │40=Black, 41=Red, 42=Green, 43=Yellow │ │ │44=Blue, 45=Magenta, 46=Cyan, 47=White │ └──────────┴────────────────────────────────────────┘
Display modes
┌──────────┬────────────────────────────────────────┐ │Mode │Description │ ├──────────┼────────────────────────────────────────┤ │0 │Text 40x25 monochrome │ ├──────────┼────────────────────────────────────────┤ │1 │Text 40x25 color │ ├──────────┼────────────────────────────────────────┤ │2 │Text 80x25 monochrome │ ├──────────┼────────────────────────────────────────┤ │3 │Text 80x25 color │ ├──────────┼────────────────────────────────────────┤ │4 │Graphics 320x200 4 colors │ ├──────────┼────────────────────────────────────────┤ │5 │Graphics 320x200 2 color │ ├──────────┼────────────────────────────────────────┤ │6 │Graphics 640x200 2-color │ ├──────────┼────────────────────────────────────────┤ │7 │cursor wrap off (7l) or on (7h) │ └──────────┴────────────────────────────────────────┘