The ANSI.sys
Page(s) - Printed From

DOS has only limited capabilities when it comes to displaying text on the screen. The dialog between you and DOS is on a line to line basis.

Under the ANSI system, positioning the cursor, setting the text colors and other functions are performed by sending a series of  Ascii  characters. For example, escape ($e (ASCII 27), followed by [31m means, "Change the foreground color to red". Escape followed by [1m means, "Turn bold on".  Subsequent characters will be highlighted as they are typed. Escape plus [5;8f means, "Move the cursor to line 5, row 8" on the screen.

These ANSI commands all start with 2 characters, $e (the code for escape) and [ . When displaying data, a system that is ANSI compatible "watches" for these 2 characters, because the characters that follow them give information about what is actually to be done.

Installing the ANSI system

To make your system ANSI compatible, you must install the ANSI.SYS.  With ANSI.SYS in the DOSMISC directory, add the command:   device=dosmisc\ansi.sys .  (In the Windows GUI version, it will be found in either c:\windows\system or c:\windows\command), add this line to your Windows CONFIG.SYS file:  device=d:\x\ansi.sys ("d" being the drive and "x" being the directory(ies) where the ANSI.SYS file was found).

DOS will install ANSI.SYS each time you boot. ANSI.SYS enlarges DOS by about 5000 bytes, occupying that much more memory. If you are short on memory, you may need to remove ANSI.SYS when running programs that need the extra space. You can do this by editing the CONFIG.SYS and adding "rem" (sans quotes) in front of the ANSI.SYS command line, (rem device=d:\x\ansi.sys).

To change your DOS prompt, edit your autoexec.bat file with the command:prompt=$e[1;40;33m$p ...  this will give you: "C:\ ..." , (sans quotes), the display will be a bold yellow.

Setting Colors with Batch files.

The escape sequences are difficult to remember. You might want to make special batch files to set your favorite colors. This one changes the color to white on blue whenever you type blue .

At the C:\ prompt, type:

copy con blue.bat  (press Enter

type:  $e[44;37m  (press  Enter)

type:  CTRL + Z  (press  Enter)

Note that there is no  echo off statement in this batch file. If echo was off , the prompt wouldn't be displayed and the ANSI driver wouldn't get the message to change the color.

Note: Trying to create the above batch file in the Windows XP Home Edition DOS enviroment, you will receive the error message:  "'$e[44;37m' is not recognized as an internal or external command, operable program or batch file".

Ansi Codes

$e[0m     Normal white on black

$e[1m     Bold or high intensity

$e[4m     Underline (if available)

$e[5m     Blink

$e[7m     Reverse video

$e[8m     Concealed (invisible)

$e[30m    Black foreground

$e[31m    Red foreground

$e[32m    Green foreground

$e[33m    Yellow foreground

$e[34m    Blue foreground

$e[35m    Magenta foreground

$e[36m    Cyan foreground

$e[37m    White foreground

$e[40m    Black background

$e[41m    Red background

$e[42m    Green background

$e[43m    Yellow background

$e[44m    Blue background

$e[45m    Magenta background

$e[46m    Cyan background

$e[47m    White background

Other ANSI Escape Sequences

Other ANSI codes are available, but it takes some programming knowledge to use them. A few are listed here, in case you're interested. The # signs are to be replaced with the indicated parameters.

$e[#;#H moves cursor to line #, column#

$e[#A     moves cursor up # line(s)

$e[#B      moves cursor down # line(s)

$e[#C      moves cursor forward # column(s)

$e[#D      moves cursor backwards # column(s)

$e[2J        clears the screen

$e[k    erases to the end of the line

$e[s     saves current cursor position

$e[u     goes back to the "saved" cursor position