parameters: (self, term_stream=sys.stdout)
docstring: Create a `TerminalController` and initialize its attributes
          with appropriate values for the current terminal.
          `term_stream` is the stream that will be used for terminal
          output; if this stream is not a tty, then the terminal is
          assumed to be a dumb terminal (i.e., have no capabilities).
docstring_summary: Create a `TerminalController` and initialize its attributes
          with appropriate values for the current terminal.
          `term_stream` is the stream that will be used for terminal
          output; if this stream is not a tty, then the terminal is
          assumed to be a dumb terminal (i.e., have no capabilities).
docstring_tokens: Create a TerminalController and initialize its attributes with appropriate values for the current terminal . term_stream is the stream that will be used for terminal output ; if this stream is not a tty then the terminal is assumed to be a dumb terminal ( i . e . have no capabilities ) .
function: def __init__(self, term_stream=sys.stdout):
          """
          Create a `TerminalController` and initialize its attributes
          with appropriate values for the current terminal.
          `term_stream` is the stream that will be used for terminal
          output; if this stream is not a tty, then the terminal is
          assumed to be a dumb terminal (i.e., have no capabilities).
          """
          # Curses isn't available on all platforms
          try: import curses
          except: return
  
          # If the stream isn't a tty, then assume it has no capabilities.
          if not term_stream.isatty(): return
  
          # Check the terminal type.  If we fail, then assume that the
          # terminal has no capabilities.
          try: curses.setupterm()
          except: return
  
          # Look up numeric capabilities.
          self.COLS = curses.tigetnum('cols')
          self.LINES = curses.tigetnum('lines')
          self.XN = curses.tigetflag('xenl')
          
          # Look up string capabilities.
          for capability in self._STRING_CAPABILITIES:
              (attrib, cap_name) = capability.split('=')
              setattr(self, attrib, self._tigetstr(cap_name) or '')
  
          # Colors
          set_fg = self._tigetstr('setf')
          if set_fg:
              for i,color in zip(range(len(self._COLORS)), self._COLORS):
                  setattr(self, color, self._tparm(set_fg, i))
          set_fg_ansi = self._tigetstr('setaf')
          if set_fg_ansi:
              for i,color in zip(range(len(self._ANSICOLORS)), self._ANSICOLORS):
                  setattr(self, color, self._tparm(set_fg_ansi, i))
          set_bg = self._tigetstr('setb')
          if set_bg:
              for i,color in zip(range(len(self._COLORS)), self._COLORS):
                  setattr(self, 'BG_'+color, self._tparm(set_bg, i))
          set_bg_ansi = self._tigetstr('setab')
          if set_bg_ansi:
              for i,color in zip(range(len(self._ANSICOLORS)), self._ANSICOLORS):
                  setattr(self, 'BG_'+color, self._tparm(set_bg_ansi, i))
function_tokens: def __init__ ( self , term_stream = sys . stdout ) : # Curses isn't available on all platforms try : import curses except : return # If the stream isn't a tty, then assume it has no capabilities. if not term_stream . isatty ( ) : return # Check the terminal type.  If we fail, then assume that the # terminal has no capabilities. try : curses . setupterm ( ) except : return # Look up numeric capabilities. self . COLS = curses . tigetnum ( 'cols' ) self . LINES = curses . tigetnum ( 'lines' ) self . XN = curses . tigetflag ( 'xenl' ) # Look up string capabilities. for capability in self . _STRING_CAPABILITIES : ( attrib , cap_name ) = capability . split ( '=' ) setattr ( self , attrib , self . _tigetstr ( cap_name ) or '' ) # Colors set_fg = self . _tigetstr ( 'setf' ) if set_fg : for i , color in zip ( range ( len ( self . _COLORS ) ) , self . _COLORS ) : setattr ( self , color , self . _tparm ( set_fg , i ) ) set_fg_ansi = self . _tigetstr ( 'setaf' ) if set_fg_ansi : for i , color in zip ( range ( len ( self . _ANSICOLORS ) ) , self . _ANSICOLORS ) : setattr ( self , color , self . _tparm ( set_fg_ansi , i ) ) set_bg = self . _tigetstr ( 'setb' ) if set_bg : for i , color in zip ( range ( len ( self . _COLORS ) ) , self . _COLORS ) : setattr ( self , 'BG_' + color , self . _tparm ( set_bg , i ) ) set_bg_ansi = self . _tigetstr ( 'setab' ) if set_bg_ansi : for i , color in zip ( range ( len ( self . _ANSICOLORS ) ) , self . _ANSICOLORS ) : setattr ( self , 'BG_' + color , self . _tparm ( set_bg_ansi , i ) )