-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add documentation about manipulating console output #9304
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
Conversation
console/manipulating_output.rst
Outdated
In order to manipulate the content, you need to create a new output section. An output section is | ||
a part in the terminal where information will be displayed from the console. | ||
|
||
A section can be manipulated individually, and multiple sections can appended to the output. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be
?
console/manipulating_output.rst
Outdated
} | ||
} | ||
|
||
This will return an instance of of the :class:`Symfony\\Component\\Console\\Output\\ConsoleSectionOutput` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double of
console/manipulating_output.rst
Outdated
|
||
Displaying information in a section will always append a new line to the output. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double blank line
console/manipulating_output.rst
Outdated
The only information displayed in the terminal will be ``World!`` as the first part will | ||
be overwritten. | ||
|
||
Clearing s Section |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a
?
console/manipulating_output.rst
Outdated
------------------ | ||
|
||
You can clear all the content in a section by using the | ||
:method:`Symfony\\Component\\Console\\Output\\ConsoleSectionOutput::overwrite` method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clear
?
4f9eb73
to
1b3c188
Compare
…ifyable sections (pierredup) This PR was squashed before being merged into the 4.1-dev branch (closes #24363). Discussion ---------- [Console] Modify console output and print multiple modifyable sections | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | TBD | Fixed tickets | | License | MIT | Doc PR | symfony/symfony-docs#9304 Add support to create different output sections for the console output. Each section is it's own 'stream' of output, where the output can be modified (even if there are other output after it). This allows you to modify previous output in the console, either by appending new lines, modifying previous lines or clearing the output. Modifying a sections output doesn't affect the output after that or in other sections. Some examples of what can be done: **Overwriting content in a previous section:** Code: ```php $section1 = $output->section(); $section2 = $output->section(); $section1->writeln("<comment>Doing something</comment>\n"); usleep(500000); $section2->writeln('<info>Result of first operation</info>'); usleep(500000); $section1->overwrite("<comment>Doing something else</comment>\n"); usleep(500000); $section2->writeln('<info>Result of second operation</info>'); usleep(500000); $section1->overwrite("<comment>Finishing</comment>\n"); usleep(500000); $section2->writeln('<info>Last Result</info>'); ``` Result:  **Multiple Progress Bars:** Code: ```php $section1 = $output->section(); $section2 = $output->section(); $progress = new ProgressBar($section1); $progress2 = new ProgressBar($section2); $progress->start(100); $progress2->start(100); $c = 0; while (++$c < 100) { $progress->advance(); if ($c % 2 === 0) { $progress2->advance(4); } usleep(500000); } ``` Result:  **Modifying content of a table & updating a progress bar:** Code: ```php $section1 = $output->section(); $section2 = $output->section(); $progress = new ProgressBar($section1); $table = new Table($section2); $table->addRow(['Row 1']); $table->render(); $progress->start(5); $c = 0; while (++$c < 5) { $table->appendRow(['Row '.($c + 1)]); $progress->advance(); usleep(500000); } $progress->finish(); $section1->clear(); ``` Result:  **Example with Symfony Installer:*** Before:  After:  TODO: - [x] Add unit tests Commits ------- 9ec51a1797 [Console] Modify console output and print multiple modifyable sections
…ifyable sections (pierredup) This PR was squashed before being merged into the 4.1-dev branch (closes #24363). Discussion ---------- [Console] Modify console output and print multiple modifyable sections | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | TBD | Fixed tickets | | License | MIT | Doc PR | symfony/symfony-docs#9304 Add support to create different output sections for the console output. Each section is it's own 'stream' of output, where the output can be modified (even if there are other output after it). This allows you to modify previous output in the console, either by appending new lines, modifying previous lines or clearing the output. Modifying a sections output doesn't affect the output after that or in other sections. Some examples of what can be done: **Overwriting content in a previous section:** Code: ```php $section1 = $output->section(); $section2 = $output->section(); $section1->writeln("<comment>Doing something</comment>\n"); usleep(500000); $section2->writeln('<info>Result of first operation</info>'); usleep(500000); $section1->overwrite("<comment>Doing something else</comment>\n"); usleep(500000); $section2->writeln('<info>Result of second operation</info>'); usleep(500000); $section1->overwrite("<comment>Finishing</comment>\n"); usleep(500000); $section2->writeln('<info>Last Result</info>'); ``` Result:  **Multiple Progress Bars:** Code: ```php $section1 = $output->section(); $section2 = $output->section(); $progress = new ProgressBar($section1); $progress2 = new ProgressBar($section2); $progress->start(100); $progress2->start(100); $c = 0; while (++$c < 100) { $progress->advance(); if ($c % 2 === 0) { $progress2->advance(4); } usleep(500000); } ``` Result:  **Modifying content of a table & updating a progress bar:** Code: ```php $section1 = $output->section(); $section2 = $output->section(); $progress = new ProgressBar($section1); $table = new Table($section2); $table->addRow(['Row 1']); $table->render(); $progress->start(5); $c = 0; while (++$c < 5) { $table->appendRow(['Row '.($c + 1)]); $progress->advance(); usleep(500000); } $progress->finish(); $section1->clear(); ``` Result:  **Example with Symfony Installer:*** Before:  After:  TODO: - [x] Add unit tests Commits ------- 9ec51a1 [Console] Modify console output and print multiple modifyable sections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks for the contribution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very useful. Thanks!
@pierredup thanks a lot for contributing these docs! (and for implementing the feature too ... it's amazing!) I like the contents, but I'd prefer another organization, so I'm going to merge this PR "as is" and then I'll create a different PR to reorganize contents. Cheers! |
…redup) This PR was squashed before being merged into the 4.1 branch (closes #9304). Discussion ---------- Add documentation about manipulating console output Add documentation about manipulating console output (symfony/symfony#24363) Commits ------- 3b0e00c Add documentation about manipulating console output
Add documentation about manipulating console output (symfony/symfony#24363)