Perl6: getc in raw mode

I am using the Perl 6 Term :: termios module.

#!/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); 

When I run this script and press the up-arrow , down-arrow , right-arrow , left-arrow and q keys, this is the result:

 #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 

But I would expect:

 #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 

How can I change the script to get the desired result?

+7
terminal perl perl6 getc
source share
1 answer

Replace my $c = $*IN.getc; on my $c = $*IN.read(1); and change the rest of the code to handle the buffer instead of the line.

+2
source share

All Articles