I've noticed strange behavior from readline while using it for user input from a CLI.
When I press multiple tabs it prints a scandir to the input stream.
Below is the code:
$msg = "";
while ($msg != "quit")
{
while (($msg == "") || ($msg == "\r"))
$msg = readline ("> ");
}
CodePudding user response:
This is behavior from your shell. You will get the same result without running the PHP script. At the prompt, type >
and tab twice.
You can prevent this by registering a no-op completion with readline_completion_function.
<?php
$msg = "";
readline_completion_function(function ()
{
return [];
});
while ($msg != "quit")
{
while (($msg == "") || ($msg == "\r"))
{
$msg = readline("> ");
}
}
CodePudding user response:
To stop this behavior, register an auto complete function that returns no matches to auto complete.
function dontAutoComplete ($input, $index)
{ return ([]); }
readline_completion_function ("dontAutoComplete");