From 5c0a56c4f3997da8fe08cba8343cf23e7ccf6899 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Sun, 30 Jul 2017 13:45:42 +0000 Subject: tlmgr shell: add "set prompt" support git-svn-id: svn://tug.org/texlive/trunk@44922 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/scripts/texlive/tlmgr.pl | 42 ++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'Master/texmf-dist') diff --git a/Master/texmf-dist/scripts/texlive/tlmgr.pl b/Master/texmf-dist/scripts/texlive/tlmgr.pl index 59fad25caf1..8c0a171bf29 100755 --- a/Master/texmf-dist/scripts/texlive/tlmgr.pl +++ b/Master/texmf-dist/scripts/texlive/tlmgr.pl @@ -5867,8 +5867,12 @@ sub action_key { # sub action_shell { my $protocol = 1; - sub do_prompt { - my $default_prompt = "tlmgr>"; + my $default_prompt = "tlmgr>"; + # we need to do an anonymous sub here otherwise the $default_prompt will get + # only fixed once and remain forever. With anonymous subs it is rebound + # on every call! + my $do_prompt; + $do_prompt = sub { my $prompt = ""; my @options; my @guarantee; @@ -5897,7 +5901,7 @@ sub action_shell { $did_prompt = 1; } } - print "default_prompt " if (!$did_prompt); + print "$default_prompt " if (!$did_prompt); my $ans = ; if (!defined($ans)) { # we got Ctrl-D, just break out @@ -5923,15 +5927,15 @@ sub action_shell { } if (!$isok) { print("Please answer one of: @guarantee\n"); - return(do_prompt(@savedargs)); + return(&$do_prompt(@savedargs)); } } return($ans); - } + }; print "protocol $protocol\n"; while (1) { - my $ans = do_prompt('tlmgr>'); + my $ans = &$do_prompt($default_prompt); return $F_OK if !defined($ans); # done if eof my ($cmd, @args) = TeXLive::TLUtils::quotewords('\s+', 0, $ans); @@ -5954,13 +5958,13 @@ sub action_shell { my @valid_bool_keys = qw/debug-translation machine-readable no-execute-actions require-verification verify-downloads/; - my @valid_string_keys = qw/repository/; + my @valid_string_keys = qw/repository prompt/; my @valid_keys = (@valid_bool_keys, @valid_string_keys); # my $key = shift @args; my $val = shift @args; if (!$key) { - $key = do_prompt('Choose one of...', -menu => \@valid_keys, '>'); + $key = &$do_prompt('Choose one of...', -menu => \@valid_keys, '>'); } if (!$key) { print("ERROR missing key argument for get/set\n"); @@ -5972,9 +5976,11 @@ sub action_shell { } if ($cmd eq "set" && !defined($val)) { if ($key eq "repository") { - $val = do_prompt('Enter repository:'); + $val = &$do_prompt('Enter repository:'); + } elsif ($key eq "prompt") { + $val = &$do_prompt('Enter new prompt:'); } else { - $val = do_prompt('Enter 1 for on, 0 for off:', -guarantee => [0,1]); + $val = &$do_prompt('Enter 1 for on, 0 for off:', -guarantee => [0,1]); } # deal with Ctrl-D if (!defined($val)) { @@ -5994,6 +6000,13 @@ sub action_shell { } } print "OK\n"; + } elsif ($key eq "prompt") { + if ($cmd eq "set") { + $default_prompt = scalar($val); + } else { + print "Current prompt: $default_prompt (but you know that, or?)\n"; + } + print "OK\n"; } elsif (TeXLive::TLUtils::member($key, @valid_bool_keys)) { if ($cmd eq "set") { if ($val eq "0") { @@ -6018,7 +6031,7 @@ sub action_shell { } elsif ($cmd eq "load") { my $what = shift @args; if (!defined($what)) { - $what = do_prompt("Choose...", -menu => ['local', 'remote'], '>'); + $what = &$do_prompt("Choose...", -menu => ['local', 'remote'], '>'); } if ($what eq "local") { init_local_db(); @@ -8007,10 +8020,11 @@ Save the local TLPDB, presumably after other operations have changed it. Get the value of I, or set it to I. Possible I names: C, C, C, -C, C, and C. All -except C are booleans, taking values 0 and 1, and behave +C, C, C, and C. All +except C and C are booleans, taking values 0 and 1, and behave like the corresponding command line option. The C variable -takes a string, and sets the remote repository location. +takes a string, and sets the remote repository location. The C variable +takes a string, and sets the current default prompt. If I or then I is not specified, it is prompted for. -- cgit v1.2.3