Created
February 10, 2020 23:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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