From: Stefan Hrdlicka <[email protected]>

Originally-by: Stefan Hrdlicka <[email protected]>
[FE: avoid changes to read_password()
     rename from read_input() to read_line()
     avoid undef warning if there is no input by avoiding chomp then
     print prompt even if not reading from interactive for better log]
Signed-off-by: Fiona Ebner <[email protected]>
---
 src/PVE/PTY.pm | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/PVE/PTY.pm b/src/PVE/PTY.pm
index 5d7d697..1db4863 100644
--- a/src/PVE/PTY.pm
+++ b/src/PVE/PTY.pm
@@ -163,6 +163,23 @@ sub tcsetsize($$$) {
         or die "failed to set window size: $!\n";
 }
 
+sub read_line($;$$) {
+    my ($query, $infd, $outfd) = @_;
+
+    $infd //= \*STDIN;
+    $outfd //= \*STDOUT;
+
+    my $msg = -t $infd ? $query : "$query\n";
+    print $outfd $msg;
+
+    my $input = '';
+    local $/ = "\n";
+    $input = <$infd>;
+    chomp $input if $input;
+
+    return $input;
+}
+
 sub read_password($;$$) {
     my ($query, $infd, $outfd) = @_;
 
-- 
2.47.2



_______________________________________________
pve-devel mailing list
[email protected]
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to