Use isatty to control console colors.
authorDavid Anderson <dvander@alliedmods.net>
Sun Feb 02 10:47:48 2014 -0800 (2014-02-02)
changeset 23441956ca47d92
parent 233 61d5d67d6456
child 235 fd0f5f1a7a10
Use isatty to control console colors.
ambuild2/util.py
     1.1 --- a/ambuild2/util.py	Sun Feb 02 01:31:08 2014 -0800
     1.2 +++ b/ambuild2/util.py	Sun Feb 02 10:47:48 2014 -0800
     1.3 @@ -306,18 +306,29 @@
     1.4  def con_print(fp, args):
     1.5    for arg in args:
     1.6      if IsColor(arg):
     1.7 -      if not sConsoleColorsEnabled:
     1.8 -        continue
     1.9        arg(fp)
    1.10      else:
    1.11        fp.write(arg)
    1.12    fp.write('\n')
    1.13  
    1.14 +def con_print_simple(fp, args):
    1.15 +  for arg in args:
    1.16 +    if IsColor(arg):
    1.17 +      continue
    1.18 +    fp.write(arg)
    1.19 +  fp.write('\n')
    1.20 +
    1.21  def con_out(*args):
    1.22 -  con_print(sys.stdout, args)
    1.23 +  if sys.stdout.isatty():
    1.24 +    con_print(sys.stdout, args)
    1.25 +  else:
    1.26 +    con_print_simple(sys.stdout, args)
    1.27  
    1.28  def con_err(*args):
    1.29 -  con_print(sys.stderr, args)
    1.30 +  if sys.stderr.isatty():
    1.31 +    con_print(sys.stderr, args)
    1.32 +  else:
    1.33 +    con_print_simple(sys.stderr, args)
    1.34  
    1.35  LambdaType = type(lambda: None)
    1.36