package Pause;
require Exporter;
use strict;
use warnings;
use diagnostics;
# use diagnostics "-verbose";
use Term::ReadKey qw ( ReadKey ReadMode );
# our @ISA = qw( Exporter );
use Exporter qw(import);
our @EXPORT = qw(); # symbols to be exported by default (space-separated)
our $VERSION = 0.01;
our @EXPORT_OK = qw( Pause DumpKeyboard );
# dnf install perl-TermReadKey
#
# Refernece: https://metacpan.org/pod/Term::ReadKey
# ReadMode MODE [, Filehandle]
#
# Takes an integer argument, which can currently be one of the following values:
#
# 0 Restore original settings.
# 1 Change to cooked mode.
# 2 Change to cooked mode with echo off.
# (Good for passwords)
# 3 Change to cbreak mode.
# 4 Change to raw mode.
# 5 Change to ultra-raw mode.
# (LF to CR/LF translation turned off)
#
# Or, you may use the synonyms:
#
# restore
# normal
# noecho
# cbreak
# raw
# ultra-raw
#
#
# ReadKey MODE [, Filehandle]
#
# Takes an integer argument, which can currently be one of the following values:
#
# 0 Perform a normal read using getc
# -1 Perform a non-blocked read
# >0 Perform a timed read
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
}
sub Pause () {
my $KeyPress;
DumpKeyboard;
ReadMode 4; # Turn off controls keys
print "\n";
print "Press any key to continue...\n";
$KeyPress = ReadKey ( 0, \*STDIN );
ReadMode 1; # Reset tty mode before exiting
# print "\$KeyPress = $KeyPress\n";
print "\n";
}