code: def TerminalSize():
    
    try:
      with open(os.ctermid(), 'r') as tty_instance:
        length_width = struct.unpack(
            'hh', fcntl.ioctl(tty_instance.fileno(), termios.TIOCGWINSZ, '1234'))
    except (IOError, OSError):
      try:
        length_width = (int(os.environ['LINES']),
                        int(os.environ['COLUMNS']))
      except (ValueError, KeyError):
        length_width = (24, 80)
    return length_width
docs: Returns terminal length and width as a tuple.