diff options
author | Andy Grover <agrover@redhat.com> | 2014-01-06 11:59:38 -0800 |
---|---|---|
committer | Andy Grover <agrover@redhat.com> | 2014-01-06 11:59:38 -0800 |
commit | 95dcb55f55c8bfc3a2fa0e4b74b4ea234c4a2da2 (patch) | |
tree | 63def0ef37269c5509a8dbd94108b6c953f4af5c | |
parent | 3b36cd8734799812140edb341902bfe7081be233 (diff) | |
download | configshell-fb-95dcb55f55c8bfc3a2fa0e4b74b4ea234c4a2da2.tar.gz |
Re-enable hack for tab-completion with nothing under the cursor
A very nice behavior is having <tab><tab> bring up options for the next
expected commandline token when nothing is underneath the cursor. There was
a workaround to get this working with the simpleparse parser, and we need
a different workaround for it to work with pyparsing.
This keeps the same technique of adding a bogus input and seeing what the
parser would categorize it as, and then setting current_token based on
that.
We also ensure current_token is defined. Without this, the call to
_dispatch_completion fails with a NameError but somebody catches the
error so things just silently don't work, without the debug msg in
_dispatch_completion for unknown current_token ever printing.
Signed-off-by: Andy Grover <agrover@redhat.com>
-rw-r--r-- | configshell/shell.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/configshell/shell.py b/configshell/shell.py index 4349f50..878d24a 100644 --- a/configshell/shell.py +++ b/configshell/shell.py @@ -638,14 +638,20 @@ class ConfigShell(object): beg = readline.get_begidx() end = readline.get_endidx() + current_token = None if beg == end: # No text under the cursor, fake it so that the parser # result_trees gives us a token name on a second parser call self.log.debug("Faking text entry on commandline.") parse_results = self._parse_cmdline(cmdline + 'x')[0] - end += 1 - if path and beg == parse_results.path.location: + if parse_results.command.value == 'x': + current_token = 'command' + elif 'x' in [x.value for x in parse_results.pparams]: + current_token = 'pparam' + elif 'x' in [x.value for x in parse_results.kparams]: + current_token = 'kparam' + elif path and beg == parse_results.path.location: current_token = 'path' elif command and beg == parse_results.command.location: current_token = 'command' |