On 09/09/2017 12:07 AM, ToddAndMargo wrote:
On 09/08/2017 11:41 PM, ToddAndMargo wrote:
Hi All!
I am trying to convert some Perl 5 code to Perl 6.
What do I use in place of
use Term::ReadKey qw ( ReadKey ReadMode );
I am trying to convert the following:
<code>
use Term::ReadKey qw ( ReadKey ReadMode );
sub DumpKeyboard () {
# Dump the contents of the keyboard buffer, if any
my $Trash;
ReadMode 4; # Turn off controls keys
while ( defined ( $Trash = ReadKey ( -1, \*STDIN ) ) ) {
# print "\$Trash = $Trash\n";
}
ReadMode 1; # Reset tty mode before exiting
}
</code>
Fedora Linux 26 and Scientific Linux 7.3
So far, I have:
<code>
#!/usr/bin/env perl6
# Pause.pm6
use Term::termios;
# reference: https://github.com/krunen/term-termios
# # zef install Term::termios (as root)
# `man termios` for flags
sub Pause () is export {
# Save the previous attrs
my $saved_termios := Term::termios.new(fd => 1).getattr;
# Get the existing attrs in order to modify them
my $termios := Term::termios.new(fd => 1).getattr;
# Set the tty to raw mode
$termios.makeraw;
# You could also do the same in the old-fashioned way
$termios.unset_iflags(<BRKINT ICRNL ISTRIP IXON>);
$termios.set_oflags(<ONLCR>);
$termios.set_cflags(<CS8>);
$termios.unset_lflags(<ECHO ICANON IEXTEN ISIG>);
# Set the modified atributes, delayed until the buffer is emptied
$termios.setattr(:DRAIN);
print "\n";
print "Press any key to continue...";
# Loop on characters from STDIN
# loop {
# my $c = $*IN.getc;
# print "got: " ~ $c.ord ~ "\r\n";
# last if $c eq 'q';
# }
my $c = $*IN.getc;
# Restore the saved, previous attributes before exit
$saved_termios.setattr(:DRAIN);
print "\n";
}
</code>
But it stacks up Carriage Returns (enter key). And it just
acts weird.
And "man termios" is not showing any of the flags he is using.
:'(
What am I doing wrong?
-T
And you have to press "any" key twice.
Here is a tester:
<code>
#!/usr/bin/env perl6
use lib '/home/linuxutil';
use strict;
use Pause; # qw[ Pause ];
Pause;
</code>
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~