【发布时间】:2013-08-18 00:21:17
【问题描述】:
我的 php 交互式 CLI 程序有一个错误。
我使用 readline_add_history 将命令添加到历史记录中,并使用 readline 将它们读入。
错误是,如果使用向上箭头键,我在历史记录中滚动到 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. **
在哪里可以查看涉及箭头键/命令历史记录的代码?我在网上查找了有关 readline 如何处理箭头键和历史记录的资源,但我找不到任何东西。
我的代码是这样的:
while(true)
{
$command = readline( "\n%" );
.. do stuff ..
readline_add_history( $command );
}
我也有一个 readline_completion_function,但是当我使用箭头键时它没有被调用。
【问题讨论】:
-
我猜它在 sapi/cli/php_cli.c
-
关于为什么它只打印第一个字符,并且只打印 5 个字符或更长的命令有什么想法吗?
标签: php command-line readline