Skip to content

Instantly share code, notes, and snippets.

@justinabrahms
Forked from graven/colortest.py
Created June 26, 2011 17:10
  • Star 37 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save justinabrahms/1047767 to your computer and use it in GitHub Desktop.
Small utility to test terminal support for 256-color output.
#!/usr/bin/env python
# Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349
print "Color indexes should be drawn in bold text of the same color."
print
colored = [0] + [0x5f + 40 * n for n in range(0, 5)]
colored_palette = [
"%02x/%02x/%02x" % (r, g, b)
for r in colored
for g in colored
for b in colored
]
grayscale = [0x08 + 10 * n for n in range(0, 24)]
grayscale_palette = [
"%02x/%02x/%02x" % (a, a, a)
for a in grayscale
]
normal = "\033[38;5;%sm"
bold = "\033[1;38;5;%sm"
reset = "\033[0m"
for (i, color) in enumerate(colored_palette + grayscale_palette, 16):
index = (bold + "%4s" + reset) % (i, str(i) + ':')
hex = (normal + "%s" + reset) % (i, color)
newline = '\n' if i % 6 == 3 else ''
print index, hex, newline,
@AdaFrame
Copy link

It should be noted that this is for Python 2.X, not 3

@jpanganiban
Copy link

Just change use print like functions and it should work on python 2 and 3. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment