Changes on console feedback colors. Example of User Tasks.

This commit is contained in:
Andrs Montaez
2011-11-23 09:38:52 -02:00
parent d6166a674d
commit e5f0fe9cfa
13 changed files with 174 additions and 93 deletions
+40 -51
View File
@@ -1,53 +1,42 @@
<?php
class Mage_Console_Colors {
private static $foreground_colors = array ();
private static $background_colors = array ();
public function __construct() {
// Set up shell colors
self::$foreground_colors ['black'] = '0;30';
self::$foreground_colors ['dark_gray'] = '1;30';
self::$foreground_colors ['blue'] = '0;34';
self::$foreground_colors ['light_blue'] = '1;34';
self::$foreground_colors ['green'] = '0;32';
self::$foreground_colors ['light_green'] = '1;32';
self::$foreground_colors ['cyan'] = '0;36';
self::$foreground_colors ['light_cyan'] = '1;36';
self::$foreground_colors ['red'] = '0;31';
self::$foreground_colors ['light_red'] = '1;31';
self::$foreground_colors ['purple'] = '0;35';
self::$foreground_colors ['light_purple'] = '1;35';
self::$foreground_colors ['brown'] = '0;33';
self::$foreground_colors ['yellow'] = '1;33';
self::$foreground_colors ['light_gray'] = '0;37';
self::$foreground_colors ['white'] = '1;37';
self::$background_colors ['black'] = '40';
self::$background_colors ['red'] = '41';
self::$background_colors ['green'] = '42';
self::$background_colors ['yellow'] = '43';
self::$background_colors ['blue'] = '44';
self::$background_colors ['magenta'] = '45';
self::$background_colors ['cyan'] = '46';
self::$background_colors ['light_gray'] = '47';
}
// Returns colored string
public static function g($string, $foreground_color = null, $background_color = null) {
$colored_string = "";
// Check if given foreground color found
if (isset ( self::$foreground_colors [$foreground_color] )) {
$colored_string .= "\033[" . self::$foreground_colors [$foreground_color] . "m";
}
// Check if given background color found
if (isset ( self::$background_colors [$background_color] )) {
$colored_string .= "\033[" . self::$background_colors [$background_color] . "m";
}
// Add string and end coloring
$colored_string .= $string . "\033[0m";
return $colored_string;
}
class Mage_Console_Colors
{
private static $foreground_colors = array(
'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'
);
// Returns colored string
public static function color($string)
{
foreach (self::$foreground_colors as $key => $code) {
$replaceFrom = array(
'<' . $key . '>',
'</' . $key . '>'
);
$replaceTo = array(
"\033[" . $code . 'm',
"\033[0m"
);
$string = str_replace($replaceFrom, $replaceTo, $string);
}
return $string;
}
}