Computing.Net > Forums > Disk Operating System > MS DOS prompt color

MS DOS prompt color

Reply to Message Icon

Original Message
Name: Martin Lindberg
Date: May 22, 2002 at 20:38:28 Pacific
Subject: MS DOS prompt color
Comment:

Could anyone please help me to remember this thing. I once learned that I can change the color of the DOS prompt and also the backround with a very cimple command but I seem to have forgotten how. Let me know if you see this ok. thanks!



Report Offensive Message For Removal


Response Number 1
Name: Dan
Date: May 22, 2002 at 20:57:49 Pacific
Subject: MS DOS prompt color
Reply: (edit)

I have a menu which changes color- I don't know if this is what you mean or not.

REM CONFIG.SYS FILE
[menu]
menucolor 7,1
menuitem Windows,Windows 98
submenu Custom,MS DOS
submenu Games,Games
menudefault Windows,10
etc



Report Offensive Follow Up For Removal

Response Number 2
Name: TomChen
Date: May 22, 2002 at 22:57:18 Pacific
Subject: MS DOS prompt color
Reply: (edit)

am...
Load ANSI.SYS in the config.sys file
DEVICE=C:\DOS\ANSI.SYS

reboot, then
type "prompt" + escape code to change the color...


Report Offensive Follow Up For Removal

Response Number 3
Name: rondroid
Date: May 23, 2002 at 01:01:40 Pacific
Subject: MS DOS prompt color
Reply: (edit)

Once ANSI.SYS is loaded you can also put a line in AUTOEXEC.BAT like this:

PROMPT $E[0;32;40m$P$G$E[0;32;40m

This makes the prompt for my special DOS work disk green. I have the whole list of options in a book somewhere. If I can find it I'll post the info for ya.

Ron


Report Offensive Follow Up For Removal

Response Number 4
Name: Luke McCarthy
Date: May 23, 2002 at 09:35:03 Pacific
Subject: MS DOS prompt color
Reply: (edit)

I made a li'l program once that changed the prompt colour. If anyone wants it I could upload it somewhere. It's dead simple to use - you could start it from autoexec.bat:

C:\COLOUR.EXE [Colour code]

The colour code is a the number that Qbasic uses for that colour (0=Black, 1=Blue, 2=Green...)


Report Offensive Follow Up For Removal

Response Number 5
Name: sekirt
Date: May 23, 2002 at 16:47:09 Pacific
Subject: MS DOS prompt color
Reply: (edit)


It can be done fairly easily. Here's the way I know to do it.
In config.sys add the following line:

DEVICEHIGH=C:\WINDOWS\COMMAND\ansi.sys

In autoexec.bat add, as an example, the following line:

prompt=$e[1;37;44m$p$g
Following a reboot in an MS-DOS prompt you'll have white type on a blue backround. The 37 and the 44 cause the colors for the foreground and background respectively. The color possibilities are as follows:
Foreground colors Background colors
30 Black 40 Black
31 Red 41 Red
32 Green 42 Green
33 Yellow 43 Yellow
34 Blue 44 Blue
35 Magenta 45 Magenta
36 Cyan 46 Cyan
37 White 47 White
If you want more info use a search engine and look for ansi.sys.


Report Offensive Follow Up For Removal


Response Number 6
Name: Dan Penny
Date: May 23, 2002 at 19:32:23 Pacific
Subject: MS DOS prompt color
Reply: (edit)

Put in a 98 cd and go to ;

tools\oldmsdos

and run help.com.

On a 95 cd, it's;

other\oldmsdos

Ansi.sys and all the other commands are in there, syntax, notes, and examples.


Report Offensive Follow Up For Removal

Response Number 7
Name: Jay-Jay
Date: May 24, 2002 at 07:34:10 Pacific
Subject: MS DOS prompt color
Reply: (edit)

Why are you all making this way too difficult?
I think he just meant the color command.
Usage:

Sets the default console foreground and background colors.

COLOR [attr]

attr Specifies color attribute of console output

Color attributes are specified by TWO hex digits -- the first
corresponds to the background; the second the foreground. Each digit
can be any of the following values:

0 = Black 8 = Gray
1 = Blue 9 = Light Blue
2 = Green A = Light Green
3 = Aqua B = Light Aqua
4 = Red C = Light Red
5 = Purple D = Light Purple
6 = Yellow E = Light Yellow
7 = White F = Bright White

If no argument is given, this command restores the color to what it was
when CMD.EXE started. This value either comes from the current console
window, the /T command line switch or from the DefaultColor registry
value.

The COLOR command sets ERRORLEVEL to 1 if an attempt is made to execute
the COLOR command with a foreground and background color that are the
same.

Example: "COLOR fc" produces light red on bright white


So color 1 4 sets the background blue and tekst in red, simple as that


Report Offensive Follow Up For Removal

Response Number 8
Name: Hal
Date: May 24, 2002 at 08:42:26 Pacific
Subject: MS DOS prompt color
Reply: (edit)

I do not think COLOR is a MS-DOS Default Command. As far as I can remember loading ANSI.SYS and the editing of the PROMPT Command line in Autoexec.bat is the best way to do it.


Report Offensive Follow Up For Removal

Response Number 9
Name:  
Date: May 24, 2002 at 18:55:15 Pacific
Subject: MS DOS prompt color
Reply: (edit)

Also, there's a file called msdosdrv.txt in your \windows directory which shows you how to do all of that 'ansi.sys' stuff.



Report Offensive Follow Up For Removal

Response Number 10
Name: Chris Hodapp
Date: May 24, 2002 at 19:30:28 Pacific
Subject: MS DOS prompt color
Reply: (edit)

USING THE ANSI DRIVER
by
C. Scot Giles
875 Lake Street
Oak Park, Illinois 60301

This essay is an attempt to explain how I use the ANSI.SYS driver to
configure the function keys on my computer, and to control the screen. I
have used these techniques on my PC and AT for years, and find them to be
convenient and effective. ANSI is not widely used by microcomputer fans
because the documentation supplied by IBM on how to send control codes to
the ANSI driver is among the most cryptic ever produced by IBM. I learned
them by reading computer magazines, and slowly figured out how it could be
done. I am not a professional computer programmer (indeed I am a
clergyman), so some of my technical observations might be in error. But
everything here works, and I have retested it before finishing this essay.

This essay covers only IBM Personal Computers (PC, XT or AT) running DOS
2.n or greater. I have no experience with compatibles, so you are on your
own if you try to use these techniques on one.

LOADING THE ANSI DRIVER
In order to use any of the techniques in this essay, you must first have loaded
the ANSI.SYS driver into your computer's memory using your CONFIG.SYS file.
You do this my adding the line, DEVICE=ANSI.SYS somewhere in the CONFIG.SYS
file and rebooting your computer.

KEYBOARD REASSIGNMENT WITH ANSI
Before we get to specific ways to send control codes to the (now loaded) ANSI
driver, you must first know what those codes mean. For the function keys the
codes are listed on the chart below which first appeared in SOFTALK magazine.
Each function key is assigned an "extended function code" which DOS will use to
recognize that a function key has been pressed and in what shifted mode, if
any. Each number is expressed as a 0 followed by a semi-colon, then the number
from the chart below.

KEY NORMAL SHIFT CONTROL ALT
F1 59 84 94 104
F2 60 85 95 105
F3 61 86 96 106
F4 62 87 97 107
F5 63 88 98 108
F6 64 89 99 109
F7 65 90 100 110
F8 66 91 101 111
F9 67 92 102 112
F10 68 93 103 113

Accordingly, the way to designate the F5 key would be 0;63 while the F10 key
would be designated by 0;68 or 0;113 if shifted with the ALT key.

If you examine the DOS Technical Reference Manual (not the Technical Manual for
PC hardware), you will find a section on SCREEN/KEYS. This section was
contained in the DOS 2.0 documentation, but IBM removed it in later editions.
Here is a summary of its contents relative to keyboard redefinition.

To change one key to have the meaning of another, enter:

ESC [#;#p

where the first # is the ASCII value of the key being changed and the second #
is the ASCII value of the new definition. For example, "A" has the ASCII value
of 65 and "Q" has the value of 81. So:

ESC [65;81p

will result in "A" being redefined as "Q." It is also possible to redefine a
key to have the meaning of a string of characters. This is done by enclosing
the string in quotes. So:

ESC [65;"Hi there"p

would change the "A" key to have the meaning of "Hi there." If the first value
for the first # is a 0 however, DOS knows that what is being changed is not an
ASCII value but the meaning of an extended function code. So if you were to
enter:

ESC [0;68;"Hi there"p

DOS would know to change the meaning of the function key (in this case F10) to
the sting enclosed in quotes. This is the key to redefining your function keys
to perform much used commands: like DIR, CHKDSK, COPY *.* B: etc. or to load
programs from disk.

There is a final trick here. If you end the escape command sequence with the
characters ";13p" instead of just "p" the command will self-execute, just as if
you pressed the [enter] key.

The IBM documentation tells the user to preface each command by an ESC command,
and I have represented this in the above paragraphs by writing the characters
"ESC." at the start of each control code sequence mentioned. Most users assume
that this means to press the ESC key on the keyboard when entering the
commands. Not so. To get the Escape Sequence to the ANSI driver you must
enter it using a prompt command or write a .COM file. For example to configure
the F1 key (extended function code 59) to have the meaning in DOS of "autoexec"
with an [enter] command at the end of it you cannot type:

ESC [0;59;"autoexec";13p

as the ESC will not be recognized by DOS as an escape sequence. What DOS will
recognize as an escape sequence is the characters "$e" although this surely
looks strange at first. Users familiar with the PROMPT command will notice
that the "$" character is what the PROMPT command uses as an escape sequence,
and that is precisely how we will get the redefinition to be recognized by DOS.
If you enter the following command:

PROMPT $e[0;59;"autoexec";13p

you will see that it works perfectly. You now have the secret to redefining
the function keys in DOS. Simply write and run a batch file with a list of
PROMPT commands and you will have done it. One precaution, ECHO must be ON,
otherwise DOS will suppress the PROMPT command and the escape sequences will
not get through.

As an example, let's create a batch file called KEYON.BAT that will set F1 as
EDITOR [enter], F2 as PC-FILE [enter], F3 as PC-CALC [enter], F4 as PC-GRAPH
[enter], F5 as PC-TALK [enter], F6 as PC-WRITE [enter], F7 as BASICA [enter],
F8 as DIR without the [enter], F9 to run a batch file called MENUOFF.BAT
[enter] and F10 to run a batch file called MENUON.BAT [enter]. It would be as
follows:

echo on
PROMPT $e[0;59;"EDITOR";13p
PROMPT $e[0;60;"PC-FILE";13p
PROMPT $e[0;61;"PC-CALC";13p
PROMPT $e[0;62;"PC-GRAPH";13p
PROMPT $e[0;63;"PC-TALK";13p
PROMPT $e[0;64;"PC-WRITE";13p
PROMPT $e[0;65;"BASICA";13p
PROMPT $e[0;66;"DIR"p
PROMPT $e[0;67;"MENUOFF";13p
PROMPT $e[0;68;"MENUON";13p
prompt
cls

You would also want to create another file called KEYOFF.BAT which resets the
function key definitions to DOS normal. The format would be:

echo on
PROMPT $e[0;59;0;59p
PROMPT $e[0;60;0;60p
PROMPT $e[0;61;0;61p
PROMPT $e[0;62;0;62p
PROMPT $e[0;63;0;63p
PROMPT $e[0;64;0;64p
PROMPT $e[0;65;0;65p
PROMPT $e[0;66;0;66p
PROMPT $e[0;67;0;67p
PROMPT $e[0;68;0;68p
prompt
cls

I should mention that the purpose of the final blank PROMPT command in each of
these batch files is to reset the DOS prompt to A> or whatever your default
prompt is. It serves no redefinition purpose, but does keep the screen looking
clean.

USING DEBUG TO LOAD THE ANSI DRIVER
While there is no reason why we could not continue to configure our function
keys by batch files consisting of lists of PROMPT commands, this is a clumsy
way to proceed. It is easier to use the DEBUG utility supplied with DOS to
create a .COM file that will do the job for us quickly and directly, without
sending any input to screen. To my knowledge this technique was first
published by Michael J. Grabel in the December 1984 edition of PC WORLD.

Place a formatted DOS disk containing the DEBUG utility in the default drive,
and follow the script below. As you do so hexadecimal numbers will appear on
the left hand side of your screen. These numbers will vary depending on the
configuration of your system. For our purposes here I will represent the
numbers in the form xxxx:nnnn. What you will see on your screen will be
different.

A>DEBUG [enter]
-A 100 [enter] MOV AH,9 [enter] MOV DX,109 [enter] INT 21 [enter] INT 20
[enter] xxxx:nnnn DB 1B'[0;59;"EDITOR";13p' [enter] xxxx:nnnn DB
1B'[0;60;"PC-FILE";13p' [enter] xxxx:nnnn DB 1B'[0;61;"PC-CALC";13p' [enter]
xxxx:nnnn DB 1B'[0;62;"PC-GRAPH";13p' [enter] xxxx:nnnn DB
1B'[0;63;"PC-TALK";13p' [enter] xxxx:nnnn DB 1B'[0;64;"PC-WRITE";13p' [enter]
xxxx:nnnn DB 1B'[0;65;"BASICA";13p' [enter] xxxx:nnnn DB 1B'[0;66;"DIR"p'
[enter] xxxx:nnnn DB 1B'[0;67;"MENUOFF";13p' [enter] xxxx:nnnn DB
1B'[0;68;"MENUON";13p' [enter] xxxx:nnnn DB 1B '$' [enter]

As soon as you have entered the previous line, your computer will respond
with a number in the form of xxxx:nnnn. Copy down the portion of the
number that is being represented here as "nnnn" as you will need it
later. Once you have copied the number down, press [enter]

xxxx:nnnn [enter]
-N KEYON.COM [enter]
-R BX [enter]

When you have entered the command above, your computer will respond with
the following line and a colon as a prompt. At this prompt enter 0 and
press [enter].

BX:0000
:0 [enter]
-R CX [enter]

When you enter the R CX command above, the computer will respond with the
following line and a colon as a prompt. At this prompt enter the number,
"nnnn" you copied down above and press [enter].


CX 0000
:nnnn [enter]
-W [enter]

The computer will respond with the following.

WRITING nnnn bytes
-Q [enter]

As soon as you enter the Q command (for Quit) you will be back at the DOS
prompt, and there will be a new file on disk called KEYON.COM. Simply type it
at the DOS prompt and your function keys will be configured. It is a good idea
to use this same procedure to write another .COM file called KEYOFF.COM which
will restore the keys to their native DOS definitions. The procedure for this
is the same as the above, except that the definition section should be:

xxxx:nnnn DB 1B'[0;59;0;59p' [enter] xxxx:nnnn DB 1B'[0;60;0;60p' [enter]
xxxx:nnnn DB 1B'[0;61;0;61p' [enter] xxxx:nnnn DB 1B'[0;62;0;62p' [enter]
xxxx:nnnn DB 1B'[0;63;0;63p' [enter] xxxx:nnnn DB 1B'[0;64;0;64p' [enter]
xxxx:nnnn DB 1B'[0;65;0;65p' [enter] xxxx:nnnn DB 1B'[0;66;0;66p' [enter]
xxxx:nnnn DB 1B'[0;67;0;67p' [enter] xxxx:nnnn DB 1B'[0;68;0;68p' [enter]
xxxx:nnnn DB 1B '$' [enter]

If you find that KEYON.COM doesn't work correctly, reboot the machine to clear
the definitions and try again. The most common mistakes are typing errors (I
often enter a colon when I wanted a semi-colon). Another source of difficulty
will arise if you have another file on disk to start with called KEYON.COM or
KEYOFF.COM. DEBUG bypasses the normal file allocation of DOS and writes
directly to the disk. If you have another file on disk with the same name,
DEBUG will overwrite it, but unless the other file was exactly the same size as
the new one or smaller, there may be a piece of the old file left over attached
to the end of the new one. As a precaution, always erase old versions of the
.COM files, or better yet give each one a unique name and rename it later using
the DOS Rename command.

SOME ADDITIONAL TRICKS
Here are some additional control codes for the ANSI driver, summarized from the
IBM material.


1. CURSOR POSITIONING

To move the cursor to a specified position: ESC [#;#h where the first #
is the desired line number and the second the desire column.

To move the cursor up without changing columns: ESC [#a where # specifies
the number of lines moved.

To move the cursor to a specified horizontal and vertical position: ESC
[#;#f where # means first the line number and secondly the column number.

To get a device status report: ESC [6n

To get a cursor position report: ESC [#;#r where the first # specifies
the current line and the second # specifies the current column

To move the cursor down: ESC [#b where # specifies the number of lines
moved down.

To move the cursor forward: ESC [#C where # specifies the number of
columns moved.

To move the cursor backward: ESC [#d where # specifies the number of
columns moved.

To save the cursor position: ESC [s and to restore it: ESC [u.

2. ERASING

To do a CLS (erase screen move cursor to home position): ESC [2j

To erase from cursor to end of line: ESC [k


3. COLOR GRAPHICS

To set the color/graphics attributes, enter ESC [#;#m where the first #
is the desired foreground color and the second is the desired background
color. Select colors from the list below:

30 black foreground
31 red foreground
32 green foreground
33 yellow foreground
34 blue foreground
35 magenta foreground
36 cyan foreground
37 white foreground
40 black background
41 red background
42 green background
43 yellow background
44 blue background
45 magenta background
46 cyan background
47 white background

To set additional attributes enter: ESC [#m where # is the number of the
desired attribute. Select attributes from the list below:

0 all attributes off (white on black)
1 bold on
4 underscore (on IBM Monochrome Display)
5 blink
7 reverse video
8 invisible

To give an example of what can be done with these additional codes, a batch
file called MENUOFF.BAT containing only the line:

PROMPT $e[2J$e[30;40m$h

would blank a color display completely. It does a CLS, sets the display to a
black foreground and background and the with the "$h" performs a backspace to
erase the blinking cursor (the "$h command is documented in the DOS manual
under PROMPT). Another batch file called MENUON.BAT containing the lines:

PROMPT $e[0m
prompt
cls

Would reset a color display to restore the screen after MENUOFF.BAT had been
run.

Enjoy ANSI! It is a wonderful tool, and can be a lot of fun to use. It's not
a keyboard enhancer, and if you load it up with too many keyboard redefinitions
at one time you will run out of environment space. This is harmless and simply
means that ANSI is full. But it will work fine to define your function keys
and control your screen.


Report Offensive Follow Up For Removal

Response Number 11
Name:  
Date: May 25, 2002 at 11:13:09 Pacific
Subject: MS DOS prompt color
Reply: (edit)


Try this for a nice little dos screen:

prompt $e[s$e[1;1f$e[0;36;44m$p$e[0;37;40m$e[K$e[1;67f$e[0;36;44m$d$e[2;67f$t$e[6D$e[K$e[u$e[0;37;40m$g


Report Offensive Follow Up For Removal

Response Number 12
Name: Secret_Doom
Date: May 26, 2002 at 15:25:57 Pacific
Subject: MS DOS prompt color
Reply: (edit)

The COLOR command Jay-Jay is refeereing to is NOT present in Windows9x, nor in any version of DOS.

It is present in NT systems (Win2K, as far as I know). CMD.EXE is the command interpreter for such systems, which recognizes such command.

Obviously, the COLOR command doesn't change the MSDOS color, only the CMD.EXE color. But we must not forget that CMD.EXE is commonly wrongly refeered to as 'DOS', because it looks like COMMAND.COM (DOS's command interpreter), so much people think it's DOS (but it's NOT).

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br


Report Offensive Follow Up For Removal

Response Number 13
Name: Matthew
Date: July 20, 2002 at 09:19:56 Pacific
Subject: MS DOS prompt color
Reply: (edit)

Hey, I was reading all of you replys and found some usefull information. But I want to know how to change colors in DOS too. Not just foreground and background colors. I remeber the 486 or 386 had color to the DOS prompt. Sertain file extentions were sertain colors. The EXEs were light blue, the BATs were green, the COMs were white, the Directories were purple, all others were gray. I asked my dad about this and he said all he could remember was come color util. You would type in at the prompt to change thangs


Report Offensive Follow Up For Removal

Response Number 14
Name: Arsalan Mahmood
Date: July 31, 2002 at 16:38:24 Pacific
Subject: MS DOS prompt color
Reply: (edit)

Hey Guys
why are you all wasting your time in these commands which are available in just windows NT. I m just giving you a method to make your DOS CoLoUrFuL.Just follow these steps

1> make a file on your desktop named cyan.txt then put the following code there


n cyan.com
e 0100 B4 12 B3 10 CD 10 B8 40 00 8E D8 B8 00 06 B7 F0
e 0110 29 C9 B6 18 80 FB 10 74 04 8A 36 84 00 8A 16 4A
e 0120 00 FE CA CD 10 B4 02 8A 3E 62 00 29 D2 CD 10 C3
q

2> Open your dos prompt type
cd desktop
debug Make a batch file on your desktop
put the following code there.
#echo off
C:\windows\desktop\color.bat

4> right click on your MS-DOS PROMPT and click on PROPERTIES and on the PROGRAM tab there will be a text box named BATCH FILE
put the path there C:\WINDOWS\DESKTOP\COLOR.BAT

5> You have got it!

NOTE: IF you want to have different color then edit the first line in the CYAN.txt,here at the last of the line you will see 'F0' F is for the background and 0 if for text.

Here I am providing a list of alphabets which you can replace at the F0 mark.

Colors (background)

1 = blue
2 = green
3 = cyan
4 = red
5 = magenta

Text Colors (foreground)

1 = blue
2 = green
3 = cyan
4 = red
6 = magenta
9 = Bright Blue
A = Bright Green
B = Bright Cyan
C = Bright Red
D = Bright Magenta
E = Yellow
F = Bright White


Report Offensive Follow Up For Removal

Response Number 15
Name: Arsalan Mahmood
Date: July 31, 2002 at 16:42:01 Pacific
Subject: MS DOS prompt color
Reply: (edit)

Hey Guys
why are you all wasting your time in these commands which are available in just windows NT. I m just giving you a method to make your DOS CoLoUrFuL.Just follow these steps

1> make a file on your desktop named cyan.txt then put the following code there


n cyan.com
e 0100 B4 12 B3 10 CD 10 B8 40 00 8E D8 B8 00 06 B7 F0
e 0110 29 C9 B6 18 80 FB 10 74 04 8A 36 84 00 8A 16 4A
e 0120 00 FE CA CD 10 B4 02 8A 3E 62 00 29 D2 CD 10 C3
q

2> Open your dos prompt.type there

cd desktop
debug right click on your MS-DOS PROMPT and click on PROPERTIES and on the PROGRAM tab there will be a text box named BATCH FILE
put the path there C:\WINDOWS\DESKTOP\COLOR.BAT

5> You have got it!

NOTE: IF you want to have different color then edit the first line in the CYAN.txt,here at the last of the line you will see 'F0' F is for the background and 0 if for text.

Here I am providing a list of alphabets which you can replace at the F0 mark.

Colors (background)

1 = blue
2 = green
3 = cyan
4 = red
5 = magenta

Text Colors (foreground)

1 = blue
2 = green
3 = cyan
4 = red
6 = magenta
9 = Bright Blue
A = Bright Green
B = Bright Cyan
C = Bright Red
D = Bright Magenta
E = Yellow
F = Bright White


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: MS DOS prompt color

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge