SConstruct should use colored()

Issue #3 new
Steven R. Brandt created an issue

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)

  1. Peter Diener repo owner

    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.

  2. Steven R. Brandt 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.

  3. Peter Diener 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.

  4. Log in to comment