diff options
author | Rafael H. Schloming <rhs@apache.org> | 2009-06-02 17:28:12 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2009-06-02 17:28:12 +0000 |
commit | 4d1172e4903e1902b3ba8a6c9e9b47bc3f7aa7e8 (patch) | |
tree | f752dfd2870aa3a2130fc9d1460c8fd46bc1b3bd /python/qpid-python-test | |
parent | e81d11bfb94e63f56448d4984f2e2dca39d19f46 (diff) | |
download | qpid-python-4d1172e4903e1902b3ba8a6c9e9b47bc3f7aa7e8.tar.gz |
detect the terminal width when possible
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@781087 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid-python-test')
-rwxr-xr-x | python/qpid-python-test | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/python/qpid-python-test b/python/qpid-python-test index b893d3698f..d02f2ac6cc 100755 --- a/python/qpid-python-test +++ b/python/qpid-python-test @@ -18,7 +18,7 @@ # under the License. # -import optparse, os, sys, logging, traceback, types +import fcntl, logging, optparse, os, struct, sys, termios, traceback, types from fnmatch import fnmatchcase as match from getopt import GetoptError from logging import getLogger, StreamHandler, Formatter, Filter, \ @@ -98,6 +98,18 @@ def included(path): return True return False +def width(): + if sys.stdout.isatty(): + s = struct.pack("HHHH", 0, 0, 0, 0) + fd_stdout = sys.stdout.fileno() + x = fcntl.ioctl(fd_stdout, termios.TIOCGWINSZ, s) + rows, cols, xpx, ypx = struct.unpack("HHHH", x) + return cols + else: + return 80 + +WIDTH = width() + def vt100_attrs(*attrs): return "\x1B[%sm" % ";".join(map(str, attrs)) @@ -156,6 +168,9 @@ class StreamWrapper: self.stream = stream self.prefix = prefix + def fileno(self): + return self.stream.fileno() + def isatty(self): return self.stream.isatty() @@ -251,6 +266,8 @@ class Runner: print "Error during %s:" % name print indent("".join(traceback.format_exception(*info))).rstrip() +ST_WIDTH = 8 + def run_test(name, test, config): patterns = filter.patterns level = root.level @@ -262,7 +279,7 @@ def run_test(name, test, config): output = "" for part in parts: if line: - if len(line) + len(part) >= 71: + if len(line) + len(part) >= (WIDTH - ST_WIDTH - 1): output += "%s. \\\n" % line line = " %s" % part else: @@ -271,7 +288,7 @@ def run_test(name, test, config): line = part if line: - output += "%s %s" % (line, ((72 - len(line))*".")) + output += "%s %s" % (line, (((WIDTH - ST_WIDTH) - len(line))*".")) sys.stdout.write(output) sys.stdout.flush() interceptor.begin() |