public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hrdlicka <s.hrdlicka@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-common 1/3] remove dependency on Term::ReadLine (see #2077)
Date: Mon,  9 May 2022 09:30:32 +0200	[thread overview]
Message-ID: <20220509073034.822117-2-s.hrdlicka@proxmox.com> (raw)
In-Reply-To: <20220509073034.822117-1-s.hrdlicka@proxmox.com>

Signed-off-by: Stefan Hrdlicka <s.hrdlicka@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




  reply	other threads:[~2022-05-09  7:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-09  7:30 [pve-devel] [PATCH pve-common 0/3] remove dependency on Term::ReadLine Stefan Hrdlicka
2022-05-09  7:30 ` Stefan Hrdlicka [this message]
2022-05-09  7:30 ` [pve-devel] [PATCH pve-manager 2/3] remove dependency on Term::ReadLine (see #2077) Stefan Hrdlicka
2022-05-09  7:30 ` [pve-devel] [PATCH qemu-server 3/3] " Stefan Hrdlicka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220509073034.822117-2-s.hrdlicka@proxmox.com \
    --to=s.hrdlicka@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal