diff --git a/configure.php b/configure.php index 26104fb..1f8c523 100644 --- a/configure.php +++ b/configure.php @@ -198,8 +198,15 @@ function ask(string $question, string $default = ''): string { - $def = $default ? "\e[0;33m ($default)" : ''; - $answer = readline("\e[0;32m" . $question . $def . ": \e[0m"); + fwrite(STDOUT, "\e[0;32m{$question}"); + + if ($default !== '') { + fwrite(STDOUT, "\e[0;33m ({$default})"); + } + + fwrite(STDOUT, "\e[0m: "); + + $answer = readline(); if (! $answer) { return $default; diff --git a/tests/configure_ask_regression.php b/tests/configure_ask_regression.php new file mode 100644 index 0000000..62b6897 --- /dev/null +++ b/tests/configure_ask_regression.php @@ -0,0 +1,74 @@ + ask('Author name', 'Taylor Otwell'), + 'writes' => $writes, + 'readlineArguments' => $readlineArguments, +]; +PHP; + +$result = eval($script); + +assertSameValue('Taylor Otwell', $result['result'], 'ask() should return the default value when readline() returns an empty string.'); + +assertSameValue([ + ['stdout', "\e[0;32mAuthor name"], + ['stdout', "\e[0;33m (Taylor Otwell)"], + ['stdout', "\e[0m: "], +], $result['writes'], 'ask() should print the prompt with fwrite() before calling readline().'); + +assertSameValue([], $result['readlineArguments'], 'ask() should call readline() without passing ANSI prompt text.'); + +fwrite(STDOUT, "configure ask regression passed\n");