mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Merge pull request #4058 from Vane11ope/vane11ope/fix
List was not cycled right for tab auto-completion
This commit is contained in:
commit
65318603ae
@ -28,15 +28,17 @@ class ListCompleter(Completer):
|
|||||||
if o.startswith(start):
|
if o.startswith(start):
|
||||||
self.options.append(o)
|
self.options.append(o)
|
||||||
self.options.sort()
|
self.options.sort()
|
||||||
self.offset = 0
|
self.pos = -1
|
||||||
|
|
||||||
def cycle(self, forward: bool = True) -> str:
|
def cycle(self, forward: bool = True) -> str:
|
||||||
if not self.options:
|
if not self.options:
|
||||||
return self.start
|
return self.start
|
||||||
ret = self.options[self.offset]
|
if self.pos == -1:
|
||||||
delta = 1 if forward else -1
|
self.pos = 0 if forward else len(self.options) - 1
|
||||||
self.offset = (self.offset + delta) % len(self.options)
|
else:
|
||||||
return ret
|
delta = 1 if forward else -1
|
||||||
|
self.pos = (self.pos + delta) % len(self.options)
|
||||||
|
return self.options[self.pos]
|
||||||
|
|
||||||
|
|
||||||
class CompletionState(typing.NamedTuple):
|
class CompletionState(typing.NamedTuple):
|
||||||
|
@ -31,23 +31,35 @@ class TestListCompleter:
|
|||||||
[
|
[
|
||||||
"",
|
"",
|
||||||
["a", "b", "c"],
|
["a", "b", "c"],
|
||||||
["a", "b", "c", "a"]
|
["a", "b", "c", "a"],
|
||||||
|
["c", "b", "a", "c"],
|
||||||
|
["a", "c", "a", "c"]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"xxx",
|
"xxx",
|
||||||
["a", "b", "c"],
|
["a", "b", "c"],
|
||||||
|
["xxx", "xxx", "xxx"],
|
||||||
|
["xxx", "xxx", "xxx"],
|
||||||
["xxx", "xxx", "xxx"]
|
["xxx", "xxx", "xxx"]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"b",
|
"b",
|
||||||
["a", "b", "ba", "bb", "c"],
|
["a", "b", "ba", "bb", "c"],
|
||||||
["b", "ba", "bb", "b"]
|
["b", "ba", "bb", "b"],
|
||||||
|
["bb", "ba", "b", "bb"],
|
||||||
|
["b", "bb", "b", "bb"]
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
for start, opts, cycle in tests:
|
for start, opts, cycle, cycle_reverse, cycle_mix in tests:
|
||||||
c = commander.ListCompleter(start, opts)
|
c = commander.ListCompleter(start, opts)
|
||||||
for expected in cycle:
|
for expected in cycle:
|
||||||
assert c.cycle() == expected
|
assert c.cycle() == expected
|
||||||
|
for expected in cycle_reverse:
|
||||||
|
assert c.cycle(False) == expected
|
||||||
|
forward = True
|
||||||
|
for expected in cycle_mix:
|
||||||
|
assert c.cycle(forward) == expected
|
||||||
|
forward = not forward
|
||||||
|
|
||||||
|
|
||||||
class TestCommandEdit:
|
class TestCommandEdit:
|
||||||
|
Loading…
Reference in New Issue
Block a user