C++ Color programming

 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Look for commands that set foreground and background color
 

Armitage

Banned
Feb 23, 2001
8,086
0
0


<< I have Turbo C++ and want to get some of the text to come out in color... Does anyone know how to do it? >>



I posted this a few weeks back, but the search function doesn't seem to find it. In any case, here is a header that you can use to output color text using ASCII escape sequences:

EDIT: This works fine on Linux. I have no idea if it will work under MS OS/ Turbo C++ But it's worth a shot.

***************************
/** @file color.h
@brief This file defines some macros for changing the color and other attributes
of terminal text output.

If you don't want color output, set the NOCOLOR macro at compile time*/

//makes the system beep
#define BELL "\a"

#ifndef NOCOLOR

//SET THE TEXT DISPLAY BACK TO NORMAL COLORS
#define NORMAL "\033[0m"

#define BOLD "\033[1m"
#define UNDERLINE "\033[4m"
#define BLINK "\033[5m"
#define REVERSE "\033[7m"

//text colors
#define BLACK "\033[30m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define MAGENTA "\033[35m"
#define CYAN "\033[36m"
#define WHITE "\033[37m"

//BACKGROUND COLOR
#define BLACK_BACK "\033[40m"
#define RED_BACK "\033[41m"
#define GREEN_BACK "\033[42m"
#define YELLOW_BACK "\033[43m"
#define BLUE_BACK "\033[44m"
#define MAGENTA_BACK "\033[45m"
#define CYAN_BACK "\033[46m"
#define WHITE_BACK "\033[47m"

#else

//SET THE TEXT DISPLAY BACK TO NORMAL COLORS
#define NORMAL ""

#define BOLD ""
#define UNDERLINE ""
#define BLINK ""
#define REVERSE ""

//text colors
#define BLACK ""
#define RED ""
#define GREEN ""
#define YELLOW ""
#define BLUE ""
#define MAGENTA ""
#define CYAN ""
#define WHITE ""

//BACKGROUND COLOR
#define BLACK_BACK ""
#define RED_BACK ""
#define GREEN_BACK ""
#define YELLOW_BACK ""
#define BLUE_BACK ""
#define MAGENTA_BACK ""
#define CYAN_BACK ""
#define WHITE_BACK ""

#endif