Skip to content

Commit 864fccb

Browse files
committed
Move Coloring the Output to a seperate article
1 parent 288cdfd commit 864fccb

File tree

3 files changed

+67
-62
lines changed

3 files changed

+67
-62
lines changed

components/console.rst

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -133,67 +133,6 @@ Commands have three lifecycle methods:
133133
This method is executed after ``interact()`` and ``initialize()``.
134134
It contains the logic you want the command to execute.
135135

136-
.. _components-console-coloring:
137-
138-
Coloring the Output
139-
~~~~~~~~~~~~~~~~~~~
140-
141-
.. note::
142-
143-
By default, the Windows command console doesn't support output coloring. The
144-
Console component disables output coloring for Windows systems, but if your
145-
commands invoke other scripts which emit color sequences, they will be
146-
wrongly displayed as raw escape characters. Install the `Cmder`_, `ConEmu`_, `ANSICON`_
147-
or `Mintty`_ (used by default in GitBash and Cygwin) free applications
148-
to add coloring support to your Windows command console.
149-
150-
Whenever you output text, you can surround the text with tags to color its
151-
output. For example::
152-
153-
// green text
154-
$output->writeln('<info>foo</info>');
155-
156-
// yellow text
157-
$output->writeln('<comment>foo</comment>');
158-
159-
// black text on a cyan background
160-
$output->writeln('<question>foo</question>');
161-
162-
// white text on a red background
163-
$output->writeln('<error>foo</error>');
164-
165-
The closing tag can be replaced by ``</>``, which revokes all formatting options
166-
established by the last opened tag.
167-
168-
It is possible to define your own styles using the class
169-
:class:`Symfony\\Component\\Console\\Formatter\\OutputFormatterStyle`::
170-
171-
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
172-
173-
// ...
174-
$style = new OutputFormatterStyle('red', 'yellow', array('bold', 'blink'));
175-
$output->getFormatter()->setStyle('fire', $style);
176-
$output->writeln('<fire>foo</>');
177-
178-
Available foreground and background colors are: ``black``, ``red``, ``green``,
179-
``yellow``, ``blue``, ``magenta``, ``cyan`` and ``white``.
180-
181-
And available options are: ``bold``, ``underscore``, ``blink``, ``reverse``
182-
(enables the "reverse video" mode where the background and foreground colors
183-
are swapped) and ``conceal`` (sets the foreground color to transparent, making
184-
the typed text invisible - although it can be selected and copied; this option is
185-
commonly used when asking the user to type sensitive information).
186-
187-
You can also set these colors and options inside the tagname::
188-
189-
// green text
190-
$output->writeln('<fg=green>foo</>');
191-
192-
// black text on a cyan background
193-
$output->writeln('<fg=black;bg=cyan>foo</>');
194-
195-
// bold text on a yellow background
196-
$output->writeln('<bg=yellow;options=bold>foo</>');
197136

198137
.. _verbosity-levels:
199138

components/console/helpers/formatterhelper.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Formatter Helper
66

77
The Formatter helpers provides functions to format the output with colors.
88
You can do more advanced things with this helper than you can in
9-
:ref:`components-console-coloring`.
9+
:doc:`/console/coloring`.
1010

1111
The :class:`Symfony\\Component\\Console\\Helper\\FormatterHelper` is included
1212
in the default helper set, which you can get by calling

console/coloring.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Coloring the Output
2+
===================
3+
4+
By using colors in the command output, you can distinguish different types of
5+
output (e.g. important messages, titles, comments, etc.).
6+
7+
.. note::
8+
9+
By default, the Windows command console doesn't support output coloring. The
10+
Console component disables output coloring for Windows systems, but if your
11+
commands invoke other scripts which emit color sequences, they will be
12+
wrongly displayed as raw escape characters. Install the `Cmder`_, `ConEmu`_, `ANSICON`_
13+
or `Mintty`_ (used by default in GitBash and Cygwin) free applications
14+
to add coloring support to your Windows command console.
15+
16+
Using Color Styles
17+
------------------
18+
19+
Whenever you output text, you can surround the text with tags to color its
20+
output. For example::
21+
22+
// green text
23+
$output->writeln('<info>foo</info>');
24+
25+
// yellow text
26+
$output->writeln('<comment>foo</comment>');
27+
28+
// black text on a cyan background
29+
$output->writeln('<question>foo</question>');
30+
31+
// white text on a red background
32+
$output->writeln('<error>foo</error>');
33+
34+
The closing tag can be replaced by ``</>``, which revokes all formatting options
35+
established by the last opened tag.
36+
37+
It is possible to define your own styles using the
38+
:class:`Symfony\\Component\\Console\\Formatter\\OutputFormatterStyle` class::
39+
40+
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
41+
42+
// ...
43+
$style = new OutputFormatterStyle('red', 'yellow', array('bold', 'blink'));
44+
$output->getFormatter()->setStyle('fire', $style);
45+
46+
$output->writeln('<fire>foo</fire>');
47+
48+
Available foreground and background colors are: ``black``, ``red``, ``green``,
49+
``yellow``, ``blue``, ``magenta``, ``cyan`` and ``white``.
50+
51+
And available options are: ``bold``, ``underscore``, ``blink``, ``reverse``
52+
(enables the "reverse video" mode where the background and foreground colors
53+
are swapped) and ``conceal`` (sets the foreground color to transparent, making
54+
the typed text invisible - although it can be selected and copied; this option is
55+
commonly used when asking the user to type sensitive information).
56+
57+
You can also set these colors and options directly inside the tagname::
58+
59+
// green text
60+
$output->writeln('<fg=green>foo</>');
61+
62+
// black text on a cyan background
63+
$output->writeln('<fg=black;bg=cyan>foo</>');
64+
65+
// bold text on a yellow background
66+
$output->writeln('<bg=yellow;options=bold>foo</>');

0 commit comments

Comments
 (0)