home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import fcntl
- import os
- import struct
- import termios
-
- def get_terminal_size(fd = 1):
- """Return size of terminal attached to the standard output.
-
- Use ioctl(2) to query a terminal for its size, given a file
- descriptor attached to the terminal. Return (None, None) if this
- fails, otherwise a tuple (columns, rows).
-
- (The optional 'fd' argument can be set to whatever file
- descriptor you want to use. This is useful for unit tests.)
-
- """
-
- try:
- buflen = struct.calcsize('hhhh')
- buf = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\x00' * buflen)
- tuple = struct.unpack('hhhh', buf)
- except:
- return (None, None)
-
- return (tuple[0], tuple[1])
-
-