[pve-devel] [PATCH common 1/4] pty: introduce read_line() function
Fiona Ebner
f.ebner at proxmox.com
Thu Sep 18 15:50:53 CEST 2025
From: Stefan Hrdlicka <s.hrdlicka at proxmox.com>
Originally-by: Stefan Hrdlicka <s.hrdlicka at proxmox.com>
[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 <f.ebner at proxmox.com>
---
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
More information about the pve-devel
mailing list