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

Re: how would I modify this to dump the buffer?

Thread Previous
From:
ToddAndMargo
Date:
September 11, 2017 05:50
Subject:
Re: how would I modify this to dump the buffer?
Message ID:
a77825b2-bc1b-1a99-70f0-16cee19a632a@zoho.com
On 09/10/2017 09:32 PM, ToddAndMargo wrote:
> 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>


Figured it out.  It will take me a little bit to clean up my example.
In the mean time, no one do any research for me.



-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thread Previous


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