如何在 Perl 中识别和处理控制字符和箭头键?
我想像在 Linux 终端中一样实现命令行功能。我也在 ftp 命令中看到了这个。
- 如果我按 Tab 键,我需要列出命令。
- 如果我按下控制字符,我需要根据该字符获取该字符,我将执行一些操作。
- 如果我发出任何命令它应该执行。
为此,我尝试使用处于非规范模式的 Term::ReadKey 。但在这里我面临更多的问题,比如如果我按任何控制字符或箭头,我会得到三个字符。对于向上箭头,我得到 ASCII 27 91 65。
任何人都可以帮助我解决这个问题吗?
I want to implement the command line features like in a linux terminal. I saw this in ftp command also.
- If I press tab I need to list the commands.
- If I press control characters I need to get that characters based on that I will do some action.
- And if I give any commands it should execute.
For this I tried with Term::ReadKey that is in non-canonical mode. But here I am facing more problems like if I press any control character or arrow I got three characters. For the up arrow I got ASCII 27 91 65.
Can anyone help me out of this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不幸的是,通用的 Term::ReadLine 界面不包含可自定义的完成功能。您必须为此选择一个特定的 readline 实现。
Term::ReadLine::Gnu, Term::ReadLine::Perl 和 Term::ReadLine::Zoid 都能够执行自定义完成。 Term::ReadLine::Gnu 可能是最好的文档 。 Term::ReadLine::Perl 实际上没有文档记录,而且我没有使用 Term::ReadLine::Zoid 的经验。
Unfortunately, the generic Term::ReadLine interface doesn't include customizable completion features. You have to pick a particular readline implementation for that.
Term::ReadLine::Gnu, Term::ReadLine::Perl, and Term::ReadLine::Zoid are all capable of performing custom completion. Term::ReadLine::Gnu is probably the best documented. Term::ReadLine::Perl is virtually undocumented, and I have no experience with Term::ReadLine::Zoid.
我认为 Term::Readline 将为您提供最好的服务。
I think you'd be best served by Term::Readline.
我有一个 Perl 模块来完全解决我的需求。
即 Term::ShellUI。
感谢您的所有投入。
如果您有任何其他解决方案,我们随时欢迎。
I got one Perl module to solve my requirement fully.
that is Term::ShellUI.
Thanks for all your inputs.
And If you have any other solution is always welcome.