Skip to content
Snippets Groups Projects
Commit 890855ff authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Replaced ReadKey and <STDIN> with IO::Prompt

parent b25cf8a3
No related branches found
No related tags found
No related merge requests found
...@@ -38,11 +38,13 @@ if (!eval {require Net::LDAP; 1;}) { ...@@ -38,11 +38,13 @@ if (!eval {require Net::LDAP; 1;}) {
print STDERR "You're missing Net::LDAP, try 'apt-get install libnet-ldap-perl'\n"; print STDERR "You're missing Net::LDAP, try 'apt-get install libnet-ldap-perl'\n";
exit 1; exit 1;
} }
# Check Term::ReadKey # Check IO::Prompt
if (!eval {require Term::ReadKey; 1;}) { if (!eval {require IO::Prompt; 1;}) {
print STDERR "You're missing Term::ReadKey, try 'apt-get install libterm-readkey-perl'\n"; print STDERR "You're missing IO::Prompt, try 'apt-get install libio-prompt-perl'\n";
exit 1; exit 1;
} }
use IO::Prompt qw( prompt );
use User::pwent; use User::pwent;
...@@ -211,12 +213,7 @@ KWALLET_END: ...@@ -211,12 +213,7 @@ KWALLET_END:
# If kwallet returned nothing, try read from terminal # If kwallet returned nothing, try read from terminal
if (!defined($password) || $password eq "") { if (!defined($password) || $password eq "") {
print STDERR "Your LDAP Password: "; $password = prompt("Your LDAP Password: ", '-echo' => "*");
# Don't echo password
Term::ReadKey::ReadMode('noecho');
chomp($password = <STDIN>);
# Turn echo back on
Term::ReadKey::ReadMode(0);
} }
print STDERR "\n"; print STDERR "\n";
...@@ -271,9 +268,25 @@ if ($ldapNumResults < 1) { ...@@ -271,9 +268,25 @@ if ($ldapNumResults < 1) {
logger('MENU '.$counter," ".color('red')."%s".color('reset'),$key); logger('MENU '.$counter," ".color('red')."%s".color('reset'),$key);
$counter++; $counter++;
} }
print STDERR "Your selection: "; my $menuSelection = prompt("Your selection [1-$ldapNumResults,q]: ",
chomp(my $menuSelection = <STDIN>); '-onechar',
if ($menuSelection =~ /\D/) { '-require' => {
"Invalid Value - Your selection [1-$ldapNumResults,q]: " => sub {
my $val = $_;
return (
# Check if is numeric and its within range
$val =~ /^\d$/ &&
$val > 0 &&
$val <= $ldapNumResults
) || (
# Else our only other option we accept is 'q'
$val eq "q"
);
}
}
);
if ($menuSelection eq "q") {
print STDERR "Exiting...\n";
exit 3; exit 3;
} }
$menuSelection--; $menuSelection--;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment