Autocompletion fixed. parse_partial refactoring. New lexer state.

This commit is contained in:
Miroslav 2018-06-08 02:50:51 +03:00
parent cb5c492c88
commit 0330b30160
2 changed files with 11 additions and 9 deletions

View file

@ -155,20 +155,22 @@ class CommandManager(mitmproxy.types._CommandBase):
parts: typing.List[str] = lexer.get_tokens(cmdstr)
if not parts:
parts = [""]
elif cmdstr.endswith(" "):
parts.append("")
parse: typing.List[ParseResult] = []
params: typing.List[type] = []
typ: typing.Type = None
for i in range(len(parts)):
for i, part in enumerate(parts):
if i == 0:
typ = mitmproxy.types.Cmd
if parts[i] in self.commands:
params.extend(self.commands[parts[i]].paramtypes)
elif params and not parts[i].isspace():
if part in self.commands:
params.extend(self.commands[part].paramtypes)
elif params and not part.isspace():
typ = params.pop(0)
if typ == mitmproxy.types.Cmd and params and params[0] == mitmproxy.types.Arg:
if parts[i] in self.commands:
params[:] = self.commands[parts[i]].paramtypes
if part in self.commands:
params[:] = self.commands[part].paramtypes
else:
typ = mitmproxy.types.Unknown
@ -176,7 +178,7 @@ class CommandManager(mitmproxy.types._CommandBase):
valid = False
if to:
try:
to.parse(self, typ, parts[i])
to.parse(self, typ, part)
except exceptions.TypeError:
valid = False
else:
@ -184,7 +186,7 @@ class CommandManager(mitmproxy.types._CommandBase):
parse.append(
ParseResult(
value=parts[i],
value=part,
type=typ,
valid=valid,
)

View file

@ -141,7 +141,7 @@ class CommandBuffer:
)
if self.completion:
nxt = self.completion.completer.cycle()
buf = "".join([i.value for i in self.completion.parse[:-1]]) + "" + nxt
buf = "".join([i.value for i in self.completion.parse[:-1]]) + nxt
buf = buf.strip()
self.text = self.flatten(buf)
self.cursor = len(self.text)