Perl6:getc处于原始模式

时间:2015-08-12 07:37:48

标签: perl terminal perl6 getc

我使用的是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);

当我运行此脚本并按下向上箭头向下箭头向右箭头左键arrow 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

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

1 个答案:

答案 0 :(得分:2)

var jsonBlob = []byte(`[ {"Name": "Platypus", "Purchase": "Monotremata"}, {"Name": "Quoll", "Purchase": "Dasyuromorphia"} ]`) type Animal struct { Name string Order string `json:"Purchase"` } var animals []Animal err := json.Unmarshal(jsonBlob, &animals) if err != nil { fmt.Println("error:", err) } fmt.Printf("%+v", animals) 替换为my $c = $*IN.getc;并更改代码的其余部分以处理缓冲区而不是字符串。