From 8cc0bdeed81a8f5bea879f2cd1856e0680d773a1 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Wed, 4 Oct 2023 18:51:44 +0200 Subject: [PATCH] pexpect: Remove some unnecessary empty lines This strips the newline from "code_context" (which is really just the called function), and from the unescaped output. Rather, in case the output doesn't end with a newline it'll mark it with an explicit message "(no trailing newline)". --- build_tools/pexpect_helper.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build_tools/pexpect_helper.py b/build_tools/pexpect_helper.py index d8c705949..ca28ce7d4 100644 --- a/build_tools/pexpect_helper.py +++ b/build_tools/pexpect_helper.py @@ -262,7 +262,7 @@ class SpawnedProc(object): filename, lineno, code_context = get_callsite() fmtkeys["filename"] = filename fmtkeys["lineno"] = lineno - fmtkeys["code"] = "\n".join(code_context) + fmtkeys["code"] = "\n".join([n.strip() for n in code_context if n]) if unmatched: print( @@ -285,7 +285,10 @@ class SpawnedProc(object): print("{CYAN}<-------{RESET}".format(**colors)) sys.stdout.write(self.spawn.before) sys.stdout.flush() - print("{RESET}\n{CYAN}------->{RESET}".format(**colors)) + maybe_nl="" + if not self.spawn.before.endswith("\n"): + maybe_nl="\n{CYAN}(no trailing newline)".format(**colors) + print("{RESET}{maybe_nl}{CYAN}------->{RESET}".format(maybe_nl=maybe_nl, **colors)) print("")