(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).
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).
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 ) .
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 ImportError:
            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 Exception:
            return

        # Look up numeric capabilities.
        self.COLS = curses.tigetnum("cols")
        self.LINES = curses.tigetnum("lines")

        # 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) or "")
        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) or "")
        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) or "")
        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) or "")
def __init__ ( self , term_stream = sys . stdout ) : # Curses isn't available on all platforms try : import curses except ImportError : 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 Exception : return # Look up numeric capabilities. self . COLS = curses . tigetnum ( "cols" ) self . LINES = curses . tigetnum ( "lines" ) # 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 ) or "" ) 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 ) or "" ) 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 ) or "" ) 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 ) or "" )