def get_terminal_size():
def ioctl_GWINSZ(fd):<EOL><INDENT>try:<EOL><INDENT>import fcntl<EOL>import termios<EOL>import struct<EOL>cr = struct.unpack('<STR_LIT>', fcntl.ioctl(fd, termios.TIOCGWINSZ,<EOL>'<STR_LIT>'))<EOL><DEDENT>except:<EOL><INDENT>return None<EOL><DEDENT>if cr == (<NUM_LIT:0>, <NUM_LIT:0>):<EOL><INDENT>return None<EOL><DEDENT>if cr == (<NUM_LIT:0>, <NUM_LIT:0>):<EOL><INDENT>return None<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 = (os.environ.get('<STR_LIT>', <NUM_LIT>), os.environ.get('<STR_LIT>', <NUM_LIT>))<EOL><DEDENT>return int(cr[<NUM_LIT:1>]), int(cr[<NUM_LIT:0>])<EOL>
Returns a tuple (x, y) representing the width(x) and the height(x)
    in characters of the terminal window.