Color-code entire string.

        :param str string: String to colorize.
        :param bool auto: Enable auto-color (dark/light terminal).

        :return: Class instance for colorized string.
        :rtype: Color
180411
def bggreen(cls, string, auto=False):
        
        return cls.colorize('bggreen', string, auto=auto)
119075
def _colourise(text: str, colour: str) -> str:
    
    if COLOUR:
        text = style(text, fg=colour, bold=True)
    return text
497002
def _wrap_with(color_code):
    '''
    '''
    def inner(text, bold=False):
        '''Inner color function.'''
        code = color_code
        if bold:
            code = flo("1;{code}")
        return flo('\033[{code}m{text}\033[0m')
    return inner
1167399
public void automaticColor()
    {
        final Map<TileRef, ColorRgba> colors = new HashMap<>();
        for (final Integer sheet : map.getSheets())
        {
            computeSheet(colors, sheet);
        }
        pixels = colors;
    }
812153
def color(type, str)
      colors = {
        'pass'          => [:green], # 90,
        'fail'          => [:red], # 31,
        'bright pass'   => [:bold, :green], # 92,
        'bright fail'   => [:bold, :red], # 91,
        'bright yellow' => [:bold, :yellow], # 93,
        'pending'       => [:yellow], # 36,
        'suite'         => [], # 0,
        'error title'   => [], # 0,
        'error message' => [:red], # 31,
        'error stack'   => [:green], # 90,
        'checkmark'     => [:green], # 32,
        'fast'          => [:green], # 90,
        'medium'        => [:green], # 33,
        'slow'          => [:red], # 31,
        'green'         => [:green], # 32,
        'light'         => [:green], # 90,
        'diff gutter'   => [:green], # 90,
        'diff added'    => [:green], # 42,
        'diff removed'  => [:red]# 41
      }

      @context.knife.ui.color(str, *colors[type])
    end
307458
function highlightAuto(value, options) {
  var result
  var sheet
  var config

  if (options) {
    if (options.subset) {
      sheet = options.sheet
      config = {subset: options.subset}
    } else {
      sheet = options
    }
  }

  if (!sheet) {
    sheet = SHEET
  }

  result = auto.call(this, value, config)

  result.value = all(sheet, result.value)

  if (result.secondBest) {
    result.secondBest.value = all(sheet, result.secondBest.value)
  }

  return result
}
1057899
def term_color(code):
    
    def inner(text, rl=False):
        """
        Every raw_input with color sequences should be called with
        rl=True to avoid readline messed up the length calculation
        """
        c = code
        if rl:
            return "\001\033[38;5;%sm\002%s\001\033[0m\002" % (c, text)
        else:
            return "\033[38;5;%sm%s\033[0m" % (c, text)
    return inner
933308
def color_text(text, color):
    
    """
    import utool as ut
    if color is None or not ENABLE_COLORS:
        return text
    elif color == 'python':
        return highlight_text(text, color)
    elif color == 'sql':
        return highlight_text(text, 'sql')
    try:
        import pygments
        import pygments.console
        # if color == 'guess':
        #     import linguist  # NOQA
        #     pygments.lexers.guess_lexer(text)
        #     return highlight_text(text, color)
        ansi_text = pygments.console.colorize(color, text)
        if ut.WIN32:
            import colorama
            ansi_reset = (colorama.Style.RESET_ALL)
        else:
            ansi_reset = pygments.console.colorize('reset', '')
        ansi_text = ansi_text + ansi_reset
        return ansi_text
    except ImportError:
        return text
1297016
def bgwhite(cls, string, auto=False):
        
        return cls.colorize('bgwhite', string, auto=auto)
1152415
def color_string(color, string):
    
    if not color_available:
        return string

    return color + string + colorama.Fore.RESET
248696
def py_syntax_highlight(self, s):
        
        if not self.enable:
            return s
        state = 0
        spaces = " \t\n"
        ops = ".,;:+-*/%&!=|(){}[]^<>"
        i = 0
        cur_token = ""
        color_args = {0: {}, len(s): {}}  # type: typing.Dict[int,typing.Dict[str]]  # pos in s -> color kwargs

        def finish_identifier():
            """
            Reset color to standard for current identifier.
            """
            if cur_token in py_keywords:
                color_args[max([k for k in color_args.keys() if k < i])] = {"color": self.fg_colors[0]}

        while i < len(s):
            c = s[i]
            i += 1
            if c == "\n":
                if state == 3:
                    finish_identifier()
                color_args[i] = {}
                state = 0
            elif state == 0:
                if c in spaces:
                    pass
                elif c in ops:
                    color_args[i - 1] = {"color": self.fg_colors[0]}
                    color_args[i] = {}
                elif c == "#":
                    color_args[i - 1] = {"color": self.fg_colors[3]}
                    state = 6
                elif c == '"':
                    color_args[i - 1] = {"color": self.fg_colors[2]}
                    state = 1
                elif c == "'":
                    color_args[i - 1] = {"color": self.fg_colors[2]}
                    state = 2
                else:
                    cur_token = c
                    color_args[i - 1] = {}
                    state = 3
            elif state == 1:  # string via "
                if c == "\\":
                    state = 4
                elif c == "\"":
                    color_args[i] = {}
                    state = 0
            elif state == 2:  # string via '
                if c == "\\":
                    state = 5
                elif c == "'":
                    color_args[i] = {}
                    state = 0
            elif state == 3:  # identifier
                if c in spaces + ops + "#\"'":
                    finish_identifier()
                    color_args[i] = {}
                    state = 0
                    i -= 1
                else:
                    cur_token += c
            elif state == 4:  # escape in "
                state = 1
            elif state == 5:  # escape in '
                state = 2
            elif state == 6:  # comment
                pass
        if state == 3:
            finish_identifier()
        out = ""
        i = 0
        while i < len(s):
            j = min([k for k in color_args.keys() if k > i])
            out += self.color(s[i:j], **color_args[i])
            i = j
        return out
1054763
def yellow(cls, string, auto=False):
        
        return cls.colorize('yellow', string, auto=auto)
1205487
public static function fromRgbaString(string $string) : TransparentColour
    {
        list($r, $g, $b, $a) = ColourStringParser::parseRgbaString($string);

        return new self(new Colour($r, $g, $b), $a);
    }
1117907
def magenta(cls, string, auto=False):
        
        return cls.colorize('magenta', string, auto=auto)
311704
def recolorize(string)
      level = 0
      string.gsub(/\e\[(\d+(?:;\d+)*)m/) do
        "".tap do |buffer|
          codes = $1.split(";").map(&:to_i)

          classes = []
          while code = codes.shift
            case code
            when 0
              classes.clear
              buffer << ("</span>" * level)
              level = 0
            when 1..5, 9, 30..37
              classes << "term-fg#{code}"
            when 38
              if codes[0] == 5
                codes.shift
                if codes[0]
                  classes << "term-fgx#{codes.shift}"
                end
              end
            when 40..47
              classes << "term-bg#{code}"
            when 48
              if codes[0] == 5
                codes.shift
                if codes[0]
                  classes << "term-bgx#{codes.shift}"
                end
              end
            when 90..97
              classes << "term-fgi#{code}"
            when 100..107
              classes << "term-bgi#{code}"
            end
          end

          if classes.any?
            level += 1
            buffer << %{<span class=#{classes.map { |klass| klass }.join(" ").encode(:xml => :attr)}>}
          end
        end
      end << ("</span>" * level)
    end
603250
public void setAutoTextColor(final boolean AUTOMATIC) {
        if (null == autoTextColor) {
            _autoTextColor = AUTOMATIC;
            adjustTextColors();
            redraw();
        } else {
            autoTextColor.set(AUTOMATIC);
        }
    }
99516
def strip_color!(string)
      [@@mirc_color, @@rgb_color, @@ecma48_color].each do |pattern|
        string.gsub!(pattern, '')
      end
      # strip cancellation codes too if there are no formatting codes
      string.gsub!(@@normal) if !has_color?(string)
      return string
    end