From cc6de0b98923f9cb3b4be94571c244b50a2864a3 Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Sun, 10 Nov 2013 06:02:04 +0100 Subject: [PATCH] Guess the console columns in the general case by trying stderr and then stdout --- waflib/Logs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/waflib/Logs.py b/waflib/Logs.py index f387aa35..bfc667fc 100644 --- a/waflib/Logs.py +++ b/waflib/Logs.py @@ -93,16 +93,15 @@ try: except ImportError: pass else: - if got_tty: + for stream in (sys.stderr, sys.stdout): def get_term_cols_real(): """ Private use only. """ - - dummy_lines, cols = struct.unpack("HHHH", \ - fcntl.ioctl(sys.stderr.fileno(),termios.TIOCGWINSZ , \ - struct.pack("HHHH", 0, 0, 0, 0)))[:2] + stuff = fcntl.ioctl(stream.fileno(), termios.TIOCGWINSZ, struct.pack("HHHH", 0, 0, 0, 0)) + dummy_lines, cols = struct.unpack("HHHH", stuff)[:2] return cols + # try the function once to see if it really works try: get_term_cols_real() @@ -110,6 +109,7 @@ else: pass else: get_term_cols = get_term_cols_real + break get_term_cols.__doc__ = """ Get the console width in characters.