From b029c79e63d5a6552c88b5dee7c12341db87f8ac Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Thu, 4 Jul 2013 22:54:29 -0400 Subject: [PATCH] Send header to stderr; omit instructions if piped --- terminal.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/terminal.py b/terminal.py index 098e278..f23767a 100755 --- a/terminal.py +++ b/terminal.py @@ -123,13 +123,15 @@ class Jimterm: self.add_cr = add_cr self.raw = raw - def print_header(self, nodes, bauds): + def print_header(self, nodes, bauds, output = sys.stdout, piped = False): for (n, (node, baud)) in enumerate(zip(nodes, bauds)): - print (self.color.code(n) - + node + ", " + str(baud) + " baud" - + self.color.reset) - print "^C to exit" - print "----------" + output.write(self.color.code(n) + + node + ", " + str(baud) + " baud" + + self.color.reset + "\n") + if not piped: + output.write("^C to exit\n") + output.write("----------\n") + output.flush() def start(self): self.alive = True @@ -352,5 +354,5 @@ if __name__ == "__main__": raw = raw, color = (os.name == "posix" and not args.mono)) if not quiet: - term.print_header(nodes, bauds) + term.print_header(nodes, bauds, sys.stderr, piped) term.run()