Skip to content

Instantly share code, notes, and snippets.

@breadthe
Created February 10, 2020 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save breadthe/3b82ed24b41a38346f32318e4f585a5d to your computer and use it in GitHub Desktop.
Save breadthe/3b82ed24b41a38346f32318e4f585a5d to your computer and use it in GitHub Desktop.
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