Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions src/Illuminate/Console/QuestionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Console;

use Illuminate\Console\View\Components\TwoColumnDetail;
use Illuminate\Support\Arr;
use Illuminate\Support\Stringable;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
Expand Down Expand Up @@ -35,28 +36,30 @@ protected function writePrompt(OutputInterface $output, Question $question): voi
: '<comment>Ctrl+D</comment>');
}

switch (true) {
case null === $default:
$text = sprintf('<info>%s</info>', $text);

break;

case $question instanceof ConfirmationQuestion:
$text = sprintf('<info>%s (yes/no)</info> [<comment>%s</comment>]', $text, $default ? 'yes' : 'no');

break;

case $question instanceof ChoiceQuestion:
$choices = $question->getChoices();
$text = sprintf('<info>%s</info> [<comment>%s</comment>]', $text, OutputFormatter::escape($choices[$default] ?? $default));

break;

default:
$text = sprintf('<info>%s</info> [<comment>%s</comment>]', $text, OutputFormatter::escape($default));

break;
}
$text = match (true) {
null === $default => sprintf(
'<info>%s</info>',
$text
),

$question instanceof ConfirmationQuestion => sprintf(
'<info>%s (yes/no)</info> [<comment>%s</comment>]',
$text,
$default ? 'yes' : 'no'
),

$question instanceof ChoiceQuestion => sprintf(
'<info>%s</info> [<comment>%s</comment>]',
$text,
OutputFormatter::escape(Arr::get($question->getChoices(), $default, $default)),
),

default => sprintf(
'<info>%s</info> [<comment>%s</comment>]',
$text,
OutputFormatter::escape($default)
),
};

$output->writeln($text);

Expand Down