Skip to content

Instantly share code, notes, and snippets.

@startling
Created March 11, 2012 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save startling/2015230 to your computer and use it in GitHub Desktop.
Save startling/2015230 to your computer and use it in GitHub Desktop.
Display 256 colors in your terminal, if it supports it.
import sys
for i, n in enumerate(xrange(232)):
# for each color, print two spaces with that background
sys.stdout.write("\x1b[48;5;%dm " % n)
# and then back to the default color
sys.stdout.write("\x1b[49m")
# every 6 numbers after the first three,
# put in a newline
if (i - 3) % 6 == 0:
print
# lazy newlines
print
print
# colors 232-255 are a grayscale ramp
for n in range(232, 256):
sys.stdout.write("\x1b[48;5;%dm " % n)
sys.stdout.write("\x1b[49m")
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment