[C/C Linux] Programming C with palette in linux – Programming C in linux with color

An example opening nhá:

color in C on linux

#include <iostream>
using namespace std;

int main(int argc, char **argv)
{
	cout << "E[" << 1 << "m" << "E[" << 31<< "m" << "E[" << 44 << "m" << "t" << "nguyenvanquan7826"<<"t";
   
	cout << "E[0m" << endl; // Ket thuc xu dung mau
   
	cout<< "E[" 		// ma bat dau
		<< 1 << "m"		// 1: chu in dam, 0 : chu thuong
		<< "E[" 
		<< 34 << "m"	// 30->38 : mau chu
		<< "E[" 
		<< 45 << "m"	// 40->48 : mau nen
		<<"t"
		<< "Quyet dinh"	// text
		<<"t"
		<<endl;
	cout << "E[0m" << endl;	//ket thuc su dung mau
   return 0;
}

A little fuller:

color in C with linux

#include <iostream>
using namespace std;

// Set a few standards to make formatting easier.
const string NC = "E[0m"; // No Color (reset to default)
const string HOME_CURSOR  = "E[0;0H"; // Place the cursor at 0;0 position.
const string CLEAR_SCREEN = "E[2J";

int main(int argc, char **argv)
{
	// Clear the screen and reset the cursor to the top left.
	cout << CLEAR_SCREEN << HOME_CURSOR;

	// print program name.
	cout << endl << argv[0] << endl;

	// display the color table.
	cout << "B;FG;BGt";
	for (int i = 40; i < 48; i++)
		cout << "  " << i << "mt";
	cout << endl;
	for (int fg = 30; fg < 38; fg++)
		for (int h = 0; h < 2; h++)
		{
			cout << NC << h << ";" << fg << "m";
			for (int bg = 40; bg < 48; bg++)
			{
				cout<< "t"
					<< "E[" 
					<< h << "m"
					<< "E[" 
					<< fg << "m"
					<< "E[" 
					<< bg << "m"
					<< "  RgB  ";
			}
			cout << endl;
		}	

	// Reset the console to no colors.
	cout << NC << endl;

	return 0;
}

If you are interested in more then Click here.