[pve-devel] [PATCH pve-common 1/3] remove dependency on Term::ReadLine (see #2077)

Stefan Hrdlicka s.hrdlicka at proxmox.com
Mon May 9 09:30:32 CEST 2022


Signed-off-by: Stefan Hrdlicka <s.hrdlicka at proxmox.com>
---
 README.dev     |  2 +-
 src/PVE/PTY.pm | 21 ++++++++++++++++++---
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/README.dev b/README.dev
index cb6bcf8..af17116 100644
--- a/README.dev
+++ b/README.dev
@@ -62,7 +62,7 @@ libstring-shellquote-perl dh-systemd rpm2cpio libsqlite3-dev sqlite3 \
 libglib2.0-dev librrd-dev librrds-perl rrdcached libdigest-hmac-perl \
 libxml-parser-perl gdb libcrypt-openssl-random-perl \
 libcrypt-openssl-rsa-perl libnet-ldap-perl libauthen-pam-perl \
-libjson-xs-perl libterm-readline-gnu-perl oathtool libmime-base32-perl \
+libjson-xs-perl oathtool libmime-base32-perl \
 liboath0 libpci-dev texi2html libsdl1.2-dev libgnutls28-dev \
 libspice-protocol-dev xfslibs-dev libnuma-dev libaio-dev \
 pve-libspice-server-dev libusbredirparser-dev glusterfs-common \
diff --git a/src/PVE/PTY.pm b/src/PVE/PTY.pm
index e433c4e..7b90150 100644
--- a/src/PVE/PTY.pm
+++ b/src/PVE/PTY.pm
@@ -165,6 +165,23 @@ sub tcsetsize($$$) {
 	or die "failed to set window size: $!\n";
 }
 
+sub read_input($;$$) {
+    my ($query, $infd, $outfd) = @_;
+    my $input = '';
+    $infd //= \*STDIN;
+
+    if (-t $infd) {
+        $outfd //= \*STDOUT;
+        print $outfd $query;
+    }
+
+    local $/ = "\n";
+    $input = <$infd>;
+    chomp $input;
+
+    return $input;
+}
+
 sub read_password($;$$) {
     my ($query, $infd, $outfd) = @_;
 
@@ -173,10 +190,8 @@ sub read_password($;$$) {
     $infd //= \*STDIN;
 
     if (!-t $infd) { # Not a terminal? Then just get a line...
-	local $/ = "\n";
-	$password = <$infd>;
+        $password = read_input("", $infd, $outfd);
 	die "EOF while reading password\n" if !defined $password;
-	chomp $password; # Chop off the newline
 	return $password;
     }
 
-- 
2.30.2




More information about the pve-devel mailing list