如何在 cygwin 下处理 Perl 脚本中的箭头键?

发布于 2024-08-18 06:24:43 字数 552 浏览 7 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剩余の解释 2024-08-25 06:24:43

查看 Term::Readline 模块。这将接管您的程序的输入,并处理历史记录,这就是我认为您正在谈论的内容。

这将是您的程序直接转换为使用 Term::ReadLine:
<代码> <代码>

 use Term::ReadLine;
 my $term = new Term::ReadLine 'Simple Perl calc';
 my $prompt = "Enter Input: ";
 while ( defined ($_ = $term->readline($prompt)) ) {
   print "Recieved Input:$_\n";
   $term->addhistory($_) if /\S/;
 }

>

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:

 use Term::ReadLine;
 my $term = new Term::ReadLine 'Simple Perl calc';
 my $prompt = "Enter Input: ";
 while ( defined ($_ = $term->readline($prompt)) ) {
   print "Recieved Input:$_\n";
   $term->addhistory($_) if /\S/;
 }

此生挚爱伱 2024-08-25 06:24:43

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文