如何在 cygwin 下处理 Perl 脚本中的箭头键?
我正在 cygwin 下运行 Perl 脚本,它从
获取输入并连续处理请求。
#!/usr/bin/perl
print "Enter Input:";
while(<STDIN>) {
print "Recieved Input: $_";
print "Enter Input:";
}
$perl testPerl.pl
Enter input:input1
Recieved input:input1
Enter input:inpt2
Recieved input:input2
Enter input:
现在,我想在当前提示符下使用向上箭头:“输入输入:”来获取先前的输入,即“input2”,“input1”
在Windows环境下运行时(cmd.exe)它的行为符合预期
但 cygwin 下的问题是向上箭头字面意思是将光标向上移动 1 行,即指向“收到的输入:input2”行,
请分享您对此的想法。
I am running Perl script under cygwin which takes input from <STDIN>
and process the requests continuously.
#!/usr/bin/perl
print "Enter Input:";
while(<STDIN>) {
print "Recieved Input: $_";
print "Enter Input:";
}
$perl testPerl.pl
Enter input:input1
Recieved input:input1
Enter input:inpt2
Recieved input:input2
Enter input:
Now, I would like the up arrow at the current prompt: "Enter input:" to take the previous inputs i.e "input2","input1"
It behaves as expected when running under windows enivronment (cmd.exe)
But the problem under cygwin is that the up arrow literally takes the cursor 1 row up i.e it takes to the line "Recieved input:input2"
Please share your thoughts on this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 Term::Readline 模块。这将接管您的程序的输入,并处理历史记录,这就是我认为您正在谈论的内容。
这将是您的程序直接转换为使用 Term::ReadLine:
<代码> <代码>
>
Look at the Term::Readline module. This will take over input for your program, and handles history, which is what I think you're talking about.
This would be a direct translation of your program to using Term::ReadLine:
Windows 控制台和 Unix 终端之间的命令行历史记录处理存在很大差异。在 Windows 上,它是由控制台完成的,而在 Unix 上,则由应用程序负责。我对 Perl 一无所知,但您需要使用诸如 readline 库之类的东西。这看起来很有帮助:http://perldoc.perl.org/functions/readline.html
There's a big difference in the handling of the command line history between the Windows console and Unix terminals. On Windows, it's done by the console, whereas on Unix, applications are responsible for it. I don't know anything about Perl, but you'll need to use something like the readline library. This looks helpful: http://perldoc.perl.org/functions/readline.html