Skip to content

Instantly share code, notes, and snippets.

@yggie
Last active August 29, 2015 14:18
Show Gist options
  • Save yggie/51095ae4382acfe4756a to your computer and use it in GitHub Desktop.
Save yggie/51095ae4382acfe4756a to your computer and use it in GitHub Desktop.
Show 256 Terminal Colors with Python
#!/usr/bin/env python
# heavily influenced by:
# https://askubuntu.com/questions/27314/script-to-display-all-terminal-colors
import sys
foreground_only = "-f" in sys.argv[1:] or "--fg-only" in sys.argv[1:]
write = sys.stdout.write
for fgbg in range(38, 48):
for color in range(0, 256):
if (((fgbg - 38)*256 + color) % 15 == 0):
write("\n")
write("\33[%d;5;%dm %02d;5;%03d \33[0m" % (fgbg, color, fgbg, color))
if foreground_only:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment