Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc. improvements in the Console component introduction #5545

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions components/console/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ output. For example::
// white text on a red background
$output->writeln('<error>foo</error>');

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 class
:class:`Symfony\\Component\\Console\\Formatter\\OutputFormatterStyle`::

Expand All @@ -148,23 +151,27 @@ It is possible to define your own styles using the class
// ...
$style = new OutputFormatterStyle('red', 'yellow', array('bold', 'blink'));
$output->getFormatter()->setStyle('fire', $style);
$output->writeln('<fire>foo</fire>');
$output->writeln('<fire>foo</>');

Available foreground and background colors are: ``black``, ``red``, ``green``,
``yellow``, ``blue``, ``magenta``, ``cyan`` and ``white``.

And available options are: ``bold``, ``underscore``, ``blink``, ``reverse`` and ``conceal``.
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 inside the tagname::

// green text
$output->writeln('<fg=green>foo</fg=green>');
$output->writeln('<fg=green>foo</>');

// black text on a cyan background
$output->writeln('<fg=black;bg=cyan>foo</fg=black;bg=cyan>');
$output->writeln('<fg=black;bg=cyan>foo</>');

// bold text on a yellow background
$output->writeln('<bg=yellow;options=bold>foo</bg=yellow;options=bold>');
$output->writeln('<bg=yellow;options=bold>foo</>');

Verbosity Levels
~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -261,15 +268,15 @@ You can access the ``names`` argument as an array::
$text .= ' '.implode(', ', $names);
}

There are 3 argument variants you can use:
There are three argument variants you can use:

=========================== ===============================================================================================================
=========================== ===========================================================================================================
Mode Value
=========================== ===============================================================================================================
InputArgument::REQUIRED The argument is required
InputArgument::OPTIONAL The argument is optional and therefore can be omitted
InputArgument::IS_ARRAY The argument can contain an indefinite number of arguments and must be used at the end of the argument list
=========================== ===============================================================================================================
=========================== ===========================================================================================================
``InputArgument::REQUIRED`` The argument is required
``InputArgument::OPTIONAL`` The argument is optional and therefore can be omitted
``InputArgument::IS_ARRAY`` The argument can contain an indefinite number of arguments and must be used at the end of the argument list
=========================== ===========================================================================================================

You can combine ``IS_ARRAY`` with ``REQUIRED`` and ``OPTIONAL`` like this::

Expand Down Expand Up @@ -342,14 +349,14 @@ will work:

There are 4 option variants you can use:

=========================== =====================================================================================
Option Value
=========================== =====================================================================================
InputOption::VALUE_IS_ARRAY This option accepts multiple values (e.g. ``--dir=/foo --dir=/bar``)
InputOption::VALUE_NONE Do not accept input for this option (e.g. ``--yell``)
InputOption::VALUE_REQUIRED This value is required (e.g. ``--iterations=5``), the option itself is still optional
InputOption::VALUE_OPTIONAL This option may or may not have a value (e.g. ``--yell`` or ``--yell=loud``)
=========================== =====================================================================================
=============================== =====================================================================================
Option Value
=============================== =====================================================================================
``InputOption::VALUE_IS_ARRAY`` This option accepts multiple values (e.g. ``--dir=/foo --dir=/bar``)
``InputOption::VALUE_NONE`` Do not accept input for this option (e.g. ``--yell``)
``InputOption::VALUE_REQUIRED`` This value is required (e.g. ``--iterations=5``), the option itself is still optional
``InputOption::VALUE_OPTIONAL`` This option may or may not have a value (e.g. ``--yell`` or ``--yell=loud``)
=============================== =====================================================================================

You can combine ``VALUE_IS_ARRAY`` with ``VALUE_REQUIRED`` or ``VALUE_OPTIONAL`` like this:

Expand Down