Perl6:原始模式下的 getc

Perl6: getc in raw mode

我正在使用 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);

当我 运行 这个脚本并按下按键 up-arrow, down-arrow, right-arrowleft-arrowq 这是输出:

#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); 并更改其余代码以处理缓冲区而不是字符串。