SConstruct should use colored()
SConstruct hard-codes terminal escape sequences to get color. Python3 makes this available through
from termcolor import colored
print(colored("foo","red))
Using this would make the code more readable. Also, you repeat the two branches of the code depending on whether you have a tty. You could do this:
if sys.stdout.isatty():
from termcolor import colored
else:
def colored(x,_):
return x # no color from colored
Comments (3)
-
repo owner -
reporter Well, one can always say
pip3 install --user termcolor
and it will be available. Roland likes to ask “what if pip isn’t installed?” Apparently, he knows of some machine somewhere that has Python without Pip.I’d at least recommend factoring out the colors into a hash
if sys.stdout.isatty(): colors = { "red": "\033...", "blue":... } else: colors = { "red": "", "blue": "", ...}
Then using the colors boy name.
-
repo owner I have made a version of SConstruct that uses termcolor where available and turns off colors if it’s not; with an message with information about how to install termcolor.
Let me know if you think this is okay.
- Log in to comment
It may not be a good idea to use termcolor as it is not a standard package and it may not be available. For example on chirp (a machine I use in Dublin) it is not installed.