I'm trying to patch a waf issue, where the Windows command prompt output isn't coloured when it's supposed to be. I'm trying to figure out how to actually implement this patch, but I'm having trouble finding sufficient resources - could someone point me in right direction?
Please don't suggest anything that requires Cygwin.
It is possible thanks to ctypes and SetConsoleTextAttribute
Here is an example
from ctypes import *
STD_OUTPUT_HANDLE_ID = c_ulong(0xfffffff5)
windll.Kernel32.GetStdHandle.restype = c_ulong
std_output_hdl = windll.Kernel32.GetStdHandle(STD_OUTPUT_HANDLE_ID)
for color in xrange(16):
windll.Kernel32.SetConsoleTextAttribute(std_output_hdl, color)
print "hello"
If you're keen on using normal cmd.exe consoles for the Python interactive interpreter, see this recipe. If you're OK with using special windows simulating a console, for example because you also need more advanced curses functionality anyway, then @TheLobster's suggestion of wcurses is just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With