def get_termsize():
    """Return terminal size as a tuple (height, width)."""
    try:
        import struct, fcntl, termios
        height, width = struct.unpack('hhhh', fcntl.ioctl(0, termios.
            TIOCGWINSZ, '\x00' * 8))[0:2]
        if not (height and width):
            height, width = 24, 79
    except (ImportError, IOError) as e:
        height, width = 24, 79
    return height, width
