I tried to colorized my text in cmd using the code below, but it does not.
`def highlight(colour, text):
if colour == "black":
return "\033[1;40m" + str(text) + "\033[1;m"
if colour == "red":
return "\033[1;41m" + str(text) + "\033[1;m"
if colour == "green":
return "\033[1;42m" + str(text) + "\033[1;m"
if colour == "yellow":
return "\033[1;43m" + str(text) + "\033[1;m"
if colour == "blue":
return "\033[1;44m" + str(text) + "\033[1;m"
if colour == "magenta":
return "\033[1;45m" + str(text) + "\033[1;m"
if colour == "cyan":
return "\033[1;46m" + str(text) + "\033[1;m"
if colour == "gray":
return "\033[1;47m" + str(text) + "\033[1;m"
return str(text)
print(highlight("black", "Highlight: black"))
print(highlight("red", "Highlight: red"))
print(highlight("green", "Highlight: green"))
print(highlight("yellow", "Highlight: yellow"))
print(highlight("blue", "Highlight: blue"))
print(highlight("magenta", "Highlight: magenta"))
print(highlight("cyan", "Highlight: cyan"))
print(highlight("gray", "Highlight: gray"))
This is the Output:
←[1;40mHighlight: black←[1;m
←[1;41mHighlight: red←[1;m
←[1;42mHighlight: green←[1;m
←[1;43mHighlight: yellow←[1;m
←[1;44mHighlight: blue←[1;m
←[1;45mHighlight: magenta←[1;m
←[1;46mHighlight: cyan←[1;m
←[1;47mHighlight: gray←[1;m`
Do you guys have any idea how to colorized/hightlight text without using any non-built in imports (eg. colorama)?
You need to make sure to enable
ENABLE_VT_PROCESSINGbefore using escape sequences. You can do that with the following snippet:Just call that once at the top of your script.