def terminal_size(file=None):
 if (file is None):
  file = _get_stdout()
 try:
  s = struct.pack(str(u'HHHH'), 0, 0, 0, 0)
  x = fcntl.ioctl(file, termios.TIOCGWINSZ, s)
  (lines, width, xpixels, ypixels) = struct.unpack(str(u'HHHH'), x)
  if (lines > 12):
   lines -= 6
  if (width > 10):
   width -= 1
  if ((lines <= 0) or (width <= 0)):
   raise Exception(u'unable to get terminal size')
  return (lines, width)
 except Exception:
  try:
   return (int(os.environ.get(u'LINES')), int(os.environ.get(u'COLUMNS')))
  except TypeError:
   lines = conf.max_lines
   width = conf.max_width
   if (lines is None):
    lines = 25
   if (width is None):
    width = 80
   return (lines, width)

def terminal_size ( file = None ) : if ( file is None ) : file = _get_stdout ( ) try : s = struct . pack ( str ( u'HHHH' ) , 0 , 0 , 0 , 0 ) x = fcntl . ioctl ( file , termios . TIOCGWINSZ , s ) ( lines , width , xpixels , ypixels ) = struct . unpack ( str ( u'HHHH' ) , x ) if ( lines > 12 ) : lines -= 6 if ( width > 10 ) : width -= 1 if ( ( lines <= 0 ) or ( width <= 0 ) ) : raise Exception ( u'unable to get terminal size' ) return ( lines , width ) except Exception : try : return ( int ( os . environ . get ( u'LINES' ) ) , int ( os . environ . get ( u'COLUMNS' ) ) ) except TypeError : lines = conf . max_lines width = conf . max_width if ( lines is None ) : lines = 25 if ( width is None ) : width = 80 return ( lines , width )
returns a tuple containing the height and width of the terminal .