From 2980425cd19b2c30a252b91c324c16a753280a5e Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 2 Feb 2020 17:01:48 +0300 Subject: [PATCH] Fix(python/init.py): Do not use `ColoredFile` at unrecognized terminals --- lib/python/init.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/python/init.py b/lib/python/init.py index 8720caa..f828226 100644 --- a/lib/python/init.py +++ b/lib/python/init.py @@ -175,10 +175,11 @@ def init(): def write(self, value): self.stdout.write(value) - def pprint(self, value): - pprint(value, - stream=ColoredFile(self.stdout, - '\033[1;3%sm' % stdout_color)) + if _term_found: + def pprint(self, value): + pprint(value, + stream=ColoredFile(self.stdout, + '\033[1;3%sm' % stdout_color)) def close(self): self.stdout.close() @@ -207,7 +208,8 @@ def init(): try: pager.pprint(value) except: # noqa - pager.stdout = ColoredFile(pager.stdout, '\033[31m') # red + if _term_found: + pager.stdout = ColoredFile(pager.stdout, '\033[31m') # red print_exc(file=pager) pager.close() @@ -216,7 +218,8 @@ def init(): def excepthook(etype, evalue, etraceback): lines = format_exception(etype, evalue, etraceback) pager = Pager() - pager.stdout = ColoredFile(pager.stdout, '\033[31m') # red + if _term_found: + pager.stdout = ColoredFile(pager.stdout, '\033[31m') # red for line in lines: pager.write(line) pager.close() -- 2.39.2