Classic Computer Magazine Archive COMPUTE! ISSUE 138 / FEBRUARY/MARCH 1992 / PAGE 62

Prompting for color. (DOS prompt) (Column)
by Tony Roberts

In a recent column, I discussed the PROMPT command and suggested a few ways to customize the DOS prompt so it would provide you with more useful or interesting information.

Perhaps the most common PROMPT command anywhere is PROMPT $p$g, which causes the system to display the current PATH on every prompt line. But there's more that can be done with PROMPT, and I invited readers to offer their suggestions.

I heard from several readers, most of whom concentrated on experimenting with color. If you have a color monitor and want to display color on your DOS screens, the PROMPT command is probably the easiest way to do it.

Before you begin experimenting, make sure that ANSI.SYS or an equivalent is installed on your system by checking your CONFIG.SYS file for the line DEVICE=ANSI.SYS.

When installing device drivers such as ANSI.SYS, it's OK to put the driver file in a subdirectory other than the root directory as long as the DEVICE line in the CONFIG.SYS file specifies the complete path.

To refresh your memory on prompt metastrings, refer to table 1. Metastrings are groups of characters (strings) that the program changes into something else. In the case of the PROMPT command, the dollar sign is a special signal that tells the program to apply special treatment to the following character.

On to the prompts: Rob Moses, of Sacramento, California, puts different parts of his prompt in different colors. He prints the path in cyan, a hyphen and greater-than symbol (->) in red, and the text in yellow. He describes it as "an interesting effect that emphasizes data and keeps the drive and path in the background."

prompt $e[1;36m$p$e[31m


In this line, you can identify the various metastrings: $e for escape, $p for the current path, $g for the greater-than symbol. Most of the other information--the left brackets and the numbers--is used by ANSI.SYS to control the color of the output.

The combination of an escape character ($e) and a left bracket ([) is a metastring that alerts ANSI.SYS that it should translate the next few characters. Use tables 2 and 3 to help you interpret the previous PROMPT command.

Following the first $e[ is the number 1, which indicates high intensity, or boldface. Next, the number 36 calls for a foreground color of cyan. The m signals an end to this ANSI color sequence. Further along, 31 changes the color to red, and later 33 changes it to yellow.

If you're getting the hang of understanding these cryptic codes, try this one from Larry Parker of Springfield, Missouri.

prompt $e[1;37;44m$p$e[2;37;

40m$ [underscore] $e[1;33;41m$q$g$e[2;37;40


This prompt displays the drive and path in bold white type on a blue background and then uses the $[underscore] metastring to move to a new line, where it displays a prompt arrow (=>) in yellow on red. Finally, normal white text on black is restored.

Bob Smith of Negley, Ohio, sent along a colorful prompt that displays the path in blue text on red, the date in yellow text on green, and the prompt WHAT NOW? in red text on cyan. The DOS colors are set to white text on magenta.

prompt $e[1;34;41m $p$g

$e[1;33;42m $d $e[0;46;31m

WHAT NOW? $e[1;37;45m

Our final prompt comes to us from Richard Ericksen, of Orinda, California, who honors us with a prompt that says COMPUTE, spelled out in a rainbow of color.

prompt $e[1m$e[37mC$e[35mO$e



Thanks to everyone who sent along prompts. You've brought a little color into our lives.

Table 1: Prompt Metastrings

$q = (equal sign)

$$ $ (dollar sign)

$t current time

$d current date

$p current drive and path

$v MS-DOS version number

$n current drive

$g > (greater-than sign)

$l < (less-than sign)

$b (pipe)

$h backspace (erases previous


$e escape code (ASCII code 27)

$ [underscore] carriage return and linefeed

Table 2: ANSI Color Codes

Color Background Foreground

Black 40 30

Red 41 31

Green 42 32

Yellow 43 33

Blue 44 34

Magenta 45 35

Cyan 46 36

White 47 37

Table 3: ANSI Attribute Values

0 white text on black

1 bold

2 low intensity

4 underline (monochrome only)

5 blinking

7 reverse

8 hidden