本文整理汇总了PHP中yii\helpers\Console::streamSupportsAnsiColors方法的典型用法代码示例。如果您正苦于以下问题:PHP Console::streamSupportsAnsiColors方法的具体用法?PHP Console::streamSupportsAnsiColors怎么用?PHP Console::streamSupportsAnsiColors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Console
的用法示例。
在下文中一共展示了Console::streamSupportsAnsiColors方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stderr
protected function stderr($string)
{
if (Console::streamSupportsAnsiColors(\STDOUT)) {
$string = Console::ansiFormat(" Error: " . $string, [Console::FG_RED]);
}
return fwrite(\STDERR, $string);
}
示例2: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->stderrIsNotStdout = fstat(\STDERR)['dev'] != fstat(\STDOUT)['dev'];
$this->stderrSupportsColors = Console::streamSupportsAnsiColors(\STDERR);
$this->stdoutSupportsColors = Console::streamSupportsAnsiColors(\STDOUT);
}
示例3: formatMessage
/**
* Colorizes a message for console output.
* @param string $message the message to colorize.
* @param array $format the message format.
* @return string the colorized message.
* @see Console::ansiFormat() for details on how to specify the message format.
*/
protected function formatMessage($message, $format = [Console::FG_RED, Console::BOLD])
{
$stream = PHP_SAPI === 'cli' ? \STDERR : \STDOUT;
// try controller first to allow check for --color switch
if (Yii::$app->controller instanceof \yii\console\Controller && Yii::$app->controller->isColorEnabled($stream) || Yii::$app instanceof \yii\console\Application && Console::streamSupportsAnsiColors($stream)) {
$message = Console::ansiFormat($message, $format);
}
return $message;
}
示例4: stdout
public function stdout($string)
{
if (Console::streamSupportsAnsiColors(STDOUT)) {
$args = func_get_args();
array_shift($args);
$string = Console::ansiFormat($string, $args);
}
return Console::stdout($string);
}
示例5: init
public function init()
{
$this->_stdoutIsTerminal = posix_isatty(\STDOUT);
if ($this->_stdoutIsTerminal) {
$this->logVars = [];
}
$this->_stdoutSupportsAnsiColors = Console::streamSupportsAnsiColors(\STDOUT);
$this->_stderrIsTerminal = posix_isatty(\STDERR);
$this->_stderrSupportsAnsiColors = Console::streamSupportsAnsiColors(\STDERR);
$this->_levelAnsiColorMap = [Logger::LEVEL_ERROR => $this->errorAnsiColor, Logger::LEVEL_WARNING => $this->warningAnsiColor, Logger::LEVEL_INFO => $this->infoAnsiColor, Logger::LEVEL_TRACE => $this->traceAnsiColor, Logger::LEVEL_PROFILE => $this->profileAnsiColor, Logger::LEVEL_PROFILE_BEGIN => $this->profileBeginAnsiColor, Logger::LEVEL_PROFILE_END => $this->profileEndAnsiColor];
parent::init();
}
示例6: isColorEnabled
/**
* Returns a value indicating whether ANSI color is enabled.
*
* ANSI color is enabled only if [[color]] is set true or is not set
* and the terminal supports ANSI color.
*
* @param resource $stream the stream to check.
* @return boolean Whether to enable ANSI style in output.
*/
public function isColorEnabled($stream = \STDOUT)
{
return $this->color === null ? Console::streamSupportsAnsiColors($stream) : $this->color;
}
示例7: stdout
/**
* Prints a string to STDOUT
* @param string $string
*/
public function stdout($string)
{
if (Yii::$app->request->isConsoleRequest) {
if (Console::streamSupportsAnsiColors(STDOUT)) {
$args = func_get_args();
array_shift($args);
$string = Console::ansiFormat($string, $args);
}
Console::stdout($string . "\n");
}
}
示例8: generateLabel
/**
* @param $message
*
* @return string
*/
private function generateLabel($message)
{
$label = '';
//Add date to log
if (true == $this->displayDate) {
$label .= '[' . date($this->dateFormat, time()) . ']';
}
//Add category to label
if (true == $this->displayCategory) {
$label .= "[" . $message[2] . "]";
}
$level = Logger::getLevelName($message[1]);
$tmpLevel = "[{$level}]";
if (Console::streamSupportsAnsiColors(\STDOUT)) {
if (isset($this->color[$level])) {
$tmpLevel = Console::ansiFormat($tmpLevel, [$this->color[$level]]);
} else {
$tmpLevel = Console::ansiFormat($tmpLevel, [Console::BOLD]);
}
}
$label .= $tmpLevel;
return $label;
}
示例9: _isColorEnabled
/**
* Returns a value indicating whether ANSI color is enabled.
*
* ANSI color is enabled only if [[color]] is set true or is not set
* and the terminal supports ANSI color.
*
* @param resource $stream the stream to check.
* @return boolean Whether to enable ANSI style in output.
*/
private function _isColorEnabled($stream = \STDOUT)
{
return $this->controller->color === null ? Console::streamSupportsAnsiColors($stream) : $this->controller->color;
}