CIS 415L Telecommunications and Networking
Instructor: Michael P. Harris
ANSI.SYS Escape Sequences
Download: TheDraw.zip (v4.63)
TheDraw is a powerful screen image file generator
for color and monochrome video users (using ANSI control codes). What does
that mean? Literally, TheDraw makes designing and figuring out a video
screen display ,using ANSI escape characters, childs play.
To obtain local full screen and keyboard control of a remotely connected
terminal or computer in telecommunications a control character oriented
keyboard and screen control system is necessary. This tutorial describes
how the ANSI escape sequences are used in MSDOS. An ANSI escape sequence
is a series of characters, beginning with the Escape character, used
to define functions to MSDOS. You can use these escape sequences
to affect cursor movement, erase information from the screen display,
set the graphics mode, and reassign keys.
There are several ways to execute ANSI escape sequences:
- You can enter them at the MSDOS command line using the PROMPT
command.
- You can create them in a file and then issue them with the TYPE
command.
- You can include escape sequences in your QBASIC/GWBASIC or assembly
language programs.
Before issuing and ANSI escape sequences, you must load the special
device driver ANSI.SYS. To do this, create or edit your CONFIG.SYS
file in the root directory of the MSDOS Boot drive (C:\) and add
the following command to it.
DEVICE=C:\DOS\ANSI.SYS or
DEVICE=C:\WINDOWS\COMMAND\ANSI.SYS
When you restart MSDOS, the ANSI.SYS driver extended screen and keyboard
control driver will be installed
ANSI ESCAPE SEQUENCE SYNTAX:
- Each ANSI escape sequence has the same basic syntax:
- ESC[parameters-command (spaces added for readability)
ESC is the 1 byte code for escape. The escape code is $e at the command
line using PROMPT. In QBASIC or GWBASIC the code for escape is CHR$(27). In
ASCII, ESC is 27 decimal or 1B hexadecimal.
ANSI CURSOR CONTROL FUNCTIONS:
ESC[#;#H - Cursor Position (CUP)
- The first # specifies the line number, the second # specifies
the column. The default for both is 1
ESC[#A - Cursor Up (CUU)
- Moves the cursor UP # number of lines
ESC[#B - Cursor Down (CUD)
- Moves the cursor DOWN # number of lines
ESC[#C - Cursor Forward (CUF)
- Moves the cursor RIGHT # number of columns
ESC[#D - Cursor Backward (CUB)
- Moves the cursor LEFT # number of columns
ESC[#;#f - Horizontal & Vertical Position
- (same as ESC[#;#H)
ESC[s - Save Cursor Position (SCP)
- The current cursor position is saved. The cursor position
can be restored using (RCP) ESC[u.
ESC[u - Restore cursor position (RCP)
- Restores the cursor position saved with the (SCP) sequence
ESC[s.
ESC[2J - Erase Display (ED)
- Clears the screen and moves to the home position
ESC[K - Erase Line (EL)
- Clears the current line from the cursor position
ESC[#;...;#m - Set Graphics Rendition (SGR)
- (optional text may be included in the ...)
The Escape parameters for (SGR) are:
0 All attributes OFF
1 Bold ON
4 Underscore ON (monochrome only)
5 Blink ON
7 Reverse Video ON
8 Concealed ON
30 Black Foreground
31 Red
32 Green
33 Yellow
34 Blue
35 Magenta
36 Cyan
37 White
40 Black Background
41 Red
42 Green
43 Yellow
44 Blue
45 Magenta
46 Cyan
47 White
ESC[=#h Set Mode (SM)
Escape parameters for Set Mode (SM)
0 | 40x25 black& white |
1 | 40x25 color |
2 | 80x25 black & white |
3 | 80x25 color |
4 | 320x200 color |
5 | 320x200 black & white |
6 | 640x200 black & white |
7 | wrap at end of line |
ESC[=#I Reset Mode (RM)
- Uses same parameters as Set Mode (SM)
ESC[=#;#...#p or ESC[string--Keyboard Reasignment
- The first # is the ASCII code for the key being changed,
the second # or "string" is the replacement, with one exception
- if the first # is a NULL then the first and second # represent
the key being reassigned.
EXAMPLES:
PROMPT $e[7m$n$p$e[m | creates a standard prompt $n$g except
in reverse video. |
PROMPT $p$g$e[33;44m | - on a color video, this will set the
prompt to display the directory $p$g and display it in red against
blue. |
ESC[65;81p | - reassigns A to become Q |
ESC[0;68;"DIR";13p | - reassigns the F10 key to DIR + [CR] |
ESC[2J | - clear the screen & home cursor |
ESC[7m | - all subsequent characters in reverse video |
ESC[7;5m | - all subsequent characters reverse and blinking |
ESC[13;40f | - move cursor to center of screen |
ASCII Code-- Extended Key
16 - 25 | ALT Q,W,E,R,T,Y,U,I,O,P |
30 - 38 | ALT A,S,D,F,G,H,J,K,L |
44 - 40 | ALT Z,X,C,V,B,N,M |
59 - 68 | [F1] through [F10] |
84 - 93 | SHIFT[F1] through SHIFT[F10] |
94 - 103 | [F1] through [F10] |
104 - 113 | ALT[F1] through ALT[F10] |
Using the above ASCII Code to Extended Key conversion table and the
ANSI.SYS redefine key syntax:
prompt $e[0;##;"command"p {without trailing ENTER}
or
prompt $e[0;##;"command";13p {with trailing ENTER}
- where ## = the ASCII code of the key to redefine and
- command = the command to assign to the Extended Key
Create a batch file to redefine the following DOS commands
to keyboard keys.
ALT-D | DIR [ENTER] |
ALT-B | DIR B: [ENTER] |
ALT-W | DIR /W [ENTER] |
ALT-S | DIR | SORT | MORE |
ALT-T | TYPE |
ALT-C | COPY |
ALT-P | PRINT |
ALT-R | RENAME |
F4] | DISKCOPY A: B: |
[F5] | FORMAT B: |
[F10] | CLS |
REMEMBER TO END THE BATCH FILE WITH "PROMPT $P$G" TO RETURN
THE PROMPT TO NORMAL.
This page is maintained by:
Michael P. Harris
|