code: def terminal_get_size(default_size=(25, 80)):
      
  
      def ioctl_gwinsz(fd):  # TABULATION FUNCTIONS
          try:  # Discover terminal width
              return struct.unpack(
                  'hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234')
              )
          except Exception:
              return None
  
      # try open fds
      size = ioctl_gwinsz(0) or ioctl_gwinsz(1) or ioctl_gwinsz(2)
      if not size:
          # ...then ctty
          try:
              fd = os.open(os.ctermid(), os.O_RDONLY)
              size = ioctl_gwinsz(fd)
              os.close(fd)
          except Exception:
              pass
      if not size:
          # env vars or finally defaults
          try:
              size = (os.environ['LINES'], os.environ['COLUMNS'])
          except Exception:
              return default_size
  
      return map(int, size)
docs: Return (number of rows, number of columns) for the terminal,
      if they can be determined, or `default_size` if they can't.