Term::ReadLine - 我需要按两次向上箭头来检索历史记录 [英] Term::ReadLine - I need to hit the up arrow twice to retrieve history

查看:36
本文介绍了Term::ReadLine - 我需要按两次向上箭头来检索历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Term::ReadLine 并且有一个奇怪的问题,我需要点击向上箭头两次才能从 addhistory 中检索项目.这是我正在使用的脚本.

I'm using Term::ReadLine and have an odd issue where I need to hit the up arrow twice to retrieve items from addhistory. Here's the script I'm using.

use Term::ReadLine;

my $term = Term::ReadLine->new('Term1');
print $term->ReadLine."\n";

while (defined(my $cmd = $term->readline())) {
    $term->addhistory($cmd) if $cmd =~ /\S/;
}

为了测试,我将输入一些命令",然后尝试使用向上箭头检索这些命令.我按了一次向上箭头,最后一项立即出现,但在检索每个后续项之前,我需要按两次向上箭头.

To test, I'll input a few "commands" then try to retrieve those commands with the up arrow. I hit the up arrow once and the last item comes up immediately, but I'll need to hit the up arrow twice before each following item is retrieved.

我早些时候在我正在从事的一个小项目中遇到了这个问题,并遇到了遇到同样问题的人.此问题的解决方案是对 addhistory 行进行如下修改:

I encountered this issue earlier in a little project I'm working on, and came across someone with the same issue. The resolution to this issue is a modification to the addhistory line as follows:

$term->addhistory($cmd) if $cmd !~ /\S||\n/;

它奏效了,所以我继续前进,直到 Tanktalus 在我发布的另一个问题中提出这个问题.Perl Term::ReadLine::Gnu 信号处理困难

It worked so I moved on until Tanktalus brought this up in another question I posted. Perl Term::ReadLine::Gnu Signal Handling Difficulties

他问/\S||\n/应该做什么?".好吧,让我去找那个建议这个修复的页面......是的......找不到它.因此,虽然我可以通过我发布的修改使其工作,但我有点卡住了,因为 A.我不知道为什么它会修复它,而 B.为什么我似乎是唯一一个遇到这个问题的人?

He asks "what is /\S||\n/ supposed to do?". Ok well, let me go find that page that suggested this as a fix... Yeah...can't find it. So while I can make it work with the modification I posted I'm a bit stuck since A. I don't know why it fixes it, and B. Why do I seem to be the only one with this issue?

任何帮助或建议将不胜感激!:)

Any help or advice would be appreciated! :)

使用以下版本测试了上述脚本:

Tested the above script with the following versions:

Perl - 5.12.4 and 5.16.1
Term::ReadLine::Gnu - 1.20
Term::ReadLine::Perl - 1.0303 (Just tried it to make sure it wasn't Gnu)
Term::ReadLine - 1.10

推荐答案

/\S||\n/ 将始终匹配,因此您永远不会调用 addhistory.如果 $term->Features->{autohistory} 为 true,则无论如何您都不需要.

/\S||\n/ will always match, so you will never be calling addhistory. If $term->Features->{autohistory} is true, you didn't need to anyway.

按两次向上箭头"是指每两次向上箭头就向上移动一次历史记录?如果是这样,您对 addhistory 的不必要调用就是罪魁祸首.完全删除调用是适当的修复.

By "hit the up arrow twice", do you mean that you move up through the history once for every two up arrows? If so, your unnecessary call to addhistory is the culprit. And just removing the call entirely is the appropriate fix.

这篇关于Term::ReadLine - 我需要按两次向上箭头来检索历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆