Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP交互式CLI:历史记录的上下箭头_Php_Command Line_Readline - Fatal编程技术网

PHP交互式CLI:历史记录的上下箭头

PHP交互式CLI:历史记录的上下箭头,php,command-line,readline,Php,Command Line,Readline,我的php交互式CLI程序有一个bug 我使用readline\u add\u history将命令添加到历史记录中,并使用readline读取它们 错误在于,如果使用向上箭头键,我在历史记录中滚动到一个5个字符或更长的命令,即命令的第一个字符“sticks”,并且在我继续使用箭头键再次滚动后,将停留在那里。只有在我按下回车键后,它才会消失 例如: 我还有一个readline_completion_函数,但当我使用箭头键时,它没有被调用。如果提示字段中有您使用过的“不可打印”字符,则readli

我的php交互式CLI程序有一个bug

我使用readline\u add\u history将命令添加到历史记录中,并使用readline读取它们

错误在于,如果使用向上箭头键,我在历史记录中滚动到一个5个字符或更长的命令,即命令的第一个字符“sticks”,并且在我继续使用箭头键再次滚动后,将停留在那里。只有在我按下回车键后,它才会消失

例如:


我还有一个readline_completion_函数,但当我使用箭头键时,它没有被调用。

如果提示字段中有您使用过的“不可打印”字符,则readline()和提示字段(使用PHP 5.5.9 Ubuntu测试)似乎存在错误

我也遇到过类似的问题,当尝试使用ESC代码给提示上色时,它只会导致历史记录功能失控:(

示例:$_命令=readline(“\033[32m PHP>\033[35m”)


不幸的是,如果您想让历史记录函数正常工作,提示符中只能有普通字符。

我猜它在sapi/cli/php_cli.cAny中,为什么它只打印第一个字符,并且只打印5个字符或更长的命令?
% hello
<enter>
%
<up arrow key>
% hello
<down arrow key>
% h
<up arrow key>
% hhello
<down arrow key>
% h
<enter>
%
<up arrow key>
% hello
** notice here that the extra h isn't read in as a command. **
while(true)
{

$command = readline( "\n%" );

.. do stuff ..

readline_add_history( $command );

}