diff --git a/src/Helpers/QuestionHelper.php b/src/Helpers/QuestionHelper.php index 39a3fe0..e6bd7c5 100644 --- a/src/Helpers/QuestionHelper.php +++ b/src/Helpers/QuestionHelper.php @@ -5,7 +5,7 @@ namespace Termwind\Helpers; use Symfony\Component\Console\Formatter\OutputFormatter; -use Symfony\Component\Console\Helper\QuestionHelper as SymfonyQuestionHelper; +use Symfony\Component\Console\Helper\SymfonyQuestionHelper; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\Question; diff --git a/src/Question.php b/src/Question.php index 399d409..4108919 100644 --- a/src/Question.php +++ b/src/Question.php @@ -4,10 +4,12 @@ namespace Termwind; -use Symfony\Component\Console\Helper\QuestionHelper as SymfonyQuestionHelper; +use ReflectionClass; +use Symfony\Component\Console\Helper\SymfonyQuestionHelper; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\StreamableInputInterface; use Symfony\Component\Console\Question\Question as SymfonyQuestion; +use Symfony\Component\Console\Style\SymfonyStyle; use Termwind\Helpers\QuestionHelper; /** @@ -53,6 +55,27 @@ public function ask(string $question): mixed { $html = (new HtmlRenderer)->parse($question)->toString(); + $output = Termwind::getRenderer(); + + if ($output instanceof SymfonyStyle) { + $property = (new ReflectionClass(SymfonyStyle::class)) + ->getProperty('questionHelper'); + + $property->setAccessible(true); + + $currentHelper = $property->isInitialized($output) + ? $property->getValue($output) + : new SymfonyQuestionHelper(); + + $property->setValue($output, new QuestionHelper); + + try { + return $output->ask($html); + } finally { + $property->setValue($output, $currentHelper); + } + } + return $this->helper->ask( self::getStreamableInput(), Termwind::getRenderer(),