I have always thought that there is no possible formatting on the command line, as everything I have read says.
However, I recently discovered that pywikipedia (a python bot framework for automatically editing wikipedia-style wikis) can output text to the command line (the normal windows cmd.exe
) in different colours!
This is the python syntax:
import wikipedia
wikipedia.output(u"\03{lightpurple}"+s+"\03{default}")
You have to use wikipedia.output()
(or pywikibot.output()
) but not just print
.
The online pywikipedia repository (around line 7990) gives a short explanation:
text can contain special sequences to create colored output. These
consist of the escape character \03 and the color name in curly braces,
e. g. \03{lightpurple}. \03{default} resets the color.
I think it is probably to do with this line:
ui.output(text, toStdout = toStdout)
But I can't find any reference to a ui
class.
So how does Pywikipedia manage it?