Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Laravel console command that lists all the default Symfony output formatter styles
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
class SymfonyColorsDemo extends Command
{
protected $signature = 'demo:symfony-colors';
protected $description = 'Demonstrates Symfony console formatter colors';
public function handle()
{
$outputFormatterStyle = new \ReflectionClass(OutputFormatterStyle::class);
$availableColorsAndOptions = $outputFormatterStyle->getStaticProperties();
foreach ($availableColorsAndOptions as $key => $options) {
$this->line(
<<<EOL
$key
-------------------------------
EOL
);
foreach ($options as $color => $ranges) {
switch ($key) {
case 'availableForegroundColors':
$this->line("<fg={$color}>{$color}</>");
break;
case 'availableBackgroundColors':
$this->line("<bg={$color}>{$color}</>");
break;
case 'availableOptions':
$this->line("<options={$color}>{$color}</>");
break;
}
}
}
$custom = <<<EOL
Styles
-------------------------------
<info>info</info>
<comment>comment</comment>
<question>question</question>
<error>error</error>
EOL;
$this->line($custom);
$custom = <<<EOL
Custom combos
-------------------------------
<fg=blue;options=blink;bg=yellow>blue text on yellow background</>
Clickable URL: <href=https://github.com;fg=blue;options=underscore>github.com</>
EOL;
$this->line($custom);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.