Here's my script that currently sets up my prompts for all of my computers (whether they're Windows, Red Hat, or OS X):
import sys
import datetime
import platform
if platform.system() is 'Windows':
tealUText = ""
tealText = ""
greenText = ""
defaultText = ""
else:
tealUText = "\001\033[4;36m\002"
tealText = "\001\033[0;36m\002"
greenText = "\001\033[0;32m\002"
defaultText = "\001\033[0;0m\002"
class ClockPS1(object):
def __repr__(self):
now = datetime.datetime.now()
clock = str(now.strftime("%H:%M:%S"))
return tealUText + clock + greenText + " >>> " + defaultText
sys.ps1 = ClockPS1()
sys.ps2 = greenText + " ... " + defaultText
On all systems this prints out the current time followed by the normal ">>>" prompt on the first line, and then if I have a multiline input it has the normal "..." prompt, but indented so that it aligns with the ">>>" prompt (remember that that prompt is prefixed by the current time).
Here's the question though: On every platform besides Windows, the current time prints in teal (and underlined), the prompts are in green, and whatever I type shows up in a normal color. How can I achieve this same thing in Windows? I've seen a few solutions suggested, but they rely on calling functions while the message is printing, which I don't think would work for me on account of the fact that the ps
variables just call __repr__
on whatever is assigned to them, right?
(By the way, I got this time trick from here: python: display elapsed time on shell)
termcolor
orcolorama
that is more portable (the homepage ofcolorama
shows that it is able to work on Windows, although not all properties are supported). – Afternoons