comparison contrib/churn.py @ 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 9bbc0217209b
children
comparison
equal deleted inserted replaced
5418:9b469bdb1ce1 5419:041bd297f01e
20 try: 20 try:
21 return int(os.environ['COLUMNS']) 21 return int(os.environ['COLUMNS'])
22 except ValueError: 22 except ValueError:
23 pass 23 pass
24 try: 24 try:
25 import termios, fcntl, struct 25 import termios, array, fcntl
26 buf = 'abcd'
27 for dev in (sys.stdout, sys.stdin): 26 for dev in (sys.stdout, sys.stdin):
28 try: 27 try:
29 if buf != 'abcd':
30 break
31 fd = dev.fileno() 28 fd = dev.fileno()
32 if not os.isatty(fd): 29 if not os.isatty(fd):
33 continue 30 continue
34 buf = fcntl.ioctl(fd, termios.TIOCGWINSZ, buf) 31 arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8)
32 return array.array('h', arri)[1]
35 except ValueError: 33 except ValueError:
36 pass 34 pass
37 if buf != 'abcd':
38 return struct.unpack('hh', buf)[1]
39 except ImportError: 35 except ImportError:
40 pass 36 pass
41 return 80 37 return 80
42 38
43 def __gather(ui, repo, node1, node2): 39 def __gather(ui, repo, node1, node2):