01/10/2018, 21:48
[C/C++ Linux] Lập trình C với bảng màu trong linux – Programming C in linux with color
[C/C++ Linux] Lập trình C với bảng màu trong linux – Programming C in linux with color Tháng Bảy 16, 2013 nguyenvanquan7826 Linux, LT C - C++ Leave a response Một ví dụ mở màn nhá: #include <iostream> using namespace ...
[C/C++ Linux] Lập trình C với bảng màu trong linux – Programming C in linux with color
Một ví dụ mở màn nhá:

#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;
}
Đầy đủ hơn một chút:

#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;
}
Nếu bạn quan tâm nhiều hơn thì vào đây.