public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH common 1/4] pty: introduce read_line() function
Date: Thu, 18 Sep 2025 15:50:53 +0200	[thread overview]
Message-ID: <20250918135215.95188-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250918135215.95188-1-f.ebner@proxmox.com>

From: Stefan Hrdlicka <s.hrdlicka@proxmox.com>

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



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  reply	other threads:[~2025-09-18 13:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-18 13:50 [pve-devel] [PATCH-SERIES common/manager/qemu-server 0/4] fix #2077: remove dependency on Term::ReadLine Fiona Ebner
2025-09-18 13:50 ` Fiona Ebner [this message]
2025-09-18 13:50 ` [pve-devel] [RFC common 2/4] developer readme: remove libterm-readline-gnu-perl dependency Fiona Ebner
2025-09-18 14:12   ` Fiona Ebner
2025-09-18 13:50 ` [pve-devel] [PATCH manager 3/4] partially fix #2077: remove dependency on Term::ReadLine Fiona Ebner
2025-09-18 13:50 ` [pve-devel] [RFC qemu-server 4/4] " Fiona Ebner

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=20250918135215.95188-2-f.ebner@proxmox.com \
    --to=f.ebner@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