/** * 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 (Leaps::$app->controller instanceof \Leaps\Console\Controller && Leaps::$app->controller->isColorEnabled($stream) || Leaps::$app instanceof \Leaps\Console\Application && Console::streamSupportsAnsiColors($stream)) { $message = Console::ansiFormat($message, $format); } return $message; }
/** * 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; }