public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pmg-devel] [PATCH-SERIES pmg-api 0/3] fix #2077: remove dependency on Term::ReadLine
@ 2025-09-18 14:19 Fiona Ebner
  2025-09-18 14:19 ` [pmg-devel] [PATCH pmg-api 1/4] partially fix #2077: pmgconfig: " Fiona Ebner
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Fiona Ebner @ 2025-09-18 14:19 UTC (permalink / raw)
  To: pmg-devel

As a side-effect, this also fixes #6748.

Term::ReadLine would prompt and read from terminal even if
stdin/stdout are redirected, the new helper will use the redirected
channels. It also would underline the prompt, which the new helper
does not. And Term::ReadLine also has advanced editing and history
shortcuts.

For the prompts in pmgconfig and pmgcm, not having the advanced
features is perfectly fine. For pmgsh, which additionally configures
even more features of than mentioned above, the change is rather bad.

Depends on the following pve-common patch:
https://lore.proxmox.com/pve-devel/20250918135215.95188-2-f.ebner@proxmox.com/
Dependency bump for pve-common needed.


Fiona Ebner (4):
  partially fix #2077: pmgconfig: remove dependency on Term::ReadLine
  partially fix #2077: pmgcm: remove dependency on Term::ReadLine
  partially fix #2077: pmgsh: remove dependency on Term::ReadLine
  d/control: remove libterm-readline-gnu-perl dependency

 debian/control           |  1 -
 src/PMG/CLI/pmgcm.pm     |  7 ++-----
 src/PMG/CLI/pmgconfig.pm | 19 +++++++------------
 src/bin/pmgsh            | 35 ++---------------------------------
 4 files changed, 11 insertions(+), 51 deletions(-)

-- 
2.47.3



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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pmg-devel] [PATCH pmg-api 1/4] partially fix #2077: pmgconfig: remove dependency on Term::ReadLine
  2025-09-18 14:19 [pmg-devel] [PATCH-SERIES pmg-api 0/3] fix #2077: remove dependency on Term::ReadLine Fiona Ebner
@ 2025-09-18 14:19 ` Fiona Ebner
  2025-09-18 14:19 ` [pmg-devel] [PATCH pmg-api 2/4] partially fix #2077: pmgcm: " Fiona Ebner
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Fiona Ebner @ 2025-09-18 14:19 UTC (permalink / raw)
  To: pmg-devel

As a side-effect, this also fixes #6748.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PMG/CLI/pmgconfig.pm | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/src/PMG/CLI/pmgconfig.pm b/src/PMG/CLI/pmgconfig.pm
index 9f3c679..e658806 100644
--- a/src/PMG/CLI/pmgconfig.pm
+++ b/src/PMG/CLI/pmgconfig.pm
@@ -5,13 +5,12 @@ use warnings;
 use IO::File;
 use Data::Dumper;
 
-use Term::ReadLine;
-
 use PVE::SafeSyslog;
 use PVE::Tools qw(extract_param);
 use PVE::INotify;
 use PVE::CLIHandler;
 use PVE::JSONSchema qw(get_standard_option);
+use PVE::PTY;
 
 use PMG::RESTEnvironment;
 use PMG::RuleDB;
@@ -277,13 +276,12 @@ __PACKAGE__->register_method({
             }
             print $i, ") Custom\n";
 
-            my $term = Term::ReadLine->new('pmgconfig');
             my $get_dir_selection = sub {
-                my $selection = $term->readline("Enter selection: ");
+                my $selection = PVE::PTY::read_line("Enter selection: ");
                 if ($selection =~ /^(\d+)$/) {
                     $selection = $1;
                     if ($selection == $i) {
-                        $param->{directory} = $term->readline("Enter custom URL: ");
+                        $param->{directory} = PVE::PTY::read_line("Enter custom URL: ");
                         return;
                     } elsif ($selection < $i && $selection >= 0) {
                         $param->{directory} = $directories->[$selection]->{url};
@@ -307,8 +305,7 @@ __PACKAGE__->register_method({
         if ($meta->{termsOfService}) {
             my $tos = $meta->{termsOfService};
             print "Terms of Service: $tos\n";
-            my $term = Term::ReadLine->new('pmgconfig');
-            my $agreed = $term->readline('Do you agree to the above terms? [y|N]: ');
+            my $agreed = PVE::PTY::read_line('Do you agree to the above terms? [y|N]: ');
             die "Cannot continue without agreeing to ToS, aborting.\n"
                 if ($agreed !~ /^y$/i);
 
@@ -319,18 +316,16 @@ __PACKAGE__->register_method({
 
         my $eab_enabled = $meta->{externalAccountRequired};
         if (!$eab_enabled && $custom_directory) {
-            my $term = Term::ReadLine->new('pmgconfig');
             my $agreed =
-                $term->readline('Do you want to use external account binding? [y|N]: ');
+                PVE::PTY::read_line('Do you want to use external account binding? [y|N]: ');
             $eab_enabled = ($agreed =~ /^y$/i);
         } elsif ($eab_enabled) {
             print "The CA requires external account binding.\n";
         }
         if ($eab_enabled) {
             print "You should have received a key id and a key from your CA.\n";
-            my $term = Term::ReadLine->new('pmgconfig');
-            my $eab_kid = $term->readline('Enter EAB key id: ');
-            my $eab_hmac_key = $term->readline('Enter EAB key: ');
+            my $eab_kid = PVE::PTY::read_line('Enter EAB key id: ');
+            my $eab_hmac_key = PVE::PTY::read_line('Enter EAB key: ');
 
             $param->{'eab-kid'} = $eab_kid;
             $param->{'eab-hmac-key'} = $eab_hmac_key;
-- 
2.47.3



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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pmg-devel] [PATCH pmg-api 2/4] partially fix #2077: pmgcm: remove dependency on Term::ReadLine
  2025-09-18 14:19 [pmg-devel] [PATCH-SERIES pmg-api 0/3] fix #2077: remove dependency on Term::ReadLine Fiona Ebner
  2025-09-18 14:19 ` [pmg-devel] [PATCH pmg-api 1/4] partially fix #2077: pmgconfig: " Fiona Ebner
@ 2025-09-18 14:19 ` Fiona Ebner
  2025-09-18 14:19 ` [pmg-devel] [PATCH pmg-api 3/4] partially fix #2077: pmgsh: " Fiona Ebner
  2025-09-18 14:19 ` [pmg-devel] [RFC pmg-api 4/4] d/control: remove libterm-readline-gnu-perl dependency Fiona Ebner
  3 siblings, 0 replies; 7+ messages in thread
From: Fiona Ebner @ 2025-09-18 14:19 UTC (permalink / raw)
  To: pmg-devel

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PMG/CLI/pmgcm.pm | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/PMG/CLI/pmgcm.pm b/src/PMG/CLI/pmgcm.pm
index ab9fe2a..401f680 100644
--- a/src/PMG/CLI/pmgcm.pm
+++ b/src/PMG/CLI/pmgcm.pm
@@ -3,7 +3,6 @@ package PMG::CLI::pmgcm;
 use strict;
 use warnings;
 use Data::Dumper;
-use Term::ReadLine;
 use POSIX qw(strftime);
 use JSON;
 
@@ -11,6 +10,7 @@ use PVE::SafeSyslog;
 use PVE::Tools qw(extract_param);
 use PVE::INotify;
 use PVE::CLIHandler;
+use PVE::PTY;
 
 use PMG::Utils;
 use PMG::Ticket;
@@ -188,10 +188,7 @@ __PACKAGE__->register_method({
 
             die "cluster already defined\n" if scalar(keys %{ $cinfo->{ids} });
 
-            my $term = new Term::ReadLine('pmgcm');
-            my $attribs = $term->Attribs;
-            $attribs->{redisplay_function} = $attribs->{shadow_redisplay};
-            my $password = $term->readline('Enter password: ');
+            my $password = PVE::PTY::read_password('Enter password: ');
 
             my $setup = {
                 username => 'root@pam',
-- 
2.47.3



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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pmg-devel] [PATCH pmg-api 3/4] partially fix #2077: pmgsh: remove dependency on Term::ReadLine
  2025-09-18 14:19 [pmg-devel] [PATCH-SERIES pmg-api 0/3] fix #2077: remove dependency on Term::ReadLine Fiona Ebner
  2025-09-18 14:19 ` [pmg-devel] [PATCH pmg-api 1/4] partially fix #2077: pmgconfig: " Fiona Ebner
  2025-09-18 14:19 ` [pmg-devel] [PATCH pmg-api 2/4] partially fix #2077: pmgcm: " Fiona Ebner
@ 2025-09-18 14:19 ` Fiona Ebner
  2025-09-18 20:58   ` Stoiko Ivanov
  2025-09-18 14:19 ` [pmg-devel] [RFC pmg-api 4/4] d/control: remove libterm-readline-gnu-perl dependency Fiona Ebner
  3 siblings, 1 reply; 7+ messages in thread
From: Fiona Ebner @ 2025-09-18 14:19 UTC (permalink / raw)
  To: pmg-devel

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

Since this removes quite a few features, it is rather bad and it's
most likely not worth it, just to remove the dependency.

 src/bin/pmgsh | 35 ++---------------------------------
 1 file changed, 2 insertions(+), 33 deletions(-)

diff --git a/src/bin/pmgsh b/src/bin/pmgsh
index 9ef39a1..b85353d 100755
--- a/src/bin/pmgsh
+++ b/src/bin/pmgsh
@@ -2,7 +2,6 @@
 
 use strict;
 use warnings;
-use Term::ReadLine;
 use File::Basename;
 use Getopt::Long;
 use HTTP::Status qw(:constants :is status_message);
@@ -12,6 +11,7 @@ use PVE::JSONSchema;
 use PVE::SafeSyslog;
 use PVE::INotify;
 use PVE::CLIHandler;
+use PVE::PTY;
 
 use PMG::RESTEnvironment;
 
@@ -82,9 +82,6 @@ initlog($ENV{PVE_LOG_ID} || 'pmgsh');
 
 print "entering PMG shell - type 'help' for help\n";
 
-my $term = new Term::ReadLine('pmgsh');
-my $attribs = $term->Attribs;
-
 sub complete_path {
     my ($text) = @_;
 
@@ -130,28 +127,6 @@ sub complete_path {
     return ($lcd, @res);
 }
 
-# just to avoid an endless loop (called by attempted_completion_function)
-$attribs->{completion_entry_function} = sub {
-    my ($text, $state) = @_;
-    return undef;
-};
-
-$attribs->{attempted_completion_function} = sub {
-    my ($text, $line, $start) = @_;
-
-    my $prefix = substr($line, 0, $start);
-    if ($prefix =~ /^\s*$/) { # first word (command completion)
-        $attribs->{completion_word} = [qw(help ls cd get set create delete quit)];
-        return $term->completion_matches($text, $attribs->{list_completion_function});
-    }
-
-    if ($prefix =~ /^\s*\S+\s+$/) { # second word (path completion)
-        return complete_path($text);
-    }
-
-    return ();
-};
-
 sub abs_path {
     my ($current, $path) = @_;
 
@@ -539,7 +514,7 @@ sub pmg_command {
 }
 
 my $input;
-while (defined($input = $term->readline("pmg:/$cdir> "))) {
+while (defined($input = PVE::PTY::read_line("pmg:/$cdir> "))) {
     chomp $input;
 
     next if $input =~ m/^\s*$/;
@@ -548,12 +523,6 @@ while (defined($input = $term->readline("pmg:/$cdir> "))) {
         exit(0);
     }
 
-    # add input to history if it gets not
-    # automatically added
-    if (!$term->Features->{autohistory}) {
-        $term->addhistory($input);
-    }
-
     eval {
         my $args = [shellwords($input)];
         pmg_command($args);
-- 
2.47.3



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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pmg-devel] [RFC pmg-api 4/4] d/control: remove libterm-readline-gnu-perl dependency
  2025-09-18 14:19 [pmg-devel] [PATCH-SERIES pmg-api 0/3] fix #2077: remove dependency on Term::ReadLine Fiona Ebner
                   ` (2 preceding siblings ...)
  2025-09-18 14:19 ` [pmg-devel] [PATCH pmg-api 3/4] partially fix #2077: pmgsh: " Fiona Ebner
@ 2025-09-18 14:19 ` Fiona Ebner
  3 siblings, 0 replies; 7+ messages in thread
From: Fiona Ebner @ 2025-09-18 14:19 UTC (permalink / raw)
  To: pmg-devel

No usage remains.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 debian/control | 1 -
 1 file changed, 1 deletion(-)

diff --git a/debian/control b/debian/control
index d8e1520..86dd180 100644
--- a/debian/control
+++ b/debian/control
@@ -79,7 +79,6 @@ Depends: apt (>= 2~),
          libpve-http-server-perl (>= 5.1.1),
          librrds-perl,
          libtemplate-perl,
-         libterm-readline-gnu-perl,
          libxdgmime-perl,
          openssh-client,
          openssh-server,
-- 
2.47.3



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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [pmg-devel] [PATCH pmg-api 3/4] partially fix #2077: pmgsh: remove dependency on Term::ReadLine
  2025-09-18 14:19 ` [pmg-devel] [PATCH pmg-api 3/4] partially fix #2077: pmgsh: " Fiona Ebner
@ 2025-09-18 20:58   ` Stoiko Ivanov
  2025-09-19  8:41     ` Fiona Ebner
  0 siblings, 1 reply; 7+ messages in thread
From: Stoiko Ivanov @ 2025-09-18 20:58 UTC (permalink / raw)
  To: Fiona Ebner; +Cc: pmg-devel

Thanks for tackling this!

applied the patch for pve-common and played around a bit with pmgsh - and
yes - I did miss the completion (not the history though.. and am not sure
if I overlooked some other readline feature that would be lost)

but this reminded me of pvesh and that we dropped interactive mode at some
point (around PVE 5.2) there:
https://git.proxmox.com/?p=pve-manager.git;a=commitdiff;h=cfc6a662938b90069e6c70b8112021a4554bad27
and the rationale of using bash for completion (still) sounds sensible.

did not look closer at what pmgsh is still missing from pvesh (the latter
saw quite a bit more changes in the past years) - but currently this seems
to be a good alternative.
(I'm not sure if I'll get to checking this in the upcoming 1-2 weeks, but
could try if you are busy elsewhere and noone else steps up)

FWIW - tried registering an acme account (patch 1/4) - also worked fine.



On Thu, 18 Sep 2025 16:19:43 +0200
Fiona Ebner <f.ebner@proxmox.com> wrote:

> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
> ---
> 
> Since this removes quite a few features, it is rather bad and it's
> most likely not worth it, just to remove the dependency.
> 
>  src/bin/pmgsh | 35 ++---------------------------------
>  1 file changed, 2 insertions(+), 33 deletions(-)
> 
> diff --git a/src/bin/pmgsh b/src/bin/pmgsh
> index 9ef39a1..b85353d 100755
> --- a/src/bin/pmgsh
> +++ b/src/bin/pmgsh
> @@ -2,7 +2,6 @@
>  
>  use strict;
>  use warnings;
> -use Term::ReadLine;
>  use File::Basename;
>  use Getopt::Long;
>  use HTTP::Status qw(:constants :is status_message);
> @@ -12,6 +11,7 @@ use PVE::JSONSchema;
>  use PVE::SafeSyslog;
>  use PVE::INotify;
>  use PVE::CLIHandler;
> +use PVE::PTY;
>  
>  use PMG::RESTEnvironment;
>  
> @@ -82,9 +82,6 @@ initlog($ENV{PVE_LOG_ID} || 'pmgsh');
>  
>  print "entering PMG shell - type 'help' for help\n";
>  
> -my $term = new Term::ReadLine('pmgsh');
> -my $attribs = $term->Attribs;
> -
>  sub complete_path {
>      my ($text) = @_;
>  
> @@ -130,28 +127,6 @@ sub complete_path {
>      return ($lcd, @res);
>  }
>  
> -# just to avoid an endless loop (called by attempted_completion_function)
> -$attribs->{completion_entry_function} = sub {
> -    my ($text, $state) = @_;
> -    return undef;
> -};
> -
> -$attribs->{attempted_completion_function} = sub {
> -    my ($text, $line, $start) = @_;
> -
> -    my $prefix = substr($line, 0, $start);
> -    if ($prefix =~ /^\s*$/) { # first word (command completion)
> -        $attribs->{completion_word} = [qw(help ls cd get set create delete quit)];
> -        return $term->completion_matches($text, $attribs->{list_completion_function});
> -    }
> -
> -    if ($prefix =~ /^\s*\S+\s+$/) { # second word (path completion)
> -        return complete_path($text);
> -    }
> -
> -    return ();
> -};
> -
>  sub abs_path {
>      my ($current, $path) = @_;
>  
> @@ -539,7 +514,7 @@ sub pmg_command {
>  }
>  
>  my $input;
> -while (defined($input = $term->readline("pmg:/$cdir> "))) {
> +while (defined($input = PVE::PTY::read_line("pmg:/$cdir> "))) {
>      chomp $input;
>  
>      next if $input =~ m/^\s*$/;
> @@ -548,12 +523,6 @@ while (defined($input = $term->readline("pmg:/$cdir> "))) {
>          exit(0);
>      }
>  
> -    # add input to history if it gets not
> -    # automatically added
> -    if (!$term->Features->{autohistory}) {
> -        $term->addhistory($input);
> -    }
> -
>      eval {
>          my $args = [shellwords($input)];
>          pmg_command($args);



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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [pmg-devel] [PATCH pmg-api 3/4] partially fix #2077: pmgsh: remove dependency on Term::ReadLine
  2025-09-18 20:58   ` Stoiko Ivanov
@ 2025-09-19  8:41     ` Fiona Ebner
  0 siblings, 0 replies; 7+ messages in thread
From: Fiona Ebner @ 2025-09-19  8:41 UTC (permalink / raw)
  To: Stoiko Ivanov; +Cc: pmg-devel

Am 18.09.25 um 10:58 PM schrieb Stoiko Ivanov:
> Thanks for tackling this!
> 
> applied the patch for pve-common and played around a bit with pmgsh - and
> yes - I did miss the completion (not the history though.. and am not sure
> if I overlooked some other readline feature that would be lost)
> 
> but this reminded me of pvesh and that we dropped interactive mode at some
> point (around PVE 5.2) there:
> https://git.proxmox.com/?p=pve-manager.git;a=commitdiff;h=cfc6a662938b90069e6c70b8112021a4554bad27
> and the rationale of using bash for completion (still) sounds sensible.

Oh, that dropped the REPL-style interface completely. If we do want to
go ahead with dropping Term::ReadLine for pmgsh, I think we should do
that here too.

> did not look closer at what pmgsh is still missing from pvesh (the latter
> saw quite a bit more changes in the past years) - but currently this seems
> to be a good alternative.
> (I'm not sure if I'll get to checking this in the upcoming 1-2 weeks, but
> could try if you are busy elsewhere and noone else steps up)

Do you have an example for what (potential) features you have in mind
here? Or just looking through all pvesh changes and see what would be
nice to have for pmgsh too?

> FWIW - tried registering an acme account (patch 1/4) - also worked fine.

Would you mind adding a T-b there :)?


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-09-19  8:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-18 14:19 [pmg-devel] [PATCH-SERIES pmg-api 0/3] fix #2077: remove dependency on Term::ReadLine Fiona Ebner
2025-09-18 14:19 ` [pmg-devel] [PATCH pmg-api 1/4] partially fix #2077: pmgconfig: " Fiona Ebner
2025-09-18 14:19 ` [pmg-devel] [PATCH pmg-api 2/4] partially fix #2077: pmgcm: " Fiona Ebner
2025-09-18 14:19 ` [pmg-devel] [PATCH pmg-api 3/4] partially fix #2077: pmgsh: " Fiona Ebner
2025-09-18 20:58   ` Stoiko Ivanov
2025-09-19  8:41     ` Fiona Ebner
2025-09-18 14:19 ` [pmg-devel] [RFC pmg-api 4/4] d/control: remove libterm-readline-gnu-perl dependency Fiona Ebner

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