This is a quick C program that will let you change the text and background color of the DOS command line. It should compile in DJGPP, or any compilers that have the non-standard conio.h.

In order for this program to work, you need to press enter over and over again until the command line cursor is at the very bottom of the dos box or screen. Then run the program. This program doesn't work with Win2K.

/***************************

DOS Color Hack v1.1
By: Nanosecond

The first argument you pass is the textcolor.
The second argument is the background color.

KNOWN ISSUES: 1) If you cls, the color goes away.
2) Some background colors show up differently
against certain
text colors.

Compiled in DJGPP Jan. 10, 2001

This code is open for the public to use and/or modify,
it is not copyrighted.

***************************/

#include <stdio.h>
#include <string.h>
#include <conio.h>

void usage();

void main(int argc, char *argv[])
{
char *literal1 = argv[1];
char *literal2 = argv[2];

if(argc == 1 || argc > 3) /* No arguments or too many*/
{
usage();
exit(1);
}

textcolor(strtol(literal1, NULL, NULL)); /* strtol converts string to
integer */
if(literal2 != NULL) /*If there wasn't a second argument, don't try
background color */
textbackground(strtol(literal2, NULL, NULL));

cprintf("COLOR ACTIVATED", 1);
}

void usage()
{
printf("\t\tAt least one argument is needed (2 possible).
The first argument is text color, and the second is
background color. You pass these arguments as #s.
Here's a table so you know what to use:\n\n

BLACK = 0,
BLUE = 1,
GREEN = 2,
CYAN = 3,
RED = 4,
MAGENTA = 5,
BROWN = 6,
LIGHTGRAY = 7 (DOS default),
DARKGRAY = 8,
LIGHTBLUE = 9,
LIGHTGREEN = 10,
LIGHTCYAN = 11,
LIGHTRED = 12,
LIGHTMAGENTA = 13,
YELLOW = 14,
WHITE = 15");
}
Perhaps an easier way of accomplishing this is by using ANSI.SYS and the "$e" paramater of PROMPT.

Add "devicehigh=c:\windows\command\ansi.sys" (or c:\dos as the case may be) to your config.sys
now reboot and try typing "prompt $e[31;34m$p$g" and see what happens.
See the ANSI colour codes for more details.

Log in or register to write something here or to contact authors.