###怎么搞
* 試試在上一章節建立的[模塊]/console/command/[命令名].php里的execute方法加入下面的代碼:
~~~
$output->writeln('Normal');
$output->writeln('<error>error</error>');
$output->writeln('<info>info</info>');
$output->writeln('<comment>comment</comment>');
$output->writeln('<question>question</question>');
~~~
輸出:

你沒猜錯!<error><info><comment><question>是TP5自帶的四個命令行樣式標簽!
* 添加更多顏色
可以通過$output->getFormatter()->setStyle()方法設置新的樣式標簽。
~~~
$output->getFormatter()->setStyle([標簽名], new Style([前景色], [背景色], [文字樣式]);
$output->writeln('<[標簽名]>Test</[標簽名]>');
~~~
TP5的前景色和背景色共有[black, red, green, yellow, blue, magenta, cyan, white]幾種,文字樣式有[bold, underscore, blink, reverse, conceal]幾種,如有需要,可以逐一試試看!
Demo:
~~~
$output->writeln('Normal');
$output->writeln('<error>error</error>');
$output->writeln('<info>info</info>');
$output->writeln('<comment>comment</comment>');
$output->writeln('<question>question</question>');
$color = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'];
$style = ['bold', 'underscore', 'blink', 'reverse', 'conceal'];
for($i = 0; $i < 1000; $i++) {
$colorSet = array_rand($color, 2);
shuffle($style);
$styleLen = mt_rand(0, 4);
$output->getFormatter()->setStyle('style_'.$i, new Style($color[$colorSet[0]], $color[$colorSet[1]], array_slice($style, 0, $styleLen)));
$output->write('<style_'.$i.'>#</style_'.$i.'>');
}
$output->writeln('Done!');
~~~
運行看看會發生什么!

彩色的小方塊,還會變色!
* * * * *
###應用
1. 命令行中的各種提示性文字