mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-16 15:21:13 +08:00
[skip ci] Added formatting and colors section to console guide
This commit is contained in:
@ -163,3 +163,23 @@ There are some predefined constants you can use:
|
|||||||
|
|
||||||
- `Controller::EXIT_CODE_NORMAL` with value of `0`;
|
- `Controller::EXIT_CODE_NORMAL` with value of `0`;
|
||||||
- `Controller::EXIT_CODE_ERROR` with value of `1`.
|
- `Controller::EXIT_CODE_ERROR` with value of `1`.
|
||||||
|
|
||||||
|
It's a good practice to define meaningful constants for your controller in case you have more error code types.
|
||||||
|
|
||||||
|
### Formatting and colors
|
||||||
|
|
||||||
|
Yii console supports formatted output that is automatically degraded to non-formatted one if it's not supported
|
||||||
|
by terminal running the command.
|
||||||
|
|
||||||
|
Outputting formatted strings is simple. Here's how to output some bold text:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$this->stdout("Hello?\n", Console::BOLD);
|
||||||
|
```
|
||||||
|
|
||||||
|
If you need to build string dynamically combining multiple styles it's better to use `ansiFormat`:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$name = $this->ansiFormat('Alex', Console::FG_YELLOW);
|
||||||
|
echo "Hello, my name is $name.";
|
||||||
|
```
|
||||||
|
Reference in New Issue
Block a user