def _wrap_color(self, code, text, format=None, style=None):
color = None<EOL>if code[:<NUM_LIT:3>] == self.bg.PREFIX:<EOL><INDENT>color = self.bg.COLORS.get(code, None)<EOL><DEDENT>if not color:<EOL><INDENT>color = self.fg.COLORS.get(code, None)<EOL><DEDENT>if not color:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>if format and format not in self.formats:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>fmt = "<STR_LIT>"<EOL>if format == '<STR_LIT>':<EOL><INDENT>fmt = "<STR_LIT>"<EOL><DEDENT>elif format == '<STR_LIT>':<EOL><INDENT>fmt = "<STR_LIT>"<EOL><DEDENT>parts = color.split('<STR_LIT:[>')<EOL>color = '<STR_LIT>'.format(parts[<NUM_LIT:0>], fmt, parts[<NUM_LIT:1>])<EOL>if self.has_colors and self.colors_enabled:<EOL><INDENT>st = '<STR_LIT>'<EOL>if style:<EOL><INDENT>st = self.st.COLORS.get(style, '<STR_LIT>')<EOL><DEDENT>return "<STR_LIT>".format(st, color, text, self.st.COLORS['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>return text<EOL><DEDENT>
Colors text with code and given format