Skip to content

Commit 2e413af

Browse files
committed
Merge branch '5.2' into 5.3
* 5.2: Minor tweaks Adds a heading for stampede prevention so I'm able to reference this section easily [#15270] Minor fixes [Console] Document console cursor Update routing.rst
2 parents 6daa122 + c159fee commit 2e413af

File tree

9 files changed

+114
-3
lines changed

9 files changed

+114
-3
lines changed

.doctor-rst.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ whitelist:
104104
- '.. versionadded:: 3.6' # MonologBundle
105105
- '// bin/console'
106106
- 'End to End Tests (E2E)'
107+
- '.. code-block:: php'

_images/components/console/cursor.gif

63.4 KB
Loading

components/cache.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ generate and return the value::
9090
Use cache tags to delete more than one key at the time. Read more at
9191
:doc:`/components/cache/cache_invalidation`.
9292

93-
The Cache Contracts also comes with built in `Stampede prevention`_. This will
93+
Stampede Prevention
94+
~~~~~~~~~~~~~~~~~~~
95+
96+
The Cache Contracts also come with built in `Stampede prevention`_. This will
9497
remove CPU spikes at the moments when the cache is cold. If an example application
9598
spends 5 seconds to compute data that is cached for 1 hour and this data is accessed
9699
10 times every second, this means that you mostly have cache hits and everything

components/console/helpers/cursor.rst

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
.. index::
2+
single: Console Helpers; Cursor Helper
3+
4+
Cursor Helper
5+
=============
6+
7+
.. versionadded:: 5.1
8+
9+
The :class:`Symfony\\Component\\Console\\Cursor` class was introduced
10+
in Symfony 5.1.
11+
12+
The :class:`Symfony\\Component\\Console\\Cursor` allows you to change the
13+
cursor position in a console command. This allows you to write on any position
14+
of the output:
15+
16+
.. image:: /_images/components/console/cursor.gif
17+
:align: center
18+
19+
.. code-block:: php
20+
21+
// src/Command/MyCommand.php
22+
namespace App\Command;
23+
24+
use Symfony\Component\Console\Command\Command;
25+
use Symfony\Component\Console\Cursor;
26+
use Symfony\Component\Console\Input\InputInterface;
27+
use Symfony\Component\Console\Output\OutputInterface;
28+
29+
class MyCommand extends Command
30+
{
31+
// ...
32+
33+
public function execute(InputInterface $input, OutputInterface $output): int
34+
{
35+
// ...
36+
37+
$cursor = new Cursor($output);
38+
39+
// moves the cursor to a specific column (1st argument) and
40+
// row (2nd argument) position
41+
$cursor->moveToPosition(7, 11);
42+
43+
// and write text on this position using the output
44+
$output->write('My text');
45+
46+
// ...
47+
}
48+
}
49+
50+
Using the cursor
51+
----------------
52+
53+
Moving the cursor
54+
.................
55+
56+
There are fews methods to control moving the command cursor::
57+
58+
// moves the cursor 1 line up from its current position
59+
$cursor->moveUp();
60+
61+
// moves the cursor 3 lines up from its current position
62+
$cursor->moveUp(3);
63+
64+
// same for down
65+
$cursor->moveDown();
66+
67+
// moves the cursor 1 column right from its current position
68+
$cursor->moveRight();
69+
70+
// moves the cursor 3 columns right from its current position
71+
$cursor->moveRight(3);
72+
73+
// same for left
74+
$cursor->moveLeft();
75+
76+
// move the cursor to a specific (column, row) position from the
77+
// top-left position of the terminal
78+
$cursor->moveToPosition(7, 11);
79+
80+
You can get the current command's cursor position by using::
81+
82+
$position = $cursor->getCurrentPosition();
83+
// $position[0] // columns (aka x coordinate)
84+
// $position[1] // rows (aka y coordinate)
85+
86+
Clearing output
87+
...............
88+
89+
The cursor can also clear some output on the screen::
90+
91+
// clears all the output from the current line
92+
$cursor->clearLine();
93+
94+
// clears all the output from the current line after the current position
95+
$cursor->clearLineAfter();
96+
97+
// clears all the output from the cursors' current position to the end of the screen
98+
$cursor->clearOutput();
99+
100+
// clears the entire screen
101+
$cursor->clearScreen();
102+
103+
You also can leverage the :method:`Symfony\\Component\\Console\\Cursor::show`
104+
and :method:`Symfony\\Component\\Console\\Cursor::hide` methods on the cursor.

components/console/helpers/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The Console Helpers
1313
questionhelper
1414
table
1515
debug_formatter
16+
cursor
1617

1718
The Console component comes with some useful helpers. These helpers contain
1819
functions to ease some common tasks.

components/console/helpers/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
* :doc:`/components/console/helpers/questionhelper`
55
* :doc:`/components/console/helpers/table`
66
* :doc:`/components/console/helpers/debug_formatter`
7+
* :doc:`/components/console/helpers/cursor`

components/console/helpers/progressbar.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ placeholder before displaying the progress bar::
349349
// 0/100 -- Start
350350

351351
$progressBar->setMessage('Task is in progress...');
352-
$progressBar->advance();
352+
$progressBar->advance();
353353
// 1/100 -- Task is in progress...
354354

355355
Messages can be combined with custom placeholders too. In this example, the

console.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,5 +454,6 @@ tools capable of helping you with different tasks:
454454
* :doc:`/components/console/helpers/table`: displays tabular data as a table
455455
* :doc:`/components/console/helpers/debug_formatter`: provides functions to
456456
output debug information when running an external program
457+
* :doc:`/components/console/helpers/cursor`: allows to manipulate the cursor in the terminal
457458

458459
.. _`exit status`: https://en.wikipedia.org/wiki/Exit_status

routing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,7 @@ use the ``generateUrl()`` helper::
24312431

24322432
While objects are converted to string when used as placeholders, they are not
24332433
converted when used as extra parameters. So, if you're passing an object (e.g. an Uuid)
2434-
as value of an extra parameter, you need to explictly convert it to a string::
2434+
as value of an extra parameter, you need to explicitly convert it to a string::
24352435

24362436
$this->generateUrl('blog', ['uuid' => (string) $entity->getUuid()]);
24372437

0 commit comments

Comments
 (0)