Term::Cap:“key up”不起作用
#!/usr/bin/env perl
use warnings;
use 5.014;
use Term::Cap;
use POSIX;
my $termios = new POSIX::Termios;
$termios->getattr;
my $ospeed = $termios->getospeed;
my $terminal = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed };
$terminal->Trequire("ku"); # move cursor up
my $UP = $terminal->Tputs("ku");
my $t = 500;
while ($t > 0) {
printf "Hour: %d \n", $t/3600;
printf "Minute: %d \n", ($t/60)%60;
printf "Second: %d \n", $t%60;
print $UP,$UP,$UP;
sleep 5;
$t -= 5;
}
当我尝试这个时(在这里找到:如何更新屏幕上的值而不在 Perl 中清除它?)我得到以下输出:
Hour: 0
Minute: 8
Second: 20
AAAHour: 0
Minute: 8
Second: 15
AAAHour: 0
Minute: 8
Second: 10
AAAHour: 0
Minute: 8
Second: 5
这是否意味着 key-up
不适用于我的终端?
#!/usr/bin/env perl
use warnings;
use 5.014;
use Term::Cap;
use POSIX;
my $termios = new POSIX::Termios;
$termios->getattr;
my $ospeed = $termios->getospeed;
my $terminal = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed };
$terminal->Trequire("ku"); # move cursor up
my $UP = $terminal->Tputs("ku");
my $t = 500;
while ($t > 0) {
printf "Hour: %d \n", $t/3600;
printf "Minute: %d \n", ($t/60)%60;
printf "Second: %d \n", $t%60;
print $UP,$UP,$UP;
sleep 5;
$t -= 5;
}
When I try this (found here: How can I update values on the screen without clearing it in Perl?) I get this output:
Hour: 0
Minute: 8
Second: 20
AAAHour: 0
Minute: 8
Second: 15
AAAHour: 0
Minute: 8
Second: 10
AAAHour: 0
Minute: 8
Second: 5
Does this mean, that key-up
doesn't work with my terminal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您误解了
ku
功能。这是当用户按终端上的向上箭头键时生成的字符序列。要实际在屏幕上向上移动光标,请打印up
功能。 (另外,最好避免间接对象语法,尽管这与您的问题无关。)这是一个更正的版本:
您可能会发现 Termcap 手册 有帮助。它解释了所有功能的含义。
You've misunderstood the
ku
capability. That's the character sequence generated when the user presses the up arrow key on the terminal. To actually move the cursor up on the screen, you print theup
capability. (Also, it's best to avoid the indirect object syntax, although that had nothing to do with your problem.)Here's a corrected version:
You may find the Termcap manual helpful. It explains what all the capabilities mean.