/** * Returns text formatted with color, background color and/or attributes. * * @global array $TC_ALL * @global string $TC_RESET * @param string $text * The text to apply color to ($arg1). * @param string/array $arg2 ... $argN * Any of the following text colors, background colors or style attributes * in arbitrary order. * Available text colors: * red, green, yellow, blue, magenta, cyan, white. * Available text highlights: * on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white. * Available attributes: * bold, dark, underline, blink, reverse, concealed. * @example * tc_colored('Hello, World!', 'red', 'on_grey', 'blue', 'blink'); * tc_colored('Hello, World!', 'green'); * @return string */ function tc_colored() { static $fmt_str = "[%dm%s"; static $reset = "[0m"; static $options = false; if (!$options) { $options = _tc_get_options(); } $args = func_get_args(); $text = array_shift($args); foreach ($args as $_arg) { foreach ((array) $_arg as $arg) { if (isset($options[$arg])) { $text = sprintf($fmt_str, $options[$arg], $text); } else { tcechon("Invalid argument to termcolor.php: {$arg}."); exit(1); } } } return $text . $reset; }
public static function debug($txt) { tcechon(date('F jS H:i:s') . " " . $txt, 'white'); }
function phpterm_demo() { echo 'Test basic colors:' . "\n"; tcechon('Grey color', 'grey'); tcecho('Red color', 'red'); echo "\n"; echo tc_colored('Green color', 'green') . "\n"; tcechon('Yellow color', 'yellow'); tcechon('Blue color', 'blue'); tcechon('Magenta color', 'magenta'); tcechon('Cyan color', 'cyan'); tcechon('White color', 'white'); echo str_repeat('-', 78) . "\n"; echo 'Test highlights:' . "\n"; tcechon('On grey color', 'on_grey'); tcechon('On red color', 'on_red'); tcechon('On green color', 'on_green'); tcechon('On yellow color', 'on_yellow'); tcechon('On blue color', 'on_blue'); tcechon('On magenta color', 'on_magenta'); tcechon('On cyan color', 'on_cyan'); tcechon('On white color', 'grey', 'on_white'); echo str_repeat('-', 78) . "\n"; echo 'Test attributes:' . "\n"; tcechon('Bold grey color', 'grey', 'bold'); tcechon('Dark red color', 'red', 'dark'); tcechon('Underline green color', 'green', 'underline'); tcechon('Blink yellow color', 'yellow', 'blink'); tcechon('Reversed blue color', 'blue', 'reverse'); tcechon('Concealed Magenta color', 'magenta', 'concealed'); tcechon('Bold underline reverse cyan color', 'cyan', 'bold', 'underline', 'reverse'); tcechon('Dark blink concealed white color', 'white', array('dark', 'blink', 'concealed')); echo str_repeat('-', 78) . "\n"; echo 'Test mixing:' . "\n"; tcechon('Underline red on grey color', 'red', 'on_grey', 'underline'); tcechon('Reversed green on red color', 'green', 'on_red', 'reverse'); }
<?php $path = realpath(dirname(__FILE__)); require "{$path}/termcolor.php"; $a = `php {$path}/termcolor.php`; $b = `python {$path}/termcolor.py`; if ($a === $b) { tcechon("Tests passed.", 'green'); } else { tcechon("Tests failed.", 'red'); tcechon("### Output php ###"); var_dump($a); echo "\n"; tcechon("### Output python ###"); var_dump($b); }