Changeset View
Changeset View
Standalone View
Standalone View
src/console/PhutilConsoleFormatter.php
Show All 16 Lines | final class PhutilConsoleFormatter extends Phobject { | ||||
private static $disableANSI; | private static $disableANSI; | ||||
public static function disableANSI($disable) { | public static function disableANSI($disable) { | ||||
self::$disableANSI = $disable; | self::$disableANSI = $disable; | ||||
} | } | ||||
public static function getDisableANSI() { | public static function getDisableANSI() { | ||||
if (self::$disableANSI === null) { | if (self::$disableANSI === null) { | ||||
self::$disableANSI = self::newShouldDisableAnsi(); | |||||
} | |||||
return self::$disableANSI; | |||||
} | |||||
private static function newShouldDisableANSI() { | |||||
$term = phutil_utf8_strtolower(getenv('TERM')); | $term = phutil_utf8_strtolower(getenv('TERM')); | ||||
// ansicon enables ANSI support on Windows | // ansicon enables ANSI support on Windows | ||||
if (!$term && getenv('ANSICON')) { | if (!$term && getenv('ANSICON')) { | ||||
$term = 'ansi'; | $term = 'ansi'; | ||||
} | } | ||||
if (phutil_is_windows() && $term !== 'cygwin' && $term !== 'ansi') { | |||||
self::$disableANSI = true; | if (phutil_is_windows()) { | ||||
} else if (!defined('STDOUT')) { | if ($term !== 'cygwin' && $term !== 'ansi') { | ||||
self::$disableANSI = true; | return true; | ||||
} else if (function_exists('posix_isatty') && !posix_isatty(STDOUT)) { | |||||
self::$disableANSI = true; | |||||
} else { | |||||
self::$disableANSI = false; | |||||
} | } | ||||
} | } | ||||
return self::$disableANSI; | |||||
$stdout = PhutilSystem::getStdoutHandle(); | |||||
if ($stdout === null) { | |||||
return true; | |||||
} | |||||
if (function_exists('posix_isatty')) { | |||||
if (!posix_isatty($stdout)) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | } | ||||
public static function formatString($format /* ... */) { | public static function formatString($format /* ... */) { | ||||
$args = func_get_args(); | $args = func_get_args(); | ||||
$args[0] = self::interpretFormat($args[0]); | $args[0] = self::interpretFormat($args[0]); | ||||
return call_user_func_array('sprintf', $args); | return call_user_func_array('sprintf', $args); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0