contrib/churn.py
changeset 5419 041bd297f01e
parent 4955 9bbc0217209b
child 5482 e5eedd74e70f
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):