mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Merge branch 'mitmproxy-improve-commander' of github.com:typoon/mitmproxy into command-history-file
This commit is contained in:
commit
8fbd0bb9ce
@ -67,6 +67,11 @@ class CommandBuffer:
|
|||||||
else:
|
else:
|
||||||
self._cursor = x
|
self._cursor = x
|
||||||
|
|
||||||
|
def set_text(self, text: str) -> None:
|
||||||
|
self.text = text
|
||||||
|
self._cursor = len(self.text)
|
||||||
|
self.render()
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
parts, remaining = self.master.commands.parse_partial(self.text)
|
parts, remaining = self.master.commands.parse_partial(self.text)
|
||||||
ret = []
|
ret = []
|
||||||
@ -133,6 +138,12 @@ class CommandBuffer:
|
|||||||
self.cursor = self.cursor - 1
|
self.cursor = self.cursor - 1
|
||||||
self.completion = None
|
self.completion = None
|
||||||
|
|
||||||
|
def delete(self) -> None:
|
||||||
|
if self.cursor == len(self.text):
|
||||||
|
return
|
||||||
|
self.text = self.text[:self.cursor] + self.text[self.cursor + 1:]
|
||||||
|
self.completion = None
|
||||||
|
|
||||||
def insert(self, k: str) -> None:
|
def insert(self, k: str) -> None:
|
||||||
"""
|
"""
|
||||||
Inserts text at the cursor.
|
Inserts text at the cursor.
|
||||||
@ -159,26 +170,51 @@ class CommandEdit(urwid.WidgetWrap):
|
|||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def keypress(self, size, key) -> None:
|
def keypress(self, size, key) -> None:
|
||||||
if key == "backspace":
|
if key == "delete":
|
||||||
|
self.cbuf.delete()
|
||||||
|
elif key == "ctrl a" or key == 'home':
|
||||||
|
self.cbuf.cursor = 0
|
||||||
|
elif key == "ctrl e" or key == 'end':
|
||||||
|
self.cbuf.cursor = len(self.cbuf.text)
|
||||||
|
elif key == "meta b":
|
||||||
|
self.cbuf.cursor = self.cbuf.text.rfind(' ', 0, self.cbuf.cursor)
|
||||||
|
elif key == "meta f":
|
||||||
|
pos = self.cbuf.text.find(' ', self.cbuf.cursor + 1)
|
||||||
|
if pos == -1:
|
||||||
|
pos = len(self.cbuf.text)
|
||||||
|
self.cbuf.cursor = pos
|
||||||
|
elif key == "ctrl w":
|
||||||
|
prev_cursor = self.cbuf.cursor
|
||||||
|
pos = self.cbuf.text.rfind(' ', 0, self.cbuf.cursor - 1)
|
||||||
|
if pos == -1:
|
||||||
|
new_text = self.cbuf.text[self.cbuf.cursor:]
|
||||||
|
cursor_pos = 0
|
||||||
|
else:
|
||||||
|
txt_after = self.cbuf.text[self.cbuf.cursor:]
|
||||||
|
txt_before = self.cbuf.text[0:pos]
|
||||||
|
new_text = f"{txt_before} {txt_after}"
|
||||||
|
cursor_pos = prev_cursor - (prev_cursor - pos) + 1
|
||||||
|
self.cbuf.set_text(new_text)
|
||||||
|
self.cbuf.cursor = cursor_pos
|
||||||
|
elif key == "backspace":
|
||||||
self.cbuf.backspace()
|
self.cbuf.backspace()
|
||||||
if self.cbuf.text == '':
|
if self.cbuf.text == '':
|
||||||
self.active_filter = False
|
self.active_filter = False
|
||||||
self.master.commands.execute("command_history.filter ''")
|
self.master.commands.execute("command_history.filter ''")
|
||||||
self.filter_str = ''
|
self.filter_str = ''
|
||||||
elif key == "left":
|
elif key == "left" or key == "ctrl b":
|
||||||
self.cbuf.left()
|
self.cbuf.left()
|
||||||
elif key == "right":
|
elif key == "right" or key == "ctrl f":
|
||||||
self.cbuf.right()
|
self.cbuf.right()
|
||||||
elif key == "up":
|
elif key == "up" or key == "ctrl p":
|
||||||
if self.active_filter is False:
|
if self.active_filter is False:
|
||||||
self.active_filter = True
|
self.active_filter = True
|
||||||
self.filter_str = self.cbuf.text
|
self.filter_str = self.cbuf.text
|
||||||
_cmd = command_lexer.quote(self.cbuf.text)
|
_cmd = command_lexer.quote(self.cbuf.text)
|
||||||
self.master.commands.execute("command_history.filter %s" % _cmd)
|
self.master.commands.execute("command_history.filter %s" % _cmd)
|
||||||
|
|
||||||
cmd = self.master.commands.execute("command_history.prev")
|
cmd = self.master.commands.execute("command_history.prev")
|
||||||
self.cbuf = CommandBuffer(self.master, cmd)
|
self.cbuf = CommandBuffer(self.master, cmd)
|
||||||
elif key == "down":
|
elif key == "down" or key == "ctrl n":
|
||||||
prev_cmd = self.cbuf.text
|
prev_cmd = self.cbuf.text
|
||||||
cmd = self.master.commands.execute("command_history.next")
|
cmd = self.master.commands.execute("command_history.next")
|
||||||
|
|
||||||
@ -192,7 +228,6 @@ class CommandEdit(urwid.WidgetWrap):
|
|||||||
self.cbuf = CommandBuffer(self.master, '')
|
self.cbuf = CommandBuffer(self.master, '')
|
||||||
else:
|
else:
|
||||||
self.cbuf = CommandBuffer(self.master, cmd)
|
self.cbuf = CommandBuffer(self.master, cmd)
|
||||||
|
|
||||||
elif key == "shift tab":
|
elif key == "shift tab":
|
||||||
self.cbuf.cycle_completion(False)
|
self.cbuf.cycle_completion(False)
|
||||||
elif key == "tab":
|
elif key == "tab":
|
||||||
|
Loading…
Reference in New Issue
Block a user