Apply a color code to text
351758
def _apply_color(code, content):
        

        normal = u'\x1B[0m'
        seq = u'\x1B[%sm' % code

        # Replace any normal sequences with this sequence to support nested colors
        return seq + (normal + seq).join(content.split(normal)) + normal
96136
function generateColorByName(str) {
    var hue = 0;
    for (var i = 0; i < str.length; i++) {
        hue = (hue * PRIME + str.charCodeAt(i)) % MASK;
    }
    hue = Math.floor(hue * PRIME) % MASK / MASK;
    var rgb = hslToRgb(hue, SATURATION, LIGHTNESS);
    return ('#' + rgb[0].toString(16) + rgb[1].toString(16) + rgb[2].toString(16)).toUpperCase();
}
1037791
def Text(text, font, color=pygame.Color(0, 0, 0), antialias=False, align="center"):
    
    assert align in ["center", "left", "right"]
    margin_l, margin_r = 1, 1
    if align == "left": margin_l = 0
    elif align == "right": margin_r = 0
    margin = Margin(margin_l, margin_r)
    color_key = pygame.Color(0, 0, 1) if pygame.Color(0, 0, 1) != color else 0x000002
    
    text_surfaces = _lmap(lambda text: _text(text, font=font, 
                                   color=color, antialias=antialias),
                                   map(methodcaller("strip"), text.split("\n")))
    w = max(surf.get_rect().w for surf in text_surfaces)
    h = sum(surf.get_rect().h for surf in text_surfaces)
    surf = compose((w, h), Fill(color_key))(LinLayout("v")(
        *_lmap(lambda s: Surface(margin)(s), text_surfaces)))
    surf.set_colorkey(color_key)
    return surf.convert_alpha()
922376
def format_color(text, color, use_color_setting):
    
    if not use_color_setting:
        return text
    else:
        return '{}{}{}'.format(color, text, NORMAL)
410642
def underline(self, msg):
        """"""
        return click.style(msg, underline=True) if self.colorize else msg
1058302
def bk_yellow(cls):
        ""
        wAttributes = cls._get_text_attributes()
        wAttributes &= ~win32.BACKGROUND_MASK
        wAttributes |=  win32.BACKGROUND_YELLOW
        cls._set_text_attributes(wAttributes)
209985
function extractColor(text, i, color) {
    var matches = [],
        match;
		
	text = text.slice(i);
    while ((match = text.match(/^\x1b\[([\d;]*)m/))) {
        matches.push(match);
        text = text.slice(match[0].length);
		i += match[0].length;
    }
    
    if (!matches.length) {
        return null;
    }
    
    var tokens = matches.map(function(match){
        return match[1].split(";");
    });
    
    tokens = Array.prototype.concat.apply([], tokens);
    
    var span = color.copy();
    span.i = i;
    
    var code;
    
    for (i = 0; i < tokens.length; i++) {
        code = +tokens[i];
        if (code == 0) {
            span.reset();
        } else if (code == 1) {
            span.l = true;
        } else if (code == 5) {
            span.flash = true;
        } else if (code == 7) {
            var t = span.f;
            span.f = span.b;
            span.b = t;
        } else if (code < 40) {
            span.f = code - 30;
        } else if (code < 50) {
            span.b = code - 40;
        }
    }
    return span;
}
870016
def colorize(text, ansi=True):
    
    if ansi:
        text = text.replace('^^', '\x00')
        for token, code in _ANSI_CODES:
            text = text.replace(token, code)
        text = text.replace('\x00', '^')
    else:
        text = strip_caret_codes(text)
    return text
526409
def hash_coloured_escapes(text):
    """"""
    ansi_code = int(sha256(text.encode('utf-8')).hexdigest(), 16) % 230
    prefix, suffix = colored('SPLIT', ansi_code=ansi_code).split('SPLIT')
    return prefix, suffix
373629
def write(self, text, color):
        
        color = self._colors[color]
        self.stream.write('\x1b[{}m{}\x1b[0m'.format(color, text))
1341138
def yellow(cls):
        ""
        wAttributes = cls._get_text_attributes()
        wAttributes &= ~win32.FOREGROUND_MASK
        wAttributes |=  win32.FOREGROUND_YELLOW
        cls._set_text_attributes(wAttributes)
119075
def _colourise(text: str, colour: str) -> str:
    
    if COLOUR:
        text = style(text, fg=colour, bold=True)
    return text
351484
def _ansi_color(code, theme):
    
    red = 170 if code & 1 else 0
    green = 170 if code & 2 else 0
    blue = 170 if code & 4 else 0
    color = QtGui.QColor(red, green, blue)
    if theme is not None:
        mappings = {
            '#aa0000': theme.red,
            '#00aa00': theme.green,
            '#aaaa00': theme.yellow,
            '#0000aa': theme.blue,
            '#aa00aa': theme.magenta,
            '#00aaaa': theme.cyan,
            '#000000': theme.background,
            "#ffffff": theme.foreground
        }
        try:
            return mappings[color.name()]
        except KeyError:
            pass
    return color
101537
def _get_text_color(self):
        """"""

        color = self.code_array.cell_attributes[self.key]["textcolor"]
        return tuple(c / 255.0 for c in color_pack2rgb(color))
1322242
def color(self, s, color=None, bold=False):
        
        if not self.enable:
            return s
        code_seq = []
        if color:
            code_seq += [30 + self.ColorIdxTable[color]]  # foreground color
        if bold:
            code_seq += [1]
        if not code_seq:
            return s
        start = "\x1b[%sm" % ";".join(map(str, code_seq))
        end = "\x1b[0m"
        while s[:1] == " ":  # move prefix spaces outside
            start = " " + start
            s = s[1:]
        while s[-1:] == " ":  # move postfix spaces outside
            end += " "
            s = s[:-1]
        return start + s + end
522187
def _colorize(self, msg, color=None, encode=False):
        
        
        # Valid colors
        colors = {
            'red':    '31',
            'green':  '32',
            'yellow': '33'
        }
        
        # No color specified or unsupported color
        if not color or not color in colors:
            return msg
        
        # The colorized string
        if encode:
            return u'\x1b[1;{}m{}\x1b[0m'.format(colors[color], msg)
        return '\x1b[1;{}m{}\x1b[0m'.format(colors[color], msg)
852742
def colorize(style, msg, resp):
    
    code = resp.status.split(maxsplit=1)[0]
    if code[0] == '2':
        # Put 2XX first, since it should be the common case
        msg = style.HTTP_SUCCESS(msg)
    elif code[0] == '1':
        msg = style.HTTP_INFO(msg)
    elif code == '304':
        msg = style.HTTP_NOT_MODIFIED(msg)
    elif code[0] == '3':
        msg = style.HTTP_REDIRECT(msg)
    elif code == '404':
        msg = style.HTTP_NOT_FOUND(msg)
    elif code[0] == '4':
        msg = style.HTTP_BAD_REQUEST(msg)
    else:
        # Any 5XX, or any other response
        msg = style.HTTP_SERVER_ERROR(msg)
    return msg