Created
July 9, 2020 01:06
-
-
Save Leedehai/ab6601cbe7fd95a0f1c7f4647caa5750 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 | |
# Ported to Python from http://www.vim.org/scripts/script.php?script_id=1349 | |
print("xterm-256color color set\n") | |
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_str = (normal + "%s" + reset) % (i, color) | |
newline = '\n' if i % 6 == 3 else '' | |
print("%s %s %s" % (index, hex_str, newline), end="") | |
print("normal: \\033[38;5;XXm.") | |
print("bold: \\033[1;38;5;XXm") | |
print("background: \\033[48;5;XXm") | |
print("reset: \\033[0m") | |
print("For Python, use \\x1b[ instead of \\033[") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment