Classic Computer Magazine Archive COMPUTE! ISSUE 133 / SEPTEMBER 1991 / PAGE 74

Introdos - A Prompt Response
by Tony Roberts

Over the years, the DOS prompt has taken a lot of heat. It's been called cold, unfriendly, and a lot of other names -- many unprintable. It's not hard, though, to take the edge off the infamous prompt. In fact, fooling with the DOS prompt has provided many an evening of recreation for computer users.

DOS provides the PROMPT command so you can customize the prompt to your liking. In many cases, this command is either ignored or placed in the AUTOEXEC.BAT file and forgotten. A common example is the command PROMPT $P$G, which is found on most hard disk systems.

Although it doesn't look like much, the above command instructs the computer to print the current directory path followed by a greater than sign. It might come out looking something like C:\DOS\UTILITIES>.

But how did the cryptic command PROMPT $P$G turn into something helpful and useful? The answer is metastrings. 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 signal that tells the program to apply a special interpretation to whatever character follows.

The metastring $P is transformed into the current path, and $G is transformed into the greater than character. Your DOS manual includes a table that lists the PROMPT metastrings. Among them are codes to display the current time or date, as well as characters to move the cursor to the next line or to erase the previous character.

If you use a program such as a word processor or spreadsheet that allows you to shell to DOS, you've probably had the experience of forgetting that your application program was running, and you've tried to run it again.

To remedy this problem, start the application via a batch file that uses the PROMPT command to remind you that you should exit back to your application. Here's how I do it for Borland's Quattro Pro:

@echo off PROMPT Spreadsheet program active. Type EXIT to return.$ [underscore] $P$G cd\QPRO q cd\ PROMPT $P$G

The metastring $ [underscore] is translated into a carriage return-linefeed, so this prompt ends up being displayed on two lines. At the end of the batch file, the prompt is restored to its normal state.

Some users like to create elaborate prompts using some of the graphics characters that are available in the upper half of the ASCII set. To use these characters, first look them up in an ASCII chart so you'll know the ASCII number of each character you want to use.

Then, to include the character in your prompt command, hold down the Alt key and punch in the ASCII code on the numeric keypad. When you release the Alt key, the character will appear onscreen.

If creating the perfect prompt has caught your fancy, you'll want to take the next step and include some ANSI escape sequences in your prompt, allowing you to add color to your creation.

To do this, you'll need to have the ANSI.SYS device driver or an equivalent (NANSI.SYS, GANSI.SYS, or TANSI.SYS) installed on your system. If it's not installed, you can add the line DEVICE=ANSI.SYS to your CONFIG.SYS file. If the ANSI.SYS file is in a directory other than the root directory, be sure to include the complete path to it in the DEVICE STATEMENT.

With ANSI.SYS installed, you can make your prompts include boldface, flashing, or reverse type, and you can select foreground and background colors as well.

ANSI commands involve the use of another set of metastrings called escape sequences. These sequences combine an escape character (ASCII 27), a left bracket ([), an optional parameter, and a one-letter command code.

This gets pretty involved, and there isn't room here to list all the codes and parameters for colors and video modes, so I'll provide an example to get you started.

Let's take the usual $P$G prompt and spice it up by displaying the prompt itself in reverse video.

PROMPT $E[7M$P$G$E[M

Notice the metastring $E in the command above. This is the PROMPT command's way of sending the escape character. When ANSI.SYS detects the escape character followed by a left bracket character, it knows that it should interpret the characters that follow. The code 7M is the ANSI code for reverse mode. ANSI.SYS switches the display to reverse mode, and then the PROMPT metastrings $P$G are expanded and printed. Finally, another escape sequence changes the video back to normal mode.

As I said, you can have a lot of fun playing with prompts. Send me your best creation in care of COMPUTE, and I'll print a selection in a future column.