Adding Color and Cursor Control to MS-DOS Batch Files with ANSI.SYS
Learn how to load the ANSI.SYS driver in MS-DOS to add colour, cursor movement and screen clearing to batch files, with a concrete example and verification steps.
03 Aug 2026, 21:30 UTC

Problem: bland MS‑DOS console output
By default MS‑DOS writes text to the screen in a single colour and offers no way to move the cursor or clear the display from a batch file. This makes it hard to build readable menus, status logs or simple games without resorting to external utilities.
Thesis: ANSI.SYS adds escape‑sequence handling
The ANSI.SYS device driver, when loaded via CONFIG.SYS, intercepts BIOS video calls and translates ANSI escape sequences (the ESC character followed by '[') into actions such as changing foreground/background colour, moving the cursor, or clearing the screen.
Installation
- Locate the ANSI.SYS file (usually in C:\DOS).
- Edit CONFIG.SYS and add a line:
DEVICE=C:\DOS\ANSI.SYS(useDEVICEHIGHif you have upper memory blocks and want to save conventional memory). - Save the file and reboot the system.
The driver occupies roughly 2 KB of conventional memory and hooks INT 10h video services.
Worked example: coloured prompt and error messages
@echo off
rem Set a green prompt that shows the current path
PROMPT=$E[32m$p$g$E[0m
rem Normal batch commands follow
echo Starting backup...
rem Simulate an error condition
if not exist backup.txt (
echo $E[31mError!$E[0m Missing backup file
goto :eof
)
echo Backup completed.
After the reboot, the prompt appears in green, each command line is prefixed with the path, and the error message prints in red. The $E token is expanded by COMMAND.COM to the ASCII escape character (27).
Verification and limitations
- Run
PROMPT $E[32m$p$g$E[0mat the command line. If the prompt turns green, ANSI.SYS is active; if you see the literal text$E[32m, the driver is not loaded. - Use DEBUG to test a raw sequence:
echo $E[2J$E[5;10HHelloand verify the screen clears and "Hello" appears at row 5 column 10. - Check memory: before reboot run
MEMand note the conventional memory free; after loading ANSI.SYS the free value should drop by about 2 KB.
Trade‑offs: the driver consumes conventional memory, may add a slight delay to screen output, and is ignored by programs that bypass BIOS video calls (e.g., many Windows console programs or certain DOS clones). Consequently, scripts that rely on ANSI.SYS should be tested on the target hardware or include a fallback to plain text.
Actionable closing
If you need richer batch‑file output on a genuine MS‑DOS system, add the DEVICE line for ANSI.SYS, reboot, and use the $E[…m sequences to colour text, clear the screen, or position the cursor. Keep an eye on conventional memory usage and verify the driver is active with the simple prompt test before depending on coloured output in critical scripts.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.