Parse and print a colored and perhaps formatted string.

    The remaining keyword arguments are the same as for Python's built-in print
    function. Colors are returning to their defaults before the function
    returns.
511972
def fprint(fmt, *args, **kwargs):
    
    if not fmt:
        return

    hascolor = False
    target = kwargs.get("target", sys.stdout)

    # Format the string before feeding it to the parser
    fmt = fmt.format(*args, **kwargs)

    for txt, markups in _color_format_parser.parse(fmt):
        if markups != (None, None):
            _color_manager.set_color(*markups)
            hascolor = True
        else:
            if hascolor:
                _color_manager.set_defaults()
                hascolor = False

        target.write(txt)
        target.flush()  # Needed for Python 3.x

    _color_manager.set_defaults()
    target.write(kwargs.get('end', '\n'))
    _color_manager.set_defaults()
534149
def printAllColorsToConsole(cls):
        '''  '''
        for elem in cls.__dict__:
            # ignore specials such as __class__ or __module__
            if not elem.startswith("__"):
                color_fmt = cls.__dict__[elem]
                if isinstance(color_fmt, six.string_types) and color_fmt != "BOLD" and color_fmt != "DIM" and \
                        color_fmt != "UNDER" and color_fmt != "INV":
                    print("\033[{fmt}AnsiColors.{name}\033[0m".format(fmt=color_fmt, name=elem))
1048524
def parse_color(self, color):
        '''
        
        '''
        if color == 'none':
            return None
        return (
            int(color[1:3], 16),
            int(color[3:5], 16),
            int(color[5:7], 16))
274871
def sprint(string, *args, **kwargs):
    """"""
    try:
        print(string, *args, **kwargs)
    except UnicodeEncodeError:
        string = string.encode('utf-8', errors='ignore')\
                       .decode('ascii', errors='ignore')
        print(string, *args, **kwargs)
268071
def coloringfromstring(s):
    
    try:
        AST = compiler.parse(s)
    except SyntaxError:
        return
    else:
        try:
            if len(AST.getChildren()) > 1:
                ST = AST.getChildren()[1]
                if isinstance(ST, Stmt) and isinstance(ST.getChildren()[0],
                                                                     Discard):
                    d = ST.getChildren()[0].asList()[0]
        except (TypeError, AttributeError):
            pass
        else:
            if isinstance(d,Dict) and len(d.items) > 0:
                if all([isctype(i[0],str) for i in d.items]):
                    if all([isinstance(i[1],List) for i in d.items]):
                        if all([all([isctype(j,str) for j in i[1]]) for i in 
                                                                      d.items]):
                            return eval(s)
117404
def _print_p(self):
        
        print "#  ",
        for i in range(self.width):
            print "  %4d   "%i,
        print
        for L in ['A', 'C', 'T', 'G']:
            print "#%s "%L,
            for i in range(self.width):
                print  "%8.3f "%math.pow(2,self.logP[i][L]),
            print
20287
def printSequence(x, formatString="%d"):
  
  numElements = len(x)
  s = ""
  for j in range(numElements):
    s += formatString % x[j]
  print s
779881
def printer(text, color=None, **kwargs):
    
    if nocolor:
        # import sys
        # sys.stdout.write(text + "" if ("end" in kwargs and kwargs["end"] == "") else '\n')
        # sys.stdout.flush()
        print(text, **kwargs)
    else:
        if color is None:
            cprint(text, **kwargs)
        else:
            cprint(text, color, **kwargs)
833820
public static boolean canParseColor(final String colorString) {
        try {
            return ColorParser.toColor(colorString) != null;
        } catch (Exception exc) {
            return false;
        }
    }
1295230
def _print(self, text, color=None, **kwargs):
        
        COLORS = {
            'red': '\033[91m{}\033[00m',
            'green': '\033[92m{}\033[00m',
            'yellow': '\033[93m{}\033[00m',
            'cyan': '\033[96m{}\033[00m'
        }
        _ = COLORS[color]
        six.print_(_.format(text), **kwargs)
659030
def main(argd=None):
    
    global DEBUG, debug

    # The argd parameter for main() is for testing purposes only.
    argd = argd or docopt(
        USAGESTR,
        version=VERSIONSTR,
        script=SCRIPT,
        # Example usage of colr_docopt colors.
        colors={
            'header': {'fore': 'yellow'},
            'script': {'fore': 'lightblue', 'style': 'bright'},
            'version': {'fore': 'lightblue'},
        }
    )

    DEBUG = argd['--debug']
    # Load real debug function if available.
    if DEBUG:
        load_debug_deps()
    else:
        debug = noop

    if argd['--auto-disable']:
        auto_disable()

    if argd['--names']:
        return list_names()
    elif argd['--translate']:
        # Just translate a simple code and exit.
        try:
            print('\n'.join(
                translate(
                    argd['CODE'] or read_stdin().split(),
                    rgb_mode=argd['--truecolor'],
                )
            ))
        except ValueError as ex:
            print_err('Translation error: {}'.format(ex))
            return 1
        return 0
    elif argd['--listcodes']:
        # List all escape codes found in some text and exit.
        return list_known_codes(
            argd['TEXT'] or read_stdin(),
            unique=argd['--unique'],
            rgb_mode=argd['--truecolor'],
        )

    txt = argd['TEXT'] or read_stdin()
    fd = sys.stderr if argd['--err'] else sys.stdout
    end = '' if argd['--newline'] else '\n'

    if argd['--stripcodes']:
        txt = justify(strip_codes(txt), argd)
        print(txt, file=fd, end=end)
        return 0

    clr = get_colr(txt, argd)

    # Center, ljust, rjust, or not.
    clr = justify(clr, argd)
    if clr:
        print(str(clr), file=fd, end=end)
        return 0
    # Error while building Colr.
    return 1
1173957
def print_traceback(with_colors=True):
    
    #traceback.print_tb()
    import traceback
    stack = traceback.extract_stack()
    stack_lines = traceback.format_list(stack)
    tbtext = ''.join(stack_lines)
    if with_colors:
        try:
            from pygments import highlight
            from pygments.lexers import get_lexer_by_name
            from pygments.formatters import TerminalFormatter
            lexer = get_lexer_by_name('pytb', stripall=True)
            formatter = TerminalFormatter(bg='dark')
            formatted_text = highlight(tbtext, lexer, formatter)
            print(formatted_text)
        except Exception:
            print(tbtext)
    else:
        print(tbtext)
745400
def _printf(self, *args, **kwargs):
        '''
        '''
        if self._stream and not kwargs.get('file'):
            kwargs['file'] = self._stream
        _printf(*args, **kwargs)
996033
def print_diff(diff, color=True):
    """"""
    import colorama

    if not diff:
        return

    if not color:
        colorama.init = lambda autoreset: None
        colorama.Fore.RED = ''
        colorama.Back.RED = ''
        colorama.Fore.GREEN = ''
        colorama.deinit = lambda: None

    colorama.init(autoreset=True)  # TODO use context_manager
    for line in diff.splitlines():
        if line.startswith('+') and not line.startswith('+++ '):
            # Note there shouldn't be trailing whitespace
            # but may be nice to generalise this
            print(colorama.Fore.GREEN + line)
        elif line.startswith('-') and not line.startswith('--- '):
            split_whitespace = re.split('(\s+)$', line)
            if len(split_whitespace) > 1:  # claim it must be 3
                line, trailing, _ = split_whitespace
            else:
                line, trailing = split_whitespace[0], ''
            print(colorama.Fore.RED + line, end='')
            # give trailing whitespace a RED background
            print(colorama.Back.RED + trailing)
        elif line == '\ No newline at end of file':
            # The assumption here is that there is now a new line...
            print(colorama.Fore.RED + line)
        else:
            print(line)
    colorama.deinit()
36426
def print(formatted = false)
      result = "#{rule}, #{description}"
      if formatted
        if failure
          result = "#{FORMATTING_BALL} #{result}".colorize(:red)
        else
          result = "#{FORMATTING_WARNING} #{result}".colorize(:yellow)
        end
      end
      result += "\n#{location.print}" unless location.nil?
      result += "\nRECOMMENDATION: #{recommendation}" unless recommendation.nil?
      result
    end
409416
def pretty_print_str(self):
        '''
        
        '''
        retval = ''
        # dfs
        todo = [self.root]
        while todo:
            current = todo.pop()
            for char in reversed(sorted(current.keys())):
                todo.append(current[char])
            indent = ' ' * (current.depth * 2)
            retval += indent + current.__unicode__() + '\n'
        return retval.rstrip('\n')
593525
def pretty_print(self, obj):
        
        s = repr(obj)
        limit = output_limit()
        if len(s) > limit:
            if self.dom_term:
                s = self.color.py_syntax_highlight(s)
                s = self.dom_term.fold_text_string("", s)
            else:
                s = s[:limit - 3]  # cut before syntax highlighting, to avoid missing color endings
                s = self.color.py_syntax_highlight(s)
                s += "..."
        else:
            s = self.color.py_syntax_highlight(s)
        extra_info = self._pp_extra_info(obj)
        if extra_info != "":
            s += ", " + self.color.py_syntax_highlight(extra_info)
        return s