gpt4 book ai didi

Perl6 : getc in raw mode

转载 作者:行者123 更新时间:2023-12-04 02:47:36 25 4
gpt4 key购买 nike

我正在使用 Perl 6 模块 Term::termios .

#!/usr/bin/env perl6
use v6;
use Term::termios;

my $saved_termios := Term::termios.new(fd => 1).getattr;
my $termios := Term::termios.new(fd => 1).getattr;
$termios.makeraw;
$termios.setattr(:DRAIN);

loop {
my $c = $*IN.getc;
print "got: " ~ $c.ord ~ "\r\n";
last if $c eq 'q';
}

$saved_termios.setattr(:DRAIN);

当我运行此脚本并按向上箭头、向下箭头、向右箭头、向左箭头和 q 键时,这是输出:
#after arrow-up:
got: 27
got: 91

#after arrow-down:
got: 65
got: 27
got: 91

#after arrow-right:
got: 66
got: 27
got: 91

#after arrow-left:
got: 67
got: 27
got: 91

#after q:
got: 68

#after another q:
got: 113

但我本来预计:
#after arrow-up:
got: 27
got: 91
got: 65

#after arrow-down:
got: 27
got: 91
got: 66

#after arrow-right:
got: 27
got: 91
got: 67

#after arrow-left:
got: 27
got: 91
got: 68

#after q:
got: 113

如何修改脚本以获得所需的输出?

最佳答案

替换 my $c = $*IN.getc;my $c = $*IN.read(1);并更改其余代码以处理缓冲区而不是字符串。

关于Perl6 : getc in raw mode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31958891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com