Skip to content

Console section is incorrectly updated #35012

@wskorodecki

Description

@wskorodecki

Symfony version(s) affected: 4.3.9, 4.4.1
PHP version: 7.3.12

Description
During alternating updates of individual sections, those previously displayed are incorrectly updated. This is somehow related to the number of lines displayed in between. Change 54 to 53 and then to 52 in for-loop to see the difference.

Invalid output

$ ./bin/console test:output
Section #1 after first overwrite.
Section #2, line #1.
Section #2, line #1.
Section #1 after second overwrite.
Section #2, line #1.
Section #2, line #2.
Section #2, line #3.
Section #2, line #4.
Section #2, line #5.
Test line #0.
Test line #1.
Test line #2.
Test line #3.
Test line #4.
Test line #5.
Test line #6.
Test line #7.
Test line #8.
Test line #9.
Test line #10.
Test line #11.
Test line #12.
Test line #13.
Test line #14.
Test line #15.
Test line #16.
Test line #17.
Test line #18.
Test line #19.
Test line #20.
Test line #21.
Test line #22.
Test line #23.
Test line #24.
Test line #25.
Test line #26.
Test line #27.
Test line #28.
Test line #29.
Test line #30.
Test line #31.
Test line #32.
Test line #33.
Test line #34.
Test line #35.
Test line #36.
Test line #37.
Test line #38.
Test line #39.
Test line #40.
Test line #41.
Test line #42.
Test line #43.
Test line #44.
Test line #45.
Test line #46.
Test line #47.
Test line #48.
Test line #49.
Test line #50.
Test line #51.
Test line #52.
Test line #53.

How to reproduce

<?php

declare(strict_types=1);

namespace App\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\ConsoleSectionOutput;
use Symfony\Component\Console\Output\OutputInterface;

class OutputTestCommand extends Command
{
    protected static $defaultName = 'test:output';

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var ConsoleOutputInterface $output */
        /** @var ConsoleSectionOutput $s1 */
        $s1 = $output->section();
        $s1->writeln('Section #1, line #1.');

        /** @var ConsoleSectionOutput $s2 */
        $s2 = $output->section();
        for ($i = 1; $i <= 5; $i++) {
            $s2->writeln("Section #2, line #$i.");
        }

        $s1->overwrite('Section #1 after first overwrite.');

        $s3 = $output->section();
        for ($i = 0; $i < 54; ++$i) {
            $s3->writeln("Test line #$i.");
        }

        // Now the first section will not be updated correctly.
        $s1->overwrite('Section #1 after second overwrite.');
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions