May 22, 2010 11:21
Copy Source |
Copy HTML- # a bit modified code from here
- import os
-
- def getTerminalSize():
- def ioctl_GWINSZ(fd):
- try:
- import fcntl, termios, struct
- cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
- except:
- return None
- return cr
- cr = ioctl_GWINSZ( 0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
- if cr is None :
- try:
- fd = os.open(os.ctermid(), os.O_RDONLY)
- cr = ioctl_GWINSZ(fd)
- os.close(fd)
- except:
- pass
- if cr is None :
- try:
- cr = (os.environ['LINES'], os.environ['COLUMNS'])
- except:
- cr = (25, 80)
- return int(cr[1]), int(cr[ 0])
-
python,
bookmark,
code