Skip to content

[Console] fix clear of section with question #48897

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

Merged
merged 1 commit into from
Feb 19, 2023

Conversation

maxbeckers
Copy link
Contributor

Q A
Branch? 6.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #47411
License MIT
Doc PR n/a

This PR fixes the problems to clear a section with a question included.

Example Code:

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $section1 = $output->section();
        $io = new SymfonyStyle($input, $section1);

        $output->writeln("foo");

        $countdown = 3;
        while ($countdown > 0) {
            $section1->clear();
            $io->writeln('start ' . $countdown);
            $io->write('foo');
            $io->write(' and bar'.\PHP_EOL);
            $givenAnswer = $io->ask('Dummy question?');
            $section1->write('bar');
            $countdown--;
        }


        return self::SUCCESS;
    }

Output loop 1:
Screenshot 2023-01-06 142630

Output loop 1:
Screenshot 2023-01-06 142653

There was already a fix #48089 to be merged in 6.1, but the problem was that there were some changes in 6.2, so it was not possible to merge it into 6.2.

So this fix is only working for 6.2, but perhaps we could find a solution as well for the older versions. But because of the changes of console it was not possible to find a solution working for all versions.

@chalasr this fix is still with the newline always true

parent::doWrite($deleteLastLine ? $lastLine.$message : $message, true);

A change of the newline to $newline would change the behavior. Maybe we could change that in symfony 7.

To make it easier to test is here a zip with 2 testcommands in the root and the changed vendors.
test-48089.zip

@chalasr
Copy link
Member

chalasr commented Feb 19, 2023

Thanks for fixing this bug @maxbeckers.

@chalasr chalasr merged commit 57901a1 into symfony:6.2 Feb 19, 2023
@fabpot fabpot mentioned this pull request Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants