home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / computerjanitorapp / terminalsize.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  1.0 KB  |  30 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import fcntl
  5. import os
  6. import struct
  7. import termios
  8.  
  9. def get_terminal_size(fd = 1):
  10.     """Return size of terminal attached to the standard output.
  11.     
  12.     Use ioctl(2) to query a terminal for its size, given a file
  13.     descriptor attached to the terminal. Return (None, None) if this
  14.     fails, otherwise a tuple (columns, rows).
  15.     
  16.     (The optional 'fd' argument can be set to whatever file
  17.     descriptor you want to use. This is useful for unit tests.)
  18.     
  19.     """
  20.     
  21.     try:
  22.         buflen = struct.calcsize('hhhh')
  23.         buf = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\x00' * buflen)
  24.         tuple = struct.unpack('hhhh', buf)
  25.     except:
  26.         return (None, None)
  27.  
  28.     return (tuple[0], tuple[1])
  29.  
  30.