ANSI.SYS
ANSI.SYS is a device driver in the DOS family of operating systems that provides extra console functions through ANSI escape sequences. It is partially based upon a subset of the text terminal control standard proposed by the ANSI X3L2 Technical Committee on Codes and Character Sets.
As it was not installed by default, and was notoriously slow, little software took advantage of it and instead resorted to directly manipulating the IBM PC hardware. A number of third-party alternatives that ran at reasonable speed were created, such as, and to attempt to change this.
Usage
To use under DOS, a line is added to the file that reads:where drive: and path are the drive letter and path to the directory in which the file is found, and options can be a number of optional switches to control the behaviour. may also be loaded into upper memory via /.
- use extended keyboard BIOS functions rather than standard ones This made the F11 and F12 keys work.
- force number of lines
- adjust line scrolling to support screen readers
- or set screensize
- support redefinition of extended key codes independent of standard codes
Functionality
The standard is very slow as it maps escape sequences to BIOS calls. Several companies made third-party replacements such as that interface directly with the video memory, in a similar way to most DOS programs that have a full-screen user interface.
checked if this driver was in use, and changed the command to use an escape sequence instead of a BIOS call.
Keyboard remapping
An interesting feature of is the ability to remap any key on the keyboard in order to perform shortcuts or macros for complex instructions. Using special escape sequences, the user can define any keystroke that has a character-code mapping to simulate an arbitrary sequence of such keystrokes. This was used to create simple trojans out of text files laced with nefarious keyboard remaps, known as "ANSI bombs". A number of products were released to protect users against this:- Many replacements for support a command line switch to disable the key remapping feature, f.e. the option in Datalight ROM-DOS or NANSI.SYS of FreeDOS. Other ANSI drivers like ANSIPLUS can be configured to disable the redefinition of keys as well.
- Some replacements were deliberately designed never to support the keyboard remapping functions.
- PKWARE produced a terminate-and-stay-resident program, PKSFANSI, which filters out keyboard remapping escape codes as they are written to the standard output. This has the advantage that the user can load some useful remappings from a text file and then run PKSFANSI to prevent further, possibly malicious remappings.
Occurrence
was required to run some software that used its cursor and color control functions. It could also be used to enable elaborate color codes in the prompt. These uses were overshadowed by the use of in BBSes; ANSI escape sequences were used to enable BBSes to send text graphics more elaborate than ASCII art, and to control the cursor in ways that were used in a number of online games and similar features.
Most versions of Windows did not support ANSI escape codes in any useful way. In Windows 10 support for similar escape sequences was built into the Win32 console, but must be activated using the Windows API function by setting the flag.
Features
CSI is a placeholder for the common two-byte escape lead-in sequence "". The ANSI standard also defines an alternative single-byte CSI code, which is not supported by ANSI.SYS.Standard DOS drivers support only the following sub-set of ANSI escape sequences:
| Sequence | Effect |
| ESC | Cursor up |
| ESC | Cursor down |
| ESC | Cursor forward |
| ESC | Cursor back |
| ESC | [Horizontal and vertical position |
| ESC | Erase display |
| ESC | Erase in line |
| ESC | Select graphic rendition |
| ESC | Device status report requests cursor position, returned as cursor position report : ESC |
| ESC | Save cursor position |
| ESC | Restore cursor position |
There are also some escape sequences specific to the implementation of. They are not generally supported by ANSI consoles in other operating systems.
| Sequence | Effect | ||
| ESC ESC ESC ESC | Set [#screen modes">screen mode | ||
| ESC | |||
| ESC | Enable or disable 1 | Switch [keyboard input"> n J | Erase display |
| ESC | Erase in line | ||
| ESC | Select graphic rendition | ||
| ESC | Device status report requests cursor position, returned as cursor position report : ESC | ||
| ESC | Save cursor position | ||
| ESC | Restore cursor position |
There are also some escape sequences specific to the implementation of. They are not generally supported by ANSI consoles in other operating systems.
| Sequence | Effect | |
| ESC ESC ESC ESC | Set [#screen modes">screen mode | |
| ESC | ||
| ESC | Enable or disable 1 | Switch [keyboard input mode to Korean |
| ESC |SKR]/KR |
| Mode | Description | Mode | Description |
| 0 | 40 × 25 monochrome | 1 | 40 × 25 color |
| 2 | 80 × 25 monochrome | 3 | 80 × 25 color |
| 4 | 320 × 200 color | 5 | 320 × 200 monochrome |
| 6 | 640 × 200 monochrome | ||
| 7 | Wrap at [end of line | ||
| 13 | 320 x 200 color | 14 | 640 x 200 color |
| 15 | 640 x 350 monochrome | 16 | 640 x 350 color |
| 17 | 640 x 480 monochrome | 18 | 640 x 480 color |
| 19 | 320 x 200 color | ||
| 114 | 640 x 480 color | 115 | 640 x 475 color |
In some DOS implementations, video modes above 7 are not documented. Under Multiuser DOS, the only valid argument in conjunction with PCTERM is 7.