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 (the "X3 Committee").
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 (or under Windows NT based versions of Windows) 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 /.
Functionality.
Once loaded, enables code sequences to apply various text formatting features. Using this driver, programs that write to the standard output can make use of the 16 text foreground colors and 8 background colors available in VGA-compatible text mode, make text blink, change the location of the cursor on the screen, and blank the screen. It also allows for the changing of the video mode from standard 80×25 text mode to a number of different graphics modes (for example, 320×200 graphics mode with text drawn as pixels, though ANSI.SYS does not provide calls to turn individual pixels on and off).
The standard is relatively slow as it maps escape sequences to the equivalent BIOS calls. Several companies made third-party replacements that interface directly with the video memory, in a similar way to most DOS programs that have a full-screen user interface.
By default, the internal DOS command works by directly calling the corresponding BIOS function to clear the screen, thereby prominently violating the hardware abstraction model otherwise maintained. However, if an ANSI driver is detected by the DR-DOS , it will instead send the control sequence defined in the reserved environment variable to the attached console device. If the environment variable is undefined, it falls back to send the sequence instead. Specifying other sequences can be used to control various screen settings after a . Due to the difficulties to define environment variables containing binary data COMMAND.COM also accepts a special notation for octal numbers. For example, to send an alternative control sequence like (for as used by ASCII terminals), one could define the variable as follows:
These features are supported by in all versions of DOS Plus and DR-DOS, but not in MS-DOS or PC DOS. They are also supported by the command interpreters in Concurrent DOS, Multiuser DOS and REAL/32, although they use VT52 rather than ANSI control sequences by default (e.g. ).
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 feature was also used by evildoers 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:
Occurrence.
 appeared in MS-DOS 2.0, the first version of the operating system supporting device drivers. It was supported by all following versions of MS-DOS. It is also present in many non-Microsoft DOS systems, e.g. IBM PC DOS and DR-DOS.
 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 elaborate 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 version of Windows did not support ANSI escape codes in any useful way (it could be used by MSDOS emulation in some versions). In Windows 10 support for similar escape sequences was built into the Win32 console (the text terminal window), but must be activated using the Windows API function by setting the flag.
Features.
CSI (Control Sequence Introducer) is a placeholder for the common two-byte escape lead-in sequence "" (that is, ). 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:
There are also some escape sequences specific to the implementation of . They are not generally supported by ANSI consoles in other operating systems.
In some DOS implementations, video modes above 7 are not documented. Under Multiuser DOS, the only valid argument in conjunction with PCTERM is 7.