2011/10/22

C++: print color text for tarminal

#include
using namespace std;

int main(int argc, char *argv[])
{
   cout << "\x1b[1;31mSample" << "\x1b[0;32m Test" << endl;
   cout << "\x1b[0m" << endl;

   return 0;
}

Python: print color text for terminal

import sys

sys.stdout.write("\x1b[1;31mSample" + "\x1b[0;32m Test")
sys.stdout.write("\x1b[0m")