code: def _GetTermSizePosix():
      """Returns the Posix terminal x and y dimensions."""
      # pylint: disable=g-import-not-at-top
      import fcntl
  
      # pylint: disable=g-import-not-at-top
      import struct
  
      # pylint: disable=g-import-not-at-top
      import termios
  
      def _GetXY(fd):
          """Returns the terminal (x,y) size for fd.
  
          Args:
            fd: The terminal file descriptor.
  
          Returns:
            The terminal (x,y) size for fd or None on error.
          """
          try:
              # This magic incantation converts a struct from ioctl(2) containing two
              # binary shorts to a (rows, columns) int tuple.
              rc = struct.unpack(
                  b"hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "junk")
              )
              return (rc[1], rc[0]) if rc else None
          except:  # pylint: disable=bare-except
              return None
  
      xy = _GetXY(0) or _GetXY(1) or _GetXY(2)
      if not xy:
          fd = None
          try:
              fd = os.open(os.ctermid(), os.O_RDONLY)
              xy = _GetXY(fd)
          except:  # pylint: disable=bare-except
              xy = None
          finally:
              if fd is not None:
                  os.close(fd)
      return xy
  
file_path: python-fire/fire/console/console_attr_os.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import unicode_literals
  import os
  import sys
  from fire.console import encoding
label_desc: Use image node_id 2 for calling a global function with example usage: _GetTermSizePosix() and returns: xy, unknown, None