<?php
namespace app\commands;
use yii\console\Controller;
use yii\helpers\BaseConsole;
class ColorTestController extends Controller
{
public function actionIndex()
{
list($width, $height) = BaseConsole::getScreenSize(true);
$foregrounds = [null, 'k', 'K', 'r', 'R', 'g', 'G', 'y', 'Y', 'b', 'B', 'm', 'M', 'p', 'P', 'c', 'C', 'w', 'W'];
$backgrounds = [null, '0', '1', '2', '3', '4', '5', '6', '7'];
$difference = intval(floor($width / 24));
for ($min = 0; $min < 9; $min += $difference) {
$max = $min + $difference;
foreach ($foregrounds as $foreground) {
foreach ($backgrounds as $key => $background) {
if ($key < $min || $key >= $max) {
continue;
}
$this->stdout(BaseConsole::renderColoredString(sprintf(
'%2s %2s %s%s%s',
is_null($foreground) ? '' : '%%' . $foreground,
is_null($background) ? '' : '%%' . $background,
is_null($foreground) ? '' : '%' . $foreground,
is_null($background) ? '' : '%' . $background,
'Sample Text%n '
)));
}
$this->stdout("\n");
}
$this->stdout("\n\n");
}
}
}
./console color-testSample text in %W %0 Sample Text has white color and black backgroundSample text in %W %6 Sample Text has white color and cyan backgroundSample text in %W %7 Sample Text has white color and gray backgroundSample text in %W %0 Sample Text has white color and gray backgroundSample text in %W %6 Sample Text has white color and purple backgroundSample text in %W %7 Sample Text has white color and cyan background| Q | A
| ---------------- | ---
| Yii version | any 2.* released after Mar 23, 2014
| PHP version | any
| Operating system | any
In the BaseConsole::renderColoredString() method, change these $conversions array values:
'%0' => [self::BG_GREY] to '%0' => [self::BG_BLACK]'%6' => [self::BG_PURPLE] to '%6' => [self::BG_CYAN]'%7' => [self::BG_CYAN] to '%7' => [self::BG_GREY]Thank you for a perfect report.
It was really easy and pleasant to reproduce and fix the problem.
Many thanks for both a praise and a fix. :)
Most helpful comment
Thank you for a perfect report.
It was really easy and pleasant to reproduce and fix the problem.