【发布时间】:2013-02-03 11:06:56
【问题描述】:
我有以下脚本,与文档概要段落中的示例几乎相同。
use strict;
use warnings;
use Term::ReadLine;
my $term = Term::ReadLine->new('My shell');
print $term, "\n";
my $prompt = "-> ";
while ( defined ($_ = $term->readline($prompt)) ) {
print $_, "\n";
$term->addhistory($_);
}
它执行没有错误,但不幸的是,即使我单击向上箭头,我也只能得到^[[A 并且没有历史记录。我错过了什么?
print $term 语句打印出Term::ReadLine::Stub=ARRAY(0x223d2b8)。
既然我们在这里,我注意到它会打印带下划线的提示...但我在文档中找不到任何可以阻止它的内容。有什么办法可以避免吗?
【问题讨论】:
-
它适用于我(Debian 上的 Perl 5.10)。你检查过你的终端键绑定吗?
-
@Rob,您使用的是哪个 Term::ReadLine 实现?在我安装 Term::ReadLine::Gnu 后它对我有用,但我认为即使使用 Stub 也应该可以工作......
标签: perl readline arrow-keys