summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-08-07 20:30:06 -0400
committerGitHub <noreply@github.com>2019-08-07 20:30:06 -0400
commit933e328c04dcaf842c5fc8b536879902cbc11bea (patch)
tree8af2ef1f3bd3d73f1116bbe88b886aae67b13230 /cmd2/cmd2.py
parent021ae36f61c1f17e18153b2f1435e895b88a39fc (diff)
parentcc3d5cd210902e899ee34cd4f71c344fdc075ecb (diff)
downloadcmd2-git-933e328c04dcaf842c5fc8b536879902cbc11bea.tar.gz
Merge branch 'master' into verify_command_names
Diffstat (limited to 'cmd2/cmd2.py')
-rwxr-xr-xcmd2/cmd2.py44
1 files changed, 40 insertions, 4 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index f29fc517..4a5c506d 100755
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -690,7 +690,7 @@ class Cmd(cmd.Cmd):
final_msg = ansi.style_error(final_msg)
if not self.debug:
- warning = "\nTo enable full traceback, run the following command: 'set debug true'"
+ warning = "\nTo enable full traceback, run the following command: 'set debug true'"
final_msg += ansi.style_warning(warning)
# Set apply_style to False since style has already been applied
@@ -2896,6 +2896,28 @@ class Cmd(cmd.Cmd):
| a list of tuples -> interpreted as (value, text), so
that the return value can differ from
the text advertised to the user """
+
+ completion_disabled = False
+ orig_completer = None
+
+ def disable_completion():
+ """Turn off completion during the select input line"""
+ nonlocal orig_completer
+ nonlocal completion_disabled
+
+ if rl_type != RlType.NONE and not completion_disabled:
+ orig_completer = readline.get_completer()
+ readline.set_completer(lambda *args, **kwargs: None)
+ completion_disabled = True
+
+ def enable_completion():
+ """Restore tab completion when select is done reading input"""
+ nonlocal completion_disabled
+
+ if rl_type != RlType.NONE and completion_disabled:
+ readline.set_completer(orig_completer)
+ completion_disabled = False
+
local_opts = opts
if isinstance(opts, str):
local_opts = list(zip(opts.split(), opts.split()))
@@ -2910,15 +2932,28 @@ class Cmd(cmd.Cmd):
fulloptions.append((opt[0], opt[0]))
for (idx, (_, text)) in enumerate(fulloptions):
self.poutput(' %2d. %s' % (idx + 1, text))
+
while True:
safe_prompt = rl_make_safe_prompt(prompt)
- response = input(safe_prompt)
+
+ try:
+ with self.sigint_protection:
+ disable_completion()
+ response = input(safe_prompt)
+ except EOFError:
+ response = ''
+ self.poutput('\n', end='')
+ finally:
+ with self.sigint_protection:
+ enable_completion()
+
+ if not response:
+ continue
if rl_type != RlType.NONE:
hlen = readline.get_current_history_length()
- if hlen >= 1 and response != '':
+ if hlen >= 1:
readline.remove_history_item(hlen - 1)
-
try:
choice = int(response)
if choice < 1:
@@ -2928,6 +2963,7 @@ class Cmd(cmd.Cmd):
except (ValueError, IndexError):
self.poutput("{!r} isn't a valid choice. Pick a number between 1 and {}:".format(
response, len(fulloptions)))
+
return result
def _get_read_only_settings(self) -> str: