mirror of
https://github.com/AdaCore/langkit.git
synced 2026-02-12 12:28:12 -08:00
Disable colored output if stdout or stderr is not a TTY
This will make it easy to spread colors everywhere without worrying about garbage test baselines. It will also clean build logs. Change-Id: I976b74fe1712ea8e5fbfd4476f4814ae375448eb TN: minor
This commit is contained in:
@@ -10,6 +10,7 @@ from copy import copy
|
||||
from itertools import takewhile
|
||||
|
||||
import inspect
|
||||
import sys
|
||||
|
||||
|
||||
class StructEq(object):
|
||||
@@ -95,6 +96,22 @@ class Colors:
|
||||
WARNING = YELLOW
|
||||
FAIL = RED
|
||||
|
||||
@classmethod
|
||||
def disable_colors(cls):
|
||||
"""
|
||||
Reset color codes to empty strings.
|
||||
"""
|
||||
for name in dir(cls):
|
||||
value = getattr(cls, name)
|
||||
if (all(c.isalpha() for c in name) and
|
||||
name.upper() == name and
|
||||
isinstance(value, str)):
|
||||
setattr(cls, name, '')
|
||||
|
||||
|
||||
if not sys.stdout.isatty() or not sys.stderr.isatty():
|
||||
Colors.disable_colors()
|
||||
|
||||
|
||||
def col(msg, color):
|
||||
return "{0}{1}{2}".format(color, msg, Colors.ENDC)
|
||||
|
||||
Reference in New Issue
Block a user