9

I have a custom command in my Symfony 3 project.

This command ask some questions like the Bundle Name.

    $io = new SymfonyStyle($input, $output);
    $question = new Question('Please enter the name of your bundle: ', 'AppBundle');
    $bundle = $io->askQuestion($question);

This code work very well but if the user made a typo error, the left arrow doesn't work.
Left arrow give ^[[D and right ^[[C

Is there a way to move cursor when user press arrow keys ?

HooK
  • 91
  • 1

1 Answers1

0

You can do that by using Symfony Styles (https://symfony.com/doc/current/console/style.html) and then you can enable arrow key support and move the cursor in your custom command.

    $io = new SymfonyStyle($input, $output);
    
    //This is where you enable arrow key support and move the cursor
    $io->getInput()->setInteractive(true);
    $io->setInputStty(['echo', 'icanon', 'opost', 'onlcr']);
    
    $question = new Question('Please enter the name of your bundle: ', 'AppBundle');
    $bundle = $io->askQuestion($question);
    
    // Reset the input config
    $io->getInput()->setInteractive(false);
    $io->setInputStty([]);
    
Lou
  • 26
  • 2
  • 5