develooper Front page | perl.perl6.users | Postings from September 2017

how would I modify this to dump the buffer?

Thread Next
September 11, 2017 04:32
how would I modify this to dump the buffer?
Message ID:
Hi All,

I am trying to dump the input buffer and exit when it
finds nothing left. This test code will read binary input
and it parks itself waiting for me to press "q".

How would I modify this to do dump everything and not wait
for a "q"?

#!/usr/bin/env perl6

# Reference:
# # zef install use Terminal::Print::RawInput

use Terminal::Print::RawInput;

my @z = qw[z zz zzz zzzz snore];
say "Sleeping for ", @z.elems, " seconds.  Press some keys.";
for @z { sleep 1; print "$_ " }; print "\n";

# Display character stream, exiting the program when 'q' is pressed
my $in-supply = raw-input-supply;
react {
     whenever $in-supply -> $c {
         my $char = $c.ord < 32 ?? '^' ~ ($c.ord + 64).chr !! $c;
         printf "got: %3d  %2s  %2s\r\n", $c.ord, $c.ord.base(16), $char;

         done if $c eq 'q';

# Give the input supply enough time to restore the TTY state
sleep .1;


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About