Turns a text color ie "Blue" into a color code.

@return void
493487
public function textToCode(array $details)
    {
        $formatted = array();

        if (isset($details['foreground'])) {
            $formatted['foreground'] = $this->color->getForeground($details['foreground']);
        }

        if (isset($details['background'])) {
            $formatted['background'] = $this->color->getBackground($details['background']);
        }

        return $formatted;
    }
872643
public function write($text, $color = '', $useclass = true)
    {
        $style    = $this->getStyle($this->getCurrentStyle());
        $htmlcode = '<span dir="' . I18N::direction() . '"';
        if ($useclass) {
            $htmlcode .= ' class="' . $style['name'] . '"';
        }
        if (!empty($color)) {
            // Check if Text Color is set and if it’s valid HTML color
            if (preg_match('/#?(..)(..)(..)/', $color)) {
                $htmlcode .= ' style="color:' . $color . ';"';
            }
        }

        $htmlcode .= '>' . $text . '</span>';
        $htmlcode = str_replace([
            "\n",
            '> ',
            ' <',
        ], [
            '<br>',
            '>&nbsp;',
            '&nbsp;<',
        ], $htmlcode);
        echo $htmlcode;
    }
145168
public function correctSelectedText()
    {
        $contentHelper = $this->module->contentHelper;
        $this->text = $contentHelper::afterSelectBody($this->text);
    }
153088
protected function shortenColors($content)
    {
        $content = preg_replace('/(?<=[: ])#([0-9a-z])\\1([0-9a-z])\\2([0-9a-z])\\3(?:([0-9a-z])\\4)?(?=[; }])/i', '#$1$2$3$4', $content);

        // remove alpha channel if it's pointless...
        $content = preg_replace('/(?<=[: ])#([0-9a-z]{6})ff?(?=[; }])/i', '#$1', $content);
        $content = preg_replace('/(?<=[: ])#([0-9a-z]{3})f?(?=[; }])/i', '#$1', $content);

        $colors = array(
            // we can shorten some even more by replacing them with their color name
            '#F0FFFF' => 'azure',
            '#F5F5DC' => 'beige',
            '#A52A2A' => 'brown',
            '#FF7F50' => 'coral',
            '#FFD700' => 'gold',
            '#808080' => 'gray',
            '#008000' => 'green',
            '#4B0082' => 'indigo',
            '#FFFFF0' => 'ivory',
            '#F0E68C' => 'khaki',
            '#FAF0E6' => 'linen',
            '#800000' => 'maroon',
            '#000080' => 'navy',
            '#808000' => 'olive',
            '#CD853F' => 'peru',
            '#FFC0CB' => 'pink',
            '#DDA0DD' => 'plum',
            '#800080' => 'purple',
            '#F00' => 'red',
            '#FA8072' => 'salmon',
            '#A0522D' => 'sienna',
            '#C0C0C0' => 'silver',
            '#FFFAFA' => 'snow',
            '#D2B48C' => 'tan',
            '#FF6347' => 'tomato',
            '#EE82EE' => 'violet',
            '#F5DEB3' => 'wheat',
            // or the other way around
            'WHITE' => '#fff',
            'BLACK' => '#000',
        );

        return preg_replace_callback(
            '/(?<=[: ])('.implode(array_keys($colors), '|').')(?=[; }])/i',
            function ($match) use ($colors) {
                return $colors[strtoupper($match[0])];
            },
            $content
        );
    }
362176
protected function OnImage()
    {
        $im = imagecreate($this->x, $this->y);
        $bg = imagecolorallocate($im, 200, 255, 200);
        $textcolor = imagecolorallocate($im, rand(0, 255), rand(0, 200), rand(0, 255));

        imagestring($im, 5, 2, 2, $this->code, $textcolor);

        for ($i = 0; $i < 5; $i++) {
            $color = imagecolorallocate($im, rand(0, 255), rand(0, 200), rand(0, 255));
            imageline($im, rand(0, 10), rand(1, 20), rand(50, 80), rand(1, 50), $color);
        }
        return $im;
    }
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])
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
791599
public function enqueue_colors_inline_css() {

		foreach ( $this->colors as $name => $args ) {

			$this->add_color_inline_css( $name, $args );

		}

	}
185540
function Color( code ) {
    this.R = 0;
    this.G = 0;
    this.B = 0;
    this.A = 0;
    this.H = 0;
    this.S = 0;
    this.L = 0;

    if ( typeof code === 'string' ) {
        this.parse( code );
    }
}
720083
public function format($text)
    {
        $lines = explode("\n", $text);
        foreach ($lines as &$line) {
            $line = ($this->quote) . str_repeat(' ', $this->indent) . $line;
        }
        return Colour::colour(implode("\n", $lines), $this->foregroundColors, $this->backgroundColors);
    }
601116
public function defineStyleCommands()
    {
        if ($this->css === null) {
            throw new Exception('LaTeX formatter has not been set a theme');
        }
        $cmds = array();
        $round = function ($n) {
            return round($n, 2);
        };
        foreach ($this->css->rules() as $name => $properties) {
            if (!preg_match('/^\w+$/', $name)) {
                continue;
            }
            $cmd = "{#1}";
            if ($this->css->value($name, 'bold', false) === true) {
                $cmd = "{\\textbf$cmd}";
            }
            if ($this->css->value($name, 'italic', false) === true) {
                $cmd = "{\\emph$cmd}";
            }
            if (($col = $this->css->value($name, 'color', null)) !== null) {
                if (preg_match('/^#[a-f0-9]{6}$/i', $col)) {
                    $rgb = ColorUtils::normalizeRgb(ColorUtils::hex2rgb($col), true);
                    $rgb = array_map($round, $rgb);
                    $colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]";
                    $cmd = "{\\textcolor[rgb]{{$colStr}}$cmd}";
                }
            }
            $name = str_replace('_', '', $name);
            $name = strtoupper($name);
            $cmds[] = "\\newcommand{\\lms{$name}}[1]$cmd";
        }

        if ($this->lineNumbers && ($col = $this->css->value('code', 'color', null)) !== null) {
            if (preg_match('/^#[a-f0-9]{6}$/i', $col)) {
                $rgb = ColorUtils::normalizeRgb(ColorUtils::hex2rgb($col), true);
                $rgb = array_map($round, $rgb);
                $colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]";
                $cmd = "\\renewcommand{\\theFancyVerbLine}{\\textcolor[rgb]{{$colStr}}{\arabic{FancyVerbLine}}}";
                $cmds[] = $cmd;
            }
        }
        return implode("\n", $cmds);
    }
105188
public function setTextColor($value) {
    $value = strtoupper($value);
    if ($this->validateTextColor($value)) {
      $this->textColor = $value;
    }
    return $this;
  }
1166758
public function isClear() {

        // it is in a clear state if bold and underscore is off and text and fill colors are empty
        return (!$this->isBold() && !$this->isUnderscore() && $this->textColor->isEmpty() && $this->fillColor->isEmpty());
    }
1367664
public static function colorizeLines($text, $fgcolor = null, $bgcolor = null)
    {
        $lines = explode("\n", $text);
        foreach ($lines as &$line) {
            $line = self::colorize($line, $fgcolor, $bgcolor);
        }
        return implode("\n", $lines);
    }
574887
private function initializeColors()
    {
        $rgb = $this->hex2rgb($this->get('background_color'));
        $this->set('background_color', imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2]));

        $rgb = $this->hex2rgb($this->get('text_color'));
        $this->set('text_color', imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2]));

        $rgb = $this->hex2rgb($this->get('success_color'));
        $this->set('success_color', imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2]));

        $rgb = $this->hex2rgb($this->get('failure_color'));
        $this->set('failure_color', imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2]));
    }
1184696
def set_textcolor(self, color):
        """"""
        self.textcolor = color
        self.relabel()
        if callable(self.theme_color_callback):
            self.theme_color_callback(color, '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