* @package tao */ class tao_helpers_Cli { /** * A set of color codes that can be used to highlight texts in a CLI context. * Keys of these associative array are color names in english and values are color * codes. Available colors are: * * $colors['background']['black'] * $colors['background']['red'] * $colors['background']['green'] * $colors['background']['yellow'] * $colors['background']['blue'] * $colors['background']['magenta'] * $colors['background']['cyan'] * $colors['background']['light_gray'] * $colors['foreground']['black'] * $colors['foreground']['dark_gray'] * $colors['foreground']['blue'] * $colors['foreground']['light_blue'] * $colors['foreground']['green'] * $colors['foreground']['light_green'] * $colors['foreground']['light_cyan'] * $colors['foreground']['red'] * $colors['foreground']['light_red'] * $colors['foreground']['purple'] * $colors['foreground']['brown'] * $colors['foreground']['yellow'] * $colors['foreground']['light_gray'] * $colors['foreground']['white'] * * @var array */ private static $colors = [ 'background' => [ 'black' => '40', 'red' => '41', 'green' => '42', 'yellow' => '43', 'blue' => '44', 'magenta' => '45', 'cyan' => '46', 'light_gray' => '47' ], 'foreground' => [ 'black' => '0;30', 'dark_gray' => '1;30', 'blue' => '0;34', 'light_blue' => '1;34', 'green' => '0;32', 'light_green' => '1;32', 'cyan' => '0;36', 'light_cyan' => '1;36', 'red' => '0;31', 'light_red' => '1;31', 'purple' => '0;35', 'light_purple' => '1;35', 'brown' => '0;33', 'yellow' => '1;33', 'light_gray' => '0;37', 'white' => '1;37' ]]; /** * Get a background color compliant with the CLI. Available color names are: * black, red, green, yellow, blue, magenta, cyan, light_gray. * * If the color name does not exist, an empty string is returned. * * @author Bertrand Chevrier, * @param string name The name of the color. * @return string The corresponding color code. */ public static function getBgColor($name) { $returnValue = (string) ''; if (!empty($name) && array_key_exists($name, self::$colors['background'])) { $returnValue = self::$colors['background'][$name]; } return (string) $returnValue; } /** * Get a foreground color compliant with the CLI. Available color names are: * black, dark_gray, blue, light_blue, green, light_green, light_cyan, * red, light_red, purple, brown, yellow, light_gray, white. * * If the provided color names is not supported, an empty string is returned. Otherwise, * the corresponding color code is returned. * * @author Bertrand Chevrier, * @param string name The color name. * @return string A color code. */ public static function getFgColor($name) { $returnValue = (string) ''; if (!empty($name) && array_key_exists($name, self::$colors['foreground'])) { $returnValue = self::$colors['foreground'][$name]; } return (string) $returnValue; } }