#!/usr/bin/env python
import sys
import argparse

parser = argparse.ArgumentParser(description='Print a colour chart.')
parser.add_argument('-g', '--gaps', dest='gaps', action='store_true',
                   help='print gaps between colours')
parser.add_argument('-e', '--escapes', dest='escapes', action='store_true',
                   help='print the escape code before each colour code')

args = parser.parse_args()

g = ' ' if args.gaps else ''
es = '\\e[' if args.escapes else ''
ee = 'm' if args.escapes else ''
print "--------------------------------------------------------------------------------"
print "                                  Colour Chart"
print ""
# 0 and 1 for not bold and bold
for b in ['', '5;']:
   for i in [0,1]:
      # foreground
       for j in range(30, 38):
           # background
           for k in range(40, 48):
                print '\b\033[%d;%d;%s%dm %s%d;%d;%s%d%s \x1B[m%s' % (i, j, b, k, es, i, j, b, k, ee, g),
           print ""
   if args.gaps:
      print ""
# horizontal gap
print ""
print "--------------------------------------------------------------------------------"
