diff --git a/src/console/PhutilConsoleFormatter.php b/src/console/PhutilConsoleFormatter.php index ae58f7a..e791990 100644 --- a/src/console/PhutilConsoleFormatter.php +++ b/src/console/PhutilConsoleFormatter.php @@ -1,86 +1,86 @@ 0, 'red' => 1, 'green' => 2, 'yellow' => 3, 'blue' => 4, 'magenta' => 5, 'cyan' => 6, 'white' => 7, 'default' => 9, ); private static $disableANSI = false; public static function disableANSI($disable) { self::$disableANSI = $disable; } public static function formatString($format /* ... */) { + $colors = implode('|', array_keys(self::$colorCodes)); + if (self::$disableANSI) { $format = preg_replace('/\*\*(.*)\*\*/sU', '\1', $format); $format = preg_replace('/__(.*)__/sU', '\1', $format); $format = preg_replace('/##(.*)##/sU', '\1', $format); $format = preg_replace( '@<(fg|bg):('.$colors.')>(.*)@sU', '\1', $format); } else { $esc = chr(27); $bold = $esc.'[1m'.'\\1'.$esc.'[m'; $underline = $esc.'[4m'.'\\1'.$esc.'[m'; $invert = $esc.'[7m'.'\\1'.$esc.'[m'; - $colors = implode('|', array_keys(self::$colorCodes)); - $format = preg_replace('/\*\*(.*)\*\*/sU', $bold, $format); $format = preg_replace('/__(.*)__/sU', $underline, $format); $format = preg_replace('/##(.*)##/sU', $invert, $format); $format = preg_replace_callback( '@<(fg|bg):('.$colors.')>(.*)@sU', array('PhutilConsoleFormatter', 'replaceColorCode'), $format); } $args = func_get_args(); $args[0] = $format; return call_user_func_array('sprintf', $args); } public static function replaceColorCode($matches) { $codes = self::$colorCodes; $offset = 30 + $codes[$matches[2]]; $default = 39; if ($matches[1] == 'bg') { $offset += 10; $default += 10; } return chr(27).'['.$offset.'m'.$matches[3].chr(27).'['.$default.'m'; } }