changeset 5419:041bd297f01e

churn: simplify code to get terminal width
author Christian Ebert <blacktrash@gmx.net>
date Wed, 12 Sep 2007 12:54:36 +0200
parents 9b469bdb1ce1
children 6d1bd20ae14d
files contrib/churn.py
diffstat 1 files changed, 3 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/churn.py	Mon Oct 08 22:20:23 2007 +0200
+++ b/contrib/churn.py	Wed Sep 12 12:54:36 2007 +0200
@@ -22,20 +22,16 @@
         except ValueError:
             pass
     try:
-        import termios, fcntl, struct
-        buf = 'abcd'
+        import termios, array, fcntl
         for dev in (sys.stdout, sys.stdin):
             try:
-                if buf != 'abcd':
-                    break
                 fd = dev.fileno()
                 if not os.isatty(fd):
                     continue
-                buf = fcntl.ioctl(fd, termios.TIOCGWINSZ, buf)
+                arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8)
+                return array.array('h', arri)[1]
             except ValueError:
                 pass
-        if buf != 'abcd':
-           return struct.unpack('hh', buf)[1]
     except ImportError:
         pass
     return 80