code: def _posix_get_window_size():
      
      # see README.txt for reference information
      # http://www.kernel.org/doc/man-pages/online/pages/man4/tty_ioctl.4.html
  
      from fcntl import ioctl
      from termios import TIOCGWINSZ
      from array import array
  
      """
      struct winsize {
          unsigned short ws_row;
          unsigned short ws_col;
          unsigned short ws_xpixel;   /* unused */
          unsigned short ws_ypixel;   /* unused */
      };
      """
      winsize = array("H", [0] * 4)
      try:
          ioctl(sys.stdout.fileno(), TIOCGWINSZ, winsize)
      except IOError:
          # for example IOError: [Errno 25] Inappropriate ioctl for device
          # when output is redirected
          # [ ] TODO: check fd with os.isatty
          pass
      return (winsize[1], winsize[0])
docs: Return (width, height) of console terminal on POSIX system.
         (0, 0) on IOError, i.e. when no console is allocated.