From a32afb867640e8c55302b742b46974da71c7d87c Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 15 Feb 2021 01:53:15 -0700 Subject: [PATCH] projtool/usertool: prohibit pager for interactive commands Certain commands must never start a pager regardless of any options that may have been given or the "terminal"ness of standard output. Interactive input simply does not work properly when standard output is a pipe to a pager. Inhibit use of a pager whenever interactive commands are used. Signed-off-by: Kyle J. McKay --- toolbox/projtool.pl | 12 +++++++++++- toolbox/usertool.pl | 10 +++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/toolbox/projtool.pl b/toolbox/projtool.pl index 89befcf..a717e65 100755 --- a/toolbox/projtool.pl +++ b/toolbox/projtool.pl @@ -1945,10 +1945,19 @@ BEGIN { set => \&cmd_set, ); } +our %nopager; +BEGIN { + %nopager = map({$_ => 1} qw( + create + chpass + checkpw + )); +} sub dohelp { my $cmd = shift; my $bn = basename($0); + setup_pager_stdout($usepager); printf "%s version %s\n\n", $bn, $VERSION; if (defined($cmd) && $cmd ne '') { $cmd =~ s/^set(?=[a-zA-Z])//i; @@ -1974,7 +1983,6 @@ sub main { shift, $usepager=1, redo if @ARGV && $ARGV[0] =~ /^(?:-p|--pager|--paginate)$/i; shift, $usepager=0, redo if @ARGV && $ARGV[0] =~ /^(?:--no-pager|--no-paginate)$/i; } - setup_pager_stdout($usepager); dohelp($ARGV[1]) if !@ARGV || @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i; my $command = shift; diename($command); @@ -1986,5 +1994,7 @@ sub main { exists($commands{$command}) or die "Unknown command \"$command\" -- try \"help\"\n"; dohelp($command) if @ARGV && ($ARGV[0] =~ /^(?:-h|-?-help)$/i || $ARGV[0] =~ /^help$/i && !Girocco::Project::does_exist("help",1)); + $nopager{$command} and $usepager = 0; + setup_pager_stdout($usepager); &{$commands{$command}}(@ARGV); } diff --git a/toolbox/usertool.pl b/toolbox/usertool.pl index 9dd32e9..634dc22 100755 --- a/toolbox/usertool.pl +++ b/toolbox/usertool.pl @@ -631,10 +631,17 @@ BEGIN { set => \&cmd_set, ); } +our %nopager; +BEGIN { + %nopager = map({$_ => 1} qw( + create + )); +} sub dohelp { my $cmd = shift; my $bn = basename($0); + setup_pager_stdout($usepager); printf "%s version %s\n\n", $bn, $VERSION; if (defined($cmd) && $cmd ne '') { $cmd =~ s/^set(?=[a-zA-Z])//i; @@ -660,7 +667,6 @@ sub main { shift, $usepager=1, redo if @ARGV && $ARGV[0] =~ /^(?:-p|--pager|--paginate)$/i; shift, $usepager=0, redo if @ARGV && $ARGV[0] =~ /^(?:--no-pager|--no-paginate)$/i; } - setup_pager_stdout($usepager); dohelp($ARGV[1]) if !@ARGV || @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i; my $command = shift; diename($command); @@ -672,5 +678,7 @@ sub main { exists($commands{$command}) or die "Unknown command \"$command\" -- try \"help\"\n"; dohelp($command) if @ARGV && ($ARGV[0] =~ /^(?:-h|-?-help)$/i || $ARGV[0] =~ /^help$/i && !Girocco::User::does_exist("help",1)); + $nopager{$command} and $usepager = 0; + setup_pager_stdout($usepager); &{$commands{$command}}(@ARGV); } -- 2.11.4.GIT