(5.12) ANSI Escape Sequences

What ANSI escape sequences can be used?

ANSI escape sequences provide cursor and screen control in OS/2 Warp character mode sessions. By default ANSI support is turned ON (although it may be turned off with the command ANSI OFF). ANSI support is also available in DOS sessions if the device driver ANSI.SYS is loaded. See the online Command Reference for details.

The following ANSI escape sequences are available:

Refers to ASCII code 27 (i.e. the Escape key)
Replace with the appropriate number
Replace with additional attributes, if desired
Escape Code Sequence
Cursor Controls
ESC[#;#H or ESC[#;#f
Moves cursor to line #, column #
Moves cursor up # lines
Moves cursor down # lines
Moves cursor forward # spaces
Moves cursor back # spaces
Reports current cursor line and column
Saves cursor position for recall later
Return to saved cursor position
Erase Functions
Clear screen and home cursor
Clear to end of line
Set Graphics Rendition
Set display attributes where # is
0 for normal display
1 bold on
4 underline (mono only)
5 blink on
7 reverse video on
8 nondisplayed (invisible)
30 black foreground
31 red foreground
32 green foreground
33 yellow foreground
34 blue foreground
35 magenta foreground
36 cyan foreground
37 white foreground
40 black background
41 red background
42 green background
43 yellow background
44 blue background
45 magenta background
46 cyan background
47 white background
Put screen in indicated mode where # is
0 for 40x25 black and white
1 40x25 color
2 80x25 black and white
3 80x25 color
4 320x200 color graphics
5 320x200 black and white graphics
6 640x200 black and white graphics
7 to wrap at end of line
Resets mode # set with above command
Keyboard Reassignments
The first ASCII code defines what is to be changed; the remaining codes define what it is to be changed to; strings are permitted.
ESC[65;81p - A becomes Q
ESC[81;65p - Q becomes A
ESC[0;68;"dir";13p - Assign the F10 key to a DIR command.
The 0;68 portion is the extended ASCII code for the F10 key and 13 is the ASCII code for a carriage return.
Other function key codes: F1=59, F2=60, F3=61, ... F10=68.

You can use ANSI escape sequences in the PROMPT environment variable to create complex command line prompts. See the online Command Reference (under PROMPT) for details.

For example, if you have a color monitor, try editing your CONFIG.SYS file so that

SET PROMPT=$e[32;40m$e[1m[$P]$e[0m

to obtain a more colorful OS/2 Warp command line prompt. (Case is significant in the example given.) You can do the same for your DOS sessions if you edit PROMPT in AUTOEXEC.BAT, assuming you have ANSI.SYS loaded. Note that the $i portion of your PROMPT will enable the help line at the top of the window or screen. It is not included in the example above.

Related information:

(5.10) Clever Tricks

Previous Section, Next Section, Table of Contents.

Converted by IPF2HTML v0.4 on Wed May 10 13:14:33 EDT 1995

The OS/2 Webmasters (os2www@mit.edu)