Created
August 21, 2014 20:36
-
-
Save hamiltont/9d0bf2ab3a716a31d642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# print grid of all colors and brightnesses | |
# uses stdout.write to write chars with no newline nor spaces between them | |
# This should run more-or-less identically on Windows and Unix. | |
from __future__ import print_function | |
import sys | |
from colorama import init, Fore, Back, Style | |
init() | |
# Fore, Back and Style are convenience classes for the constant ANSI strings that set | |
# the foreground, background and style. The don't have any magic of their own. | |
FORES = [ Fore.BLACK, Fore.RED, Fore.GREEN, Fore.YELLOW, Fore.BLUE, Fore.MAGENTA, Fore.CYAN, Fore.WHITE ] | |
BACKS = [ Back.BLACK, Back.RED, Back.GREEN, Back.YELLOW, Back.BLUE, Back.MAGENTA, Back.CYAN, Back.WHITE ] | |
STYLES = [ Style.DIM, Style.NORMAL, Style.BRIGHT ] | |
NAMES = { | |
Fore.BLACK: 'black', Fore.RED: 'red', Fore.GREEN: 'green', Fore.YELLOW: 'yellow', Fore.BLUE: 'blue', Fore.MAGENTA: 'magenta', Fore.CYAN: 'cyan', Fore.WHITE: 'white' | |
, Fore.RESET: 'reset', | |
Back.BLACK: 'black', Back.RED: 'red', Back.GREEN: 'green', Back.YELLOW: 'yellow', Back.BLUE: 'blue', Back.MAGENTA: 'magenta', Back.CYAN: 'cyan', Back.WHITE: 'white', | |
Back.RESET: 'reset' | |
} | |
# show the color names | |
sys.stdout.write(' ') | |
for foreground in FORES: | |
sys.stdout.write('%s%-7s' % (foreground, NAMES[foreground])) | |
print() | |
# make a row for each background color | |
for background in BACKS: | |
sys.stdout.write('%s%-7s%s %s' % (background, NAMES[background], Back.RESET, background)) | |
# make a column for each foreground color | |
for foreground in FORES: | |
sys.stdout.write(foreground) | |
# show dim, normal bright | |
for brightness in STYLES: | |
sys.stdout.write('%sX ' % brightness) | |
sys.stdout.write(Style.RESET_ALL + ' ' + background) | |
print(Style.RESET_ALL) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment