Clean up and temporarily disable alias completion.

Fixes #358.
This commit is contained in:
Florian Bruhin 2014-12-28 22:08:38 +01:00
parent 6089d4a636
commit b703028411
2 changed files with 7 additions and 13 deletions

View File

@ -166,12 +166,11 @@ class CommandRunner(QObject):
self._args = [] self._args = []
self._win_id = win_id self._win_id = win_id
def _get_alias(self, text, alias_no_args): def _get_alias(self, text):
"""Get an alias from the config. """Get an alias from the config.
Args: Args:
text: The text to parse. text: The text to parse.
alias_no_args: Whether to apply an alias if there are no arguments.
Return: Return:
None if no alias was found. None if no alias was found.
@ -185,16 +184,12 @@ class CommandRunner(QObject):
try: try:
new_cmd = '{} {}'.format(alias, parts[1]) new_cmd = '{} {}'.format(alias, parts[1])
except IndexError: except IndexError:
if alias_no_args:
new_cmd = alias new_cmd = alias
else:
new_cmd = parts[0]
if text.endswith(' '): if text.endswith(' '):
new_cmd += ' ' new_cmd += ' '
return new_cmd return new_cmd
def parse(self, text, aliases=True, fallback=False, alias_no_args=True, def parse(self, text, aliases=True, fallback=False, keep=False):
keep=False):
"""Split the commandline text into command and arguments. """Split the commandline text into command and arguments.
Args: Args:
@ -202,7 +197,6 @@ class CommandRunner(QObject):
aliases: Whether to handle aliases. aliases: Whether to handle aliases.
fallback: Whether to do a fallback splitting when the command was fallback: Whether to do a fallback splitting when the command was
unknown. unknown.
alias_no_args: Whether to apply an alias if there are no arguments.
keep: Whether to keep special chars and whitespace keep: Whether to keep special chars and whitespace
Return: Return:
@ -212,7 +206,7 @@ class CommandRunner(QObject):
if not cmdstr and not fallback: if not cmdstr and not fallback:
raise cmdexc.NoSuchCommandError("No command given") raise cmdexc.NoSuchCommandError("No command given")
if aliases: if aliases:
new_cmd = self._get_alias(text, alias_no_args) new_cmd = self._get_alias(text)
if new_cmd is not None: if new_cmd is not None:
log.commands.debug("Re-parsing with '{}'.".format(new_cmd)) log.commands.debug("Re-parsing with '{}'.".format(new_cmd))
return self.parse(new_cmd, aliases=False, fallback=fallback, return self.parse(new_cmd, aliases=False, fallback=fallback,

View File

@ -326,11 +326,12 @@ class Completer(QObject):
if completion.enabled: if completion.enabled:
completion.show() completion.show()
def split(self, keep=False): def split(self, keep=False, aliases=False):
"""Get the text split up in parts. """Get the text split up in parts.
Args: Args:
keep: Whether to keep special chars and whitespace. keep: Whether to keep special chars and whitespace.
aliases: Whether to resolve aliases.
""" """
text = self._cmd.text()[len(self._cmd.prefix()):] text = self._cmd.text()[len(self._cmd.prefix()):]
if not text: if not text:
@ -342,8 +343,7 @@ class Completer(QObject):
# the whitespace. # the whitespace.
return [text] return [text]
runner = runners.CommandRunner(self._win_id) runner = runners.CommandRunner(self._win_id)
parts = runner.parse(text, fallback=True, alias_no_args=False, parts = runner.parse(text, fallback=True, aliases=aliases, keep=keep)
keep=keep)
if self._empty_item_idx is not None: if self._empty_item_idx is not None:
log.completion.debug("Empty element queued at {}, " log.completion.debug("Empty element queued at {}, "
"inserting.".format(self._empty_item_idx)) "inserting.".format(self._empty_item_idx))