[PATCH] churn: simplify code to get terminal width
Christian Ebert
blacktrash at gmx.net
Wed Jul 25 01:12:26 CDT 2007
* Christian Ebert on Tuesday, July 24, 2007 at 15:52:00 +0200
> churn: simplify code to get terminal width
oops, don't know why this worked for me; this should be better:
# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1185343717 -7200
# Node ID 1e1f57f6597963ca31ae97e999234e3bac2d76c1
# Parent a0d37976cd5bbea3cadbea6ed305ae55bcf369b0
churn: simplify code to get terminal width
Until progressbar is included steal its array part.
diff --git a/contrib/churn.py b/contrib/churn.py
--- a/contrib/churn.py
+++ b/contrib/churn.py
@@ -22,20 +22,17 @@ def get_tty_width():
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)
+ lines, columns = array.array('h', arri)[:2]
+ return columns
except ValueError:
pass
- if buf != 'abcd':
- return struct.unpack('hh', buf)[1]
except ImportError:
pass
return 80
More information about the Mercurial-devel
mailing list