By default, the Windows command console doesn't support output coloring. The Console component disables output coloring for Windows systems, but if your commands invoke other scripts which emit color sequences, they will be wrongly displayed as raw escape characters. Install the Cmder, ConEmu, ANSICON or Mintty (used by default in GitBash and Cygwin) free applications to add coloring support to your Windows command console.
Using Color StylesΒΆ
Whenever you output text, you can surround the text with tags to color its output. For example:
1 2 3 4 5 6 7 8 9 10 11 | // green text $output->writeln(' |
The closing tag can be replaced by >
, which revokes all formatting options
established by the last opened tag.
It is possible to define your own styles using the
OutputFormatterStyle
class:
1 2 3 4 5 6 7 | use Symfony\Component\Console\Formatter\OutputFormatterStyle; // ... $style = new OutputFormatterStyle('red', 'yellow', array('bold', 'blink')); $output->getFormatter()->setStyle('fire', $style); $output->writeln(' |
Available foreground and background colors are: black
, red
, green
,
yellow
, blue
, magenta
, cyan
and white
.
And available options are: bold
, underscore
, blink
, reverse
(enables the "reverse video" mode where the background and foreground colors
are swapped) and conceal
(sets the foreground color to transparent, making
the typed text invisible - although it can be selected and copied; this option is
commonly used when asking the user to type sensitive information).
You can also set these colors and options directly inside the tagname:
1 2 3 4 5 6 7 8 9 10 11 | // green text $output->writeln(' |
comments powered by Disqus