OK, TL;DR you press “q” but nothing happens, and then “q” is received when you
press something else.

This has been brought up several times, and the reason is that perl 6 works
with unicode strings by default (with NFG). It cannot give you “q” right away
because there can be a combiner following the q, and therefore it has to wait
for the next character to make sure it can return the first one. That's just
how perl 6 rolls by default.

If you don't want that, you can use something like this:

INIT { $*IN.encoding: ‘ASCII’ }

Or anything else that'd make it not read unicode strings.

I'm rejecting this in favor of a doc ticket in Term::termios bug tracker:
https://github.com/krunen/term-termios/issues/10

Maybe the intention of this ticket was that it has to be handled on rakudo side
somehow, but I don't think that's right. That being said, if you have any
additional info please let us know and we will reopen the ticket.

On 2015-08-17 05:28:12, cue...@gmail.com wrote:
> Hi, when I run this script
>
> #!/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);
>
> and press the keys <kbd>up-arrow</kbd>, <kbd>down-arrow</kbd>,
> <kbd>right-arrow</kbd>, <kbd>left-arrow</kbd> and <kbd>q</kbd> I get
> this output:
>
> #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 have expected this output:
>
> #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
>

Reply via email to