Colorizes given text using given color.

    :param text: Text to colorize.
    :type text: unicode
    :param color: *ANSI* escape code name.
    :type color: unicode
    :return: Colorized text.
    :rtype: unicode
487168
def colorize(text, color):
    

    escape_code = getattr(AnsiEscapeCodes, color, None)
    if escape_code is None:
        raise foundations.exceptions.AnsiEscapeCodeExistsError(
            "'{0}' | '{1}' 'ANSI' escape code name doesn't exists!".format(
                inspect.getmodulename(__file__), color))

    return "{0}{1}{2}".format(escape_code, text, AnsiEscapeCodes.reset)
373629
def write(self, text, color):
        
        color = self._colors[color]
        self.stream.write('\x1b[{}m{}\x1b[0m'.format(color, text))
1210667
def colored_map(text, cmap):
    
    if not __ISON: return text
    for key, v in cmap.items():
        if isinstance(v, dict):
            text = text.replace(key, colored(key, **v))
        else:
            text = text.replace(key, colored(key, color=v))
    return text
1352466
public static function colorize($text, $fgcolor = null, $bgcolor = null)
    {
        $colors = '';
        if ($bgcolor) {
            $colors .= self::getBgColorString(self::getColorCode($bgcolor));
        }
        if ($fgcolor) {
            $colors .= self::getFgColorString(self::getColorCode($fgcolor));
        }
        if ($colors) {
            $text = $colors . $text . self::RESET;
        }
        return $text;
    }
192441
def parse_color(color):
    
    if color is None:
        color = rcParams['color']
    if isinstance(color, str):
        return vtki.string_to_rgb(color)
    elif len(color) == 3:
        return color
    else:
        raise Exception("""
    Invalid color input
    Must ba string, rgb list, or hex color string.  For example:
        color='white'
        color='w'
        color=[1, 1, 1]
        color='#FFFFFF'""")
913920
def add_text(self, text):
        
        for char in text:
            self.add_char(char)
        self.flush()
1092014
public function colored($text, $color)
    {
        $colors = [
            'black'  => '0;30',
            'red'    => '0;31',
            'green'  => '0;32',
            'blue'   => '1;34',
            'yellow' => '1;33'
        ];

        $c = (
            array_key_exists($color, $colors)
            ? $colors[$color]
            : $colors['black']
        );

        if ($this->arguments->{'no-colors'}) {
            return $text;
        } else {
            return "\033[". $c . 'm' . $text . "\033[0m";
        }
    }
635452
def color_code(cls, color):
        
        if not isinstance(color, tuple):
            color = cls.colors[color]
        return "{:d};{}".format(color[0], str(color[1]) if len(color) == 2 else "")
610392
def colorize(txt, fg=None, bg=None):
    

    setting = ''
    setting += _SET_FG.format(fg) if fg else ''
    setting += _SET_BG.format(bg) if bg else ''
    return setting + str(txt) + _STYLE_RESET
1302201
def write_color(self, text, attr=None):
        '''
        '''
        log(u'write_color("%s", %s)' % (text, attr))
        chunks = self.terminal_escape.split(text)
        log(u'chunks=%s' % repr(chunks))
        bg = self.savebg
        n = 0 # count the characters we actually write, omitting the escapes
        if attr is None:#use attribute from initial console
            attr = self.attr
        try:
            fg = self.trtable[(0x000f&attr)]
            bg = self.trtable[(0x00f0&attr)>>4]
        except TypeError:
            fg = attr
            
        for chunk in chunks:
            m = self.escape_parts.match(chunk)
            if m:
                log(m.group(1))
                attr = ansicolor.get(m.group(1), self.attr)
            n += len(chunk)
            System.Console.ForegroundColor = fg
            System.Console.BackgroundColor = bg
            System.Console.Write(chunk)
        return n
354622
def colorize(str, sev: :normal_s)
      return str unless color_enabled?

      cc = COLOR_CODE
      color = cc.key?(sev) ? cc[sev] : ''
      "#{color}#{str.sub(cc[:esc_m], color)}#{cc[:esc_m]}"
    end
1267157
def color(text, color=None, background=None, light=False, enabled="auto"):
    
    colors = {"black": 30, "red": 31, "green": 32, "yellow": 33,
              "blue": 34, "magenta": 35, "cyan": 36, "white": 37}
    # Nothing do do if coloring disabled
    if enabled == "auto":
        enabled = Coloring().enabled()
    if not enabled:
        return text
    # Prepare colors (strip 'light' if present in color)
    if color and color.startswith("light"):
        light = True
        color = color[5:]
    color = color and ";{0}".format(colors[color]) or ""
    background = background and ";{0}".format(colors[background] + 10) or ""
    light = light and 1 or 0
    # Starting and finishing sequence
    start = "\033[{0}{1}{2}m".format(light, color, background)
    finish = "\033[1;m"
    return "".join([start, text, finish])
548863
def ansi(color, text):
    """"""
    code = COLOR_CODES[color]
    return '\033[1;{0}m{1}{2}'.format(code, text, RESET_TERM)
312454
def colorize(self, string, rgb=None, ansi=None, bg=None, ansi_bg=None):
        ''''''
        if not isinstance(string, str):
            string = str(string)
        if rgb is None and ansi is None:
            raise TerminalColorMapException(
                'colorize: must specify one named parameter: rgb or ansi')
        if rgb is not None and ansi is not None:
            raise TerminalColorMapException(
                'colorize: must specify only one named parameter: rgb or ansi')
        if bg is not None and ansi_bg is not None:
            raise TerminalColorMapException(
                'colorize: must specify only one named parameter: bg or ansi_bg')

        if rgb is not None:
            (closestAnsi, closestRgb) = self.convert(rgb)
        elif ansi is not None:
            (closestAnsi, closestRgb) = (ansi, self.colors[ansi])

        if bg is None and ansi_bg is None:
            return "\033[38;5;{ansiCode:d}m{string:s}\033[0m".format(ansiCode=closestAnsi, string=string)

        if bg is not None:
            (closestBgAnsi, unused) = self.convert(bg)
        elif ansi_bg is not None:
            (closestBgAnsi, unused) = (ansi_bg, self.colors[ansi_bg])

        return "\033[38;5;{ansiCode:d}m\033[48;5;{bf:d}m{string:s}\033[0m".format(ansiCode=closestAnsi, bf=closestBgAnsi, string=string)
648017
def write(self, text: str):
        
        # Default color is NORMAL.
        last_color = (self._DARK_CODE, 0)
        # We use splitlines with keepends in order to keep the line breaks.
        # Then we split by using the console width.
        original_lines = text.splitlines(True)
        lines = self._split_lines(original_lines) if self._width_limit else original_lines

        # Print the new width-formatted lines.
        for line in lines:
            # Print indents only at line beginnings.
            if not self._in_line:
                self._writer.write(' ' * self.indents_sum)
            # Remove colors if needed.
            if not self._colors:
                for color_code in self._ANSI_REGEXP.findall(line):
                    line = line.replace(self._ANSI_COLOR_CODE % (color_code[0], int(color_code[1])), '')
            elif not self._ANSI_REGEXP.match(line):
                # Check if the line starts with a color. If not, we apply the color from the last line.
                line = self._ANSI_COLOR_CODE % (last_color[0], int(last_color[1])) + line
            # Print the final line.
            self._writer.write(line)
            # Update the in_line status.
            self._in_line = not line.endswith(self.LINE_SEP)
            # Update the last color used.
            if self._colors:
                last_color = self._ANSI_REGEXP.findall(line)[-1]

        # Update last position (if there was no line break in the end).
        if len(lines) > 0:
            last_line = lines[-1]
            if not last_line.endswith(self.LINE_SEP):
                # Strip the colors to figure out the real number of characters in the line.
                if self._colors:
                    for color_code in self._ANSI_REGEXP.findall(last_line):
                        last_line = last_line.replace(self._ANSI_COLOR_CODE % (color_code[0], int(color_code[1])), '')
                self._last_position += len(last_line)
            else:
                self._last_position = 0
                self._is_first_line = False
        else:
            self._last_position = 0

        # Reset colors for the next print.
        if self._colors and not text.endswith(self.NORMAL):
            self._writer.write(self.NORMAL)
897796
def set_text_color(self, r,g=-1,b=-1):
        ""
        if((r==0 and g==0 and b==0) or g==-1):
            self.text_color=sprintf('%.3f g',r/255.0)
        else:
            self.text_color=sprintf('%.3f %.3f %.3f rg',r/255.0,g/255.0,b/255.0)
        self.color_flag=(self.fill_color!=self.text_color)
722495
def heading(cls, heading_text, char='=', level=0, ansi=False):
        
        heading_color = cls.headings[level] if ansi else '%s'
        if char is None:
            return heading_color % '%s\n' % heading_text
        else:
            heading_ul = char*len(heading_text)
            return heading_color % '%s\n%s\n%s' % (heading_ul, heading_text, heading_ul)