Merge pull request #2686 from cortesi/flowspecopts

commander: add completion for flowspecs
This commit is contained in:
Aldo Cortesi 2017-12-17 11:23:20 +13:00 committed by GitHub
commit 1f6656ccb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -24,6 +24,32 @@ def lexer(s):
return lex
# This is an awkward location for these values, but it's better than having
# the console core import and depend on an addon. FIXME: Add a way for
# addons to add custom types and manage their completion and validation.
valid_flow_prefixes = [
"@all",
"@focus",
"@shown",
"@hidden",
"@marked",
"@unmarked",
"~q",
"~s",
"~a",
"~hq",
"~hs",
"~b",
"~bq",
"~bs",
"~t",
"~d",
"~m",
"~u",
"~c",
]
Cuts = typing.Sequence[
typing.Sequence[typing.Union[str, bytes]]
]

View File

@ -6,6 +6,7 @@ import typing
import urwid
from urwid.text_layout import calc_coords
import mitmproxy.flow
import mitmproxy.master
import mitmproxy.command
@ -142,7 +143,14 @@ class CommandBuffer():
),
parse = parts,
)
elif last.type in (typing.Sequence[mitmproxy.flow.Flow], mitmproxy.flow.Flow):
self.completion = CompletionState(
completer = ListCompleter(
"",
mitmproxy.command.valid_flow_prefixes,
),
parse = parts,
)
if self.completion:
nxt = self.completion.completer.cycle()
buf = " ".join([i.value for i in self.completion.parse[:-1]]) + " " + nxt