def getTerminalSize():
env = os.environ<EOL>def ioctl_GWINSZ(fd):<EOL><INDENT>try:<EOL><INDENT>import fcntl, termios, struct<EOL>cr = struct.unpack('<STR_LIT>', fcntl.ioctl(fd, termios.TIOCGWINSZ, '<STR_LIT>'))<EOL><DEDENT>except:<EOL><INDENT>return<EOL><DEDENT>return cr<EOL><DEDENT>cr = ioctl_GWINSZ(<NUM_LIT:0>) or ioctl_GWINSZ(<NUM_LIT:1>) or ioctl_GWINSZ(<NUM_LIT:2>)<EOL>if not cr:<EOL><INDENT>try:<EOL><INDENT>fd = os.open(os.ctermid(), os.O_RDONLY)<EOL>cr = ioctl_GWINSZ(fd)<EOL>os.close(fd)<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if not cr:<EOL><INDENT>cr = (env.get('<STR_LIT>', <NUM_LIT>), env.get('<STR_LIT>', <NUM_LIT>))<EOL><DEDENT>return int(cr[<NUM_LIT:1>]), int(cr[<NUM_LIT:0>])<EOL>
Returns terminal width, height