Kees Cook
unread,Feb 24, 2022, 12:53:53 AM2/24/22Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Brendan Higgins, Kees Cook, linux-k...@vger.kernel.org, kuni...@googlegroups.com, David Gow, linux-...@vger.kernel.org, linux-h...@vger.kernel.org
Filling log files with color codes makes diffs and other comparisons
difficult. Only emit vt100 codes when the stdout is a TTY.
Cc: Brendan Higgins <
brendan...@google.com>
Cc:
linux-k...@vger.kernel.org
Cc:
kuni...@googlegroups.com
Signed-off-by: Kees Cook <
kees...@chromium.org>
---
tools/testing/kunit/kunit_parser.py | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
index 05ff334761dd..807ed2bd6832 100644
--- a/tools/testing/kunit/kunit_parser.py
+++ b/tools/testing/kunit/kunit_parser.py
@@ -11,6 +11,7 @@
from __future__ import annotations
import re
+import sys
import datetime
from enum import Enum, auto
@@ -503,14 +504,20 @@ RESET = '\033[0;0m'
def red(text: str) -> str:
"""Returns inputted string with red color code."""
+ if not sys.stdout.isatty():
+ return text
return '\033[1;31m' + text + RESET
def yellow(text: str) -> str:
"""Returns inputted string with yellow color code."""
+ if not sys.stdout.isatty():
+ return text
return '\033[1;33m' + text + RESET
def green(text: str) -> str:
"""Returns inputted string with green color code."""
+ if not sys.stdout.isatty():
+ return text
return '\033[1;32m' + text + RESET
ANSI_LEN = len(red(''))
--
2.30.2