def __init__(self, term_stream=sys.stdout):
<EOL>try: import curses<EOL>except: return<EOL>if not term_stream.isatty(): return<EOL>try: curses.setupterm()<EOL>except: return<EOL>self.COLS ,self.LINES = self.size()<EOL>for capability in self._STRING_CAPABILITIES:<EOL><INDENT>(attrib, cap_name) = capability.split('<STR_LIT:=>')<EOL>setattr(self, attrib, self._tigetstr(cap_name) or '<STR_LIT>')<EOL><DEDENT>set_fg = self._tigetstr('<STR_LIT>')<EOL>if set_fg:<EOL><INDENT>for i,color in zip(list(range(len(self._COLORS))), self._COLORS):<EOL><INDENT>setattr(self, color, curses.tparm(set_fg, i) or '<STR_LIT>')<EOL><DEDENT><DEDENT>set_fg_ansi = self._tigetstr('<STR_LIT>')<EOL>if set_fg_ansi:<EOL><INDENT>for i,color in zip(list(range(len(self._ANSICOLORS))), self._ANSICOLORS):<EOL><INDENT>setattr(self, color, curses.tparm(set_fg_ansi, i) or '<STR_LIT>')<EOL><DEDENT><DEDENT>set_bg = self._tigetstr('<STR_LIT>')<EOL>if set_bg:<EOL><INDENT>for i,color in zip(list(range(len(self._COLORS))), self._COLORS):<EOL><INDENT>setattr(self, '<STR_LIT>'+color, curses.tparm(set_bg, i) or '<STR_LIT>')<EOL><DEDENT><DEDENT>set_bg_ansi = self._tigetstr('<STR_LIT>')<EOL>if set_bg_ansi:<EOL><INDENT>for i,color in zip(list(range(len(self._ANSICOLORS))), self._ANSICOLORS):<EOL><INDENT>setattr(self, '<STR_LIT>'+color, curses.tparm(set_bg_ansi, i) or '<STR_LIT>')<EOL><DEDENT><DEDENT>
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).