Skip to content

Conversation

@valx76
Copy link
Contributor

@valx76 valx76 commented Sep 29, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues
License MIT

QuestionHelper is blocking signals because of its fgets/fgetc use.
This PR uses fread so signals can be dispatched in text inputs.
Since Windows is not supported by the PCNTL extension, it was working fine on this OS.

Note

This change has been tested in Windows, Linux and MacOS.


Snippet to test the behavior manually:

use Symfony\Component\Console\Attribute\Argument;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;

#[AsCommand(name: 'app:test')]
class TestCommand
{
    public function __invoke(
        InputInterface $input,
        OutputInterface $output,
        #[Argument('Mode (single / multi)')] string $mode = 'single'
    ): int {
        $question = new Question('Enter text: ');
        $question->setMultiline($mode !== 'single');

        $helper = new QuestionHelper();
        $result = $helper->ask($input, $output, $question);

        $output->writeln('Result: '.$result);

        return Command::SUCCESS;
    }
}

Usage:

  • Single line input: php bin/console app:test single
  • Multiline input: php bin/console app:test multi

@valx76
Copy link
Contributor Author

valx76 commented Sep 29, 2025

Closing this while waiting for #61861 to be merged.
As discussed with @nicolas-grekas, I'll create a new one afterwards and set it as bugfix instead.

@valx76 valx76 closed this Sep 29, 2025
@valx76 valx76 deleted the feature/handle-signals-on-text-input branch October 5, 2025 18:22
nicolas-grekas added a commit that referenced this pull request Dec 5, 2025
This PR was squashed before being merged into the 6.4 branch.

Discussion
----------

 [Console] Handle signals on text input

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

`QuestionHelper` is blocking signals because of its `fgets`/`fgetc` use.
This PR uses `fread` so signals can be dispatched in text inputs.
Since Windows is not supported by the PCNTL extension, it was working fine on this OS.
This change has been tested in Windows, Linux and MacOS.

> [!NOTE]
>  This PR replaces #61878.

---

Snippet to test the behavior manually:
```php
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;

#[AsCommand('app:test')]
class TestCommand extends Command
{
    protected function configure(): void
    {
        $this->addArgument('mode', InputArgument::OPTIONAL, default: 'single');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $mode = $input->getArgument('mode');

        $question = new Question('Enter text: ');
        $question->setMultiline($mode !== 'single');

        $helper = new QuestionHelper();
        $result = $helper->ask($input, $output, $question);

        $output->writeln('Result: '.$result);

        return Command::SUCCESS;
    }
}
```

Usage:
- Single line input: `php bin/console app:test single`
- Multiline input: `php bin/console app:test multi`

Commits
-------

7c40cad Handle signals on text input
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.

3 participants