Skip to content

Instantly share code, notes, and snippets.

@cvzi
Created August 21, 2020 20:31
Show Gist options
  • Save cvzi/15199241f8e4f47f9ea69eb190b024e0 to your computer and use it in GitHub Desktop.
Save cvzi/15199241f8e4f47f9ea69eb190b024e0 to your computer and use it in GitHub Desktop.
List all colors available in your terminal or console with VT100 virtual terminal sequences
"""
List all colors available in your terminal with VT100 sequences
"""
from __future__ import print_function
import ctypes
if hasattr(ctypes, 'WinDLL'):
# In some Windows consoles you need to enable support for theses sequences. See:
# Enable VT100 sequences "Console Virtual Terminal Sequences" for colored font/background in the Windows terminal
# https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#example-of-sgr-terminal-sequences
import ctypes
kernel32 = ctypes.WinDLL('kernel32')
stdOut = kernel32.GetStdHandle(-11)
consoleMode = ctypes.c_ulong()
kernel32.GetConsoleMode(stdOut, ctypes.byref(consoleMode))
consoleMode.value |= 4
kernel32.SetConsoleMode(stdOut, consoleMode)
END = '\033[0m'
BLUE = '\033[96m'
UNDERLINE = '\033[4m'
print(UNDERLINE + BLUE + 'All colors:' + END + "\n")
for x in range(0, 50):
s = '%03d: \033[%dm\\033[%dm' + END
print(s % (x, x, x), end="")
x += 50
print("\t\t" + s % (x, x, x), end="")
x += 50
print("\t\t" + s % (x, x, x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment