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?
我正在尝试修补一个waf问题,其中Windows命令提示符输出在它应该是颜色的时候没有着色。我想弄清楚如何实现这个补丁,但是我找不到足够的资源——有人能给我指出正确的方向吗?
Update 1
Please don't suggest anything that requires Cygwin.
请不要建议任何需要Cygwin的东西。
2 个解决方案
#1
20
It is possible thanks to ctypes and SetConsoleTextAttribute
这要感谢ctype和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"
#2
3
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.
如果你喜欢使用常规的cmd。Python交互式解释器的exe控制台,请参见此菜谱。如果您不介意使用特殊的windows模拟控制台,例如,因为无论如何您也需要更高级的curses功能,那么@TheLobster关于wcurses的建议就很好了。
#1
20
It is possible thanks to ctypes and SetConsoleTextAttribute
这要感谢ctype和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"
#2
3
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.
如果你喜欢使用常规的cmd。Python交互式解释器的exe控制台,请参见此菜谱。如果您不介意使用特殊的windows模拟控制台,例如,因为无论如何您也需要更高级的curses功能,那么@TheLobster关于wcurses的建议就很好了。