@cachedmethod
def getConsoleWidth(default=80):
 width = None
 if os.getenv('COLUMNS', '').isdigit():
  width = int(os.getenv('COLUMNS'))
 else:
  try:
   try:
    FNULL = open(os.devnull, 'w')
   except IOError:
    FNULL = None
   process = subprocess.Popen('stty size', shell=True, stdout=subprocess.PIPE, stderr=(FNULL or subprocess.PIPE))
   (stdout, _) = process.communicate()
   items = stdout.split()
   if ((len(items) == 2) and items[1].isdigit()):
    width = int(items[1])
  except (OSError, MemoryError):
   pass
 if (width is None):
  try:
   import curses
   stdscr = curses.initscr()
   (_, width) = stdscr.getmaxyx()
   curses.endwin()
  except:
   pass
 return (width or default)

@ cachedmethod def getConsoleWidth ( default = 80 ) : width = None if os . getenv ( 'COLUMNS' , '' ) . isdigit ( ) : width = int ( os . getenv ( 'COLUMNS' ) ) else : try : try : FNULL = open ( os . devnull , 'w' ) except IOError : FNULL = None process = subprocess . Popen ( 'stty size' , shell = True , stdout = subprocess . PIPE , stderr = ( FNULL or subprocess . PIPE ) ) ( stdout , _ ) = process . communicate ( ) items = stdout . split ( ) if ( ( len ( items ) == 2 ) and items [ 1 ] . isdigit ( ) ) : width = int ( items [ 1 ] ) except ( OSError , MemoryError ) : pass if ( width is None ) : try : import curses stdscr = curses . initscr ( ) ( _ , width ) = stdscr . getmaxyx ( ) curses . endwin ( ) except : pass return ( width or default )
returns console width .