Formatting the output from the console
The base class console controller yii\console\Controller
supports methods to display colored and formatted output.
There are two standard methods to display the output, which are as follows:
stdout
: This prints a string toSTDOUT
strerr
: This prints a string toSTDERR
Both these methods support more parameters: the first is the text string to be displayed, and the other includes the formatting options that can be passed to make a pretty output.
There are formatting options for colors and typing; these are defined by constants from \yii\helpers\Console
; for example, BG_CYAN
for cyan background color, BG_RED
for red background color, and UNDERLINE
for underlined text.
Let's see an example using the following code:
$this->stdout("Hello?\n", Console::BOLD);
This will display Hello?
(with a carriage return) with bold font. Sometimes, it could be possible that no effect will be displayed, since our terminal does not support colors.
In this case...