Once Ansi.sys has been loaded, it's various functions can be accessed at any time by sending one or more "Escape" Sequences to the screen. An Escape Sequence comprises three parts:
The Prefix | This is the two characters represented by ASCII 27 followed by ASCII 91. ASCII 27 is the character returned by the "ESC" key and is represented in the tables below by . ASCII 91 is the left hand square bracket "[". |
The Codes | Depending on the actual command, these will be a series of numbers or characters that define the new screen colour, keyboard key, or whatever. The default code is 0 and, when that value is specified, can be omitted. |
The Suffix | A single letter (case sensitive) that defines how Ansi.sys interprets the Codes. ie. whether the cursor is to be moved, a key to be reassigned or whatever. |
Note that an "Escape" Sequence cannot be entered directly - see: Ansi Escape Sequences for further details.
Setting Text and Background Colours
|
Colour | ANSI Code |
Prefix | Text | Background | Suffix |
Black | [ | 30 | 40 | m |
Red | 31 | 41 |
Green | 32 | 42 |
Yellow | 33 | 43 |
Blue | 34 | 44 |
Magenta | 35 | 45 |
Cyan | 36 | 46 |
White | 37 | 47 |
|
Attribute | ANSI Code |
Prefix | Code | Suffix |
All attributes off | [ | 0 | m |
Bright characters | 1 |
Underlined characters | 4 |
Blinking characters | 5 |
Reverse video characters | 7 |
Hidden characters | 8 |
|
Notes
A series of color/attribute commands can be combined into one by separating the codes with semicolons.
Color changes only take effect as each character is written following the Ansi command. To change the whole screen to the new colours, add the "2J" sequence to clear the screen (see under Miscellaneous, below) or simply enter CLS on the next line.
Examples
To change the colours to blinking bright green characters on a cyan background:
ECHO [46m [32m [5m [1m [2J
or, more efficiently:
ECHO [46;32;5;1m
CLS
|
Cursor Positioning
Prefix | Code | Suffix | Cursor Position |
[ |
r;c |
H | Moves the cursor to line r and column c If omitted, r and c both default to 0 (ie. the cursor moves to the top left corner of the screen) |
f |
n | A | Moves the cursor up n lines (or top of screen) |
n | B | Moves the cursor down n lines (or bottom of screen) |
n | C | Moves the cursor right n columns (or right hand side of screen) |
n | D | Moves the cursor left n columns (or left hand side of screen) |
| s | Saves current cursor position |
| u | Restores cursor to previously saved position
|
---|
|
Miscellaneous
Prefix | Code | Suffix | Effect |
[ |
2 | J | Clears the screen.1 |
| K | Clears from the cursor to the end of the line |
=7 | h | Enables line wrap |
=7 | l | Disables line wrap |
Notes
These two groups of commands are primarily used for constructing page headers, footers and menus. See PROMPT for further notes and examples.
1 Actually, the screen is cleared when the Code value is any integer (or is omitted).
|
To change the Display Mode:
|
Prefix | Code | Suffix | Text Mode |
[ |
=0 | h | 40 cols 25 lines | Monochrome |
=1 | Colour |
=2 | 80 cols 25 lines | Monochrome |
=3 | Colour |
Notes
I have no real experience with these modes but they rather look as though they are a hangover from the early days of Dos. I cannot think of any situation where changing display mode to one of the above values would be to any advantage.
|
Prefix | Code | Suffix | Graphics Mode |
[ |
=5 | h | 320 x 200 | Monochrome |
=4 | 4 Colour |
=13 | Colour |
=19 | 256 Colour |
=6 | 640 x 200 | Monochrome |
=14 | 16 Colour |
=15 | 640 x 350 | 2 Colour |
=16 | 16 Colour |
=17 | 640 x 480 | 2 Colour |
=18 | 16 Colour |
|
Keyboard Layout Codes
Ansi.sys can be used to remap the keys of the keyboard. Any key can be redefined to any one or more characters of the extended ASCII character set.
Typical applications of this facility include:
- Assignment of "non-standard" characters to unused keys
- Assignment of text phrases to unused keys. This can include DOS commands.
- Complete remapping of the keyboard - for special data entry functions or obscure foreign language use, perhaps.
|
Syntax
[keycode;stringp
keycode |
The
code(s) associated with the given key. Many keys use a code of two numbers separated by a semicolon and these must be used in full. |
string |
- This can be:
- The ASCII code for a single character;
- The code associated with a key; or
- a text string (of one or more characters) enclosed in inverted commas.
|
|
Notes
- Most DOS programs (including EDIT) bypass the standard DOS calls when accepting keyboard input and so will ignore Ansi.sys reassignments.
- Have a care when assigning environmental variables to a key as these will be parsed as they are fed to the screen. Thus, assigning "ECHO %ESC%[" to a key leaves you with just "[" as the "ECHO" is cleared from the command line by %ESC%. However, it is possible to assign two keys to this: the first is assigned "ECHO %ESC", and the second is assigned "%[". Pressing the two keys sequentially puts "ECHO %ESC%[" onto the command line.
Examples
- To assign á to the Alt-A key:
[0;30;160p
- To disable Ctrl-C, assign it to ASCII 255 (Nul)
[3;255p
- To re-enable Ctrl-C, assign it back to 3:
[3;3p
- To assign "FOR %v IN ( ) DO " to Alt-F and have Alt-D append a directory listing of Drive D: to DirD.txt, you have several options including:
- Use EDIT to create a file called "Keys.txt" containing the following lines:
[0;33;"FOR %v IN ( ) DO "p
[0;32;"DIR D: /S >> DirD.txt";13p
(where is inserted using Ctrl-P followed by the "ESC" key).
- Copy Keys.txt to the screen using either:
TYPE Keys.txt or COPY Keys.txt CON
Or
- Use EDIT to create "Keys.bat" containing the lines:
ECHO [0;33;"FOR %v IN ( ) DO "p
ECHO [0;32;"DIR D: /S >> DirD.txt";13p
- Run the batch file by entering "Keys" at the command line prompt.
Either way, the keys will now be reassigned.
|