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

my Pause.pm6 updated

Thread Next
October 28, 2017 04:35
my Pause.pm6 updated
Message ID:
Hi All,

With the help of Geekosaur over on the chat line, I fixed
my Pause.pm6 module.  I came across a computer where the
module froze the terminal.  Now it is fixed.  I stood on
the shoulders of giants!  Love the chat line!

Geekosaur found and reported a bug in the example of

To get my module and test program without the annoying eMail
line breaks:


<code Pause.pm6>
#!/usr/bin/env perl6
# Pause.pm6


     # zef install Term::termios   (as root)
     # zef install Terminal::Print::RawInput   (as root)

use Term::termios;
use Terminal::Print::RawInput;

sub Pause ( $PauseMessage) is export {
         This sub will
            1) dump (flush) the keyboard buffer
            2) print out $PauseMessage
            3) wait for a new (fresh) keyboard stroke
            4) return the ASCII equivalent key that was pressed

         Note: the GUI (Xfce, ec.) has precedence over reading
               unusual keys, such as the "F" keys, etc.

    my $c;
    my $char;
    my $saved_termios;
    my $termios;

    # Save the previous attrs
    $saved_termios := => 1).getattr;

    # Get the existing attrs in order to modify them
    $termios := => 1).getattr;

    # Set the tty to raw mode

    # You could also do the same in the old-fashioned way
    $termios.unset_iflags(<BRKINT ICRNL ISTRIP IXON>);
    $termios.unset_lflags(<ECHO ICANON IEXTEN ISIG>);

    # int "\n";
    print "$PauseMessage";


    # Disable Unicode grapheme processing
    $*IN.encoding: Nil;

    $c = $*'latin-1');
    $char = $c.ord < 32 ?? '^' ~ ($c.ord + 64).chr !! $c;
    print "got: " ~ $c.ord ~ "   $char\r\n";

    my $in-supply = raw-input-supply;
    react {
       whenever $in-supply -> $c {
          $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';

    # Restore the saved, previous attributes before exit
    # print "$char\n";
    return $char

<code Pause.pl6>
#!/usr/bin/env perl6

use lib '/home/linuxutil';
use strict;
use Pause; # qw[ Pause ];

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

my $Key = Pause( 'Press any key to continue... ' );
print "The key that was pressed was <$Key>\n";

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