Skip to content

Commit 4f04acd

Browse files
[Console] Mention Terminal color mode support
1 parent 3d5aa3f commit 4f04acd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

console.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,38 @@ call ``setAutoExit(false)`` on it to get the command result in ``CommandTester``
574574
:class:`Symfony\\Component\\Console\\Application`
575575
and extend the normal ``\PHPUnit\Framework\TestCase``.
576576

577+
578+
When testing your commands, it could be useful to understand how your command
579+
reacts on different settings like the width and the height of the terminal, or
580+
even the color mode being used.
581+
Thanks to the :class:`Symfony\\Component\\Console\\Terminal` class, you can
582+
have access to such information::
583+
584+
use Symfony\Component\Console\Terminal;
585+
use Symfony\Component\Console\Output\AnsiColorMode;
586+
587+
$terminal = new Terminal();
588+
589+
// access to number of lines available
590+
$height = $terminal->getHeight();
591+
592+
// access to number of columns available
593+
$width = $terminal->getWidth();
594+
595+
// access to the color mode
596+
$colorMode = $terminal->getColorMode();
597+
598+
// set the color mode to use
599+
$colorMode = $terminal->setColorMode(AnsiColorMode::Ansi24);
600+
601+
By default, the ``Terminal`` class uses the values of the
602+
``LINES`` and ``COLUMNS`` system environment variables.
603+
604+
.. versionadded:: 6.2
605+
606+
The support for setting and getting the current color mode was introduced
607+
in Symfony 6.2.
608+
577609
Logging Command Errors
578610
----------------------
579611

0 commit comments

Comments
 (0)