Skip to content
FreeDOSDeep Dive Published Updated 3 min readViews unavailable

ANSI Console Drivers on FreeDOS: Escape Sequences, NANSI, and Compatibility

How FreeDOS NANSI interprets console escape sequences, colors, cursor controls and optional key redefinition, plus loading, testing, and safety boundaries.

Plain DOS console output writes characters; an ANSI-style console driver recognizes an escape byte followed by control sequences for cursor movement, colors, erasure, and other terminal behavior. FreeDOS commonly supplies NANSI.SYS as its ANSI console enhancement. Programs that emit these sequences work only when a compatible driver or terminal interprets them.

NANSI extends the CON device path

Load NANSI from FDCONFIG.SYS/CONFIG.SYS before applications use it:

DEVICEHIGH=C:\FREEDOS\BIN\NANSI.SYS /S

DEVICEHIGH needs a functioning upper-memory configuration; otherwise use DEVICE and measure conventional memory. /S enables safe mode by disabling keyboard-key redefinition, a feature with genuine security risk. Other options affect keyboard style, BIOS output, bell, video mode, and unknown request handling. Query the installed NANSI /? because builds differ.

When testing interactively, DEVLOAD can load supported device drivers after boot, but a console driver changes a foundational device path. A boot-menu profile is safer and more reproducible than repeatedly hot-loading it.

CSI sequences carry numeric parameters

The Escape character is byte 27. Many controls use Escape, [, optional semicolon-separated decimal parameters, and a final letter:

ESC [ 2 J       clear the display
ESC [ H         move cursor home
ESC [ 1 ; 33 m  bold yellow foreground
ESC [ 0 m       reset attributes

In FreeCOM’s prompt syntax, $e emits Escape:

PROMPT $E[1;33m$P$G$E[0m

Reset attributes at the end. Otherwise a batch file can leave later commands unreadable, which appears like a broken console even though output is still present.

“ANSI” is not one perfectly uniform terminal

DOS ANSI.SYS, NANSI, VT100-derived terminals, modern emulators, and remote Telnet/serial clients overlap but differ in supported commands and defaults. NANSI documentation lists unsupported insert/delete operations and nonstandard DOS video-mode controls. Test only the subset needed by the application.

Do not identify terminal capability solely from environment variables. A program can be redirected to a file or pipe where escape bytes become literal data. Check device context or offer --no-color/plain output.

Key redefinition is an input injection surface

Historical ANSI drivers can redefine keys through control sequences. A displayed file containing such a sequence could make a function key emit destructive commands later. NANSI’s /S safe option disables redefinition and should be the default unless a controlled application genuinely needs it.

Do not TYPE untrusted binary or ANSI-art files into a privileged shell with redefinition enabled. Screen art is executable terminal input in that model, not passive text.

Direct-video applications bypass the driver

Programs that write to video memory or BIOS services instead of DOS CON may ignore NANSI. Conversely, redirecting NANSI-aware output to a file preserves escape bytes but not the rendered screen. Screen readers may need BIOS-based output (/R in documented NANSI builds) rather than direct acceleration.

Colors also depend on display mode and hardware/emulator palette. ANSI color index 1 is not a calibrated RGB value. Capture intent as semantic colors and verify contrast on the actual screen; blinking and bright-background behavior varies.

Diagnose by inspecting bytes

If raw [31m text appears, confirm that the Escape byte is present and NANSI is loaded. If a file contains literal characters ^ and [ instead, the producer encoded the escape incorrectly. If colors start but never stop, look for a missing reset.

Test cursor movement at screen edges, clear operations, redirected output, piping, prompt reset, shell exit, accessibility path, warm reboot, and applications known to use ANSI art. Keep a clean boot profile without NANSI for software that supplies its own console driver.

NANSI makes DOS text interfaces richer by interpreting a byte protocol. Safe operation comes from using a documented subset, disabling key redefinition, and treating console control data as active input.

Related:

Sources:

Comments