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

how would I modify this to dump the buffer?

Thread Next
From:
ToddAndMargo
Date:
September 11, 2017 04:32
Subject:
how would I modify this to dump the buffer?
Message ID:
e2e60a9e-94d4-1cdb-96b9-c91ec813ef44@zoho.com
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"?

<code>
#!/usr/bin/env perl6

# Reference: 
https://github.com/ab5tract/Terminal-Print/blob/1c05a17dd0390447d5a26da29467729d5803bea8/examples/raw-input.p6
# # 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;

</code>

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About