mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
Editing now works.
This commit is contained in:
parent
7e6196511f
commit
64360f5996
@ -9,6 +9,9 @@ class SText(common.WWrap):
|
|||||||
w = urwid.AttrWrap(w, "editfield")
|
w = urwid.AttrWrap(w, "editfield")
|
||||||
common.WWrap.__init__(self, w)
|
common.WWrap.__init__(self, w)
|
||||||
|
|
||||||
|
def get_text(self):
|
||||||
|
return self.w.get_text()[0]
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
return key
|
return key
|
||||||
|
|
||||||
@ -18,9 +21,12 @@ class SText(common.WWrap):
|
|||||||
|
|
||||||
class SEdit(common.WWrap):
|
class SEdit(common.WWrap):
|
||||||
def __init__(self, txt):
|
def __init__(self, txt):
|
||||||
w = urwid.Edit(txt, wrap="any")
|
w = urwid.Edit(txt, wrap="any", multiline=True)
|
||||||
common.WWrap.__init__(self, w)
|
common.WWrap.__init__(self, w)
|
||||||
|
|
||||||
|
def get_text(self):
|
||||||
|
return self.w.get_text()[0]
|
||||||
|
|
||||||
def selectable(self):
|
def selectable(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -29,12 +35,12 @@ class KVItem(common.WWrap):
|
|||||||
def __init__(self, focused, editing, maxk, k, v):
|
def __init__(self, focused, editing, maxk, k, v):
|
||||||
self.focused, self.editing = focused, editing
|
self.focused, self.editing = focused, editing
|
||||||
if focused == 0 and editing:
|
if focused == 0 and editing:
|
||||||
self.kf = SEdit(k)
|
self.editing = self.kf = SEdit(k)
|
||||||
else:
|
else:
|
||||||
self.kf = SText(k, True if focused == 0 else False)
|
self.kf = SText(k, True if focused == 0 else False)
|
||||||
|
|
||||||
if focused == 1 and editing:
|
if focused == 1 and editing:
|
||||||
self.vf = SEdit(v)
|
self.editing = self.vf = SEdit(v)
|
||||||
else:
|
else:
|
||||||
self.vf = SText(v, True if focused == 1 else False)
|
self.vf = SText(v, True if focused == 1 else False)
|
||||||
|
|
||||||
@ -49,12 +55,12 @@ class KVItem(common.WWrap):
|
|||||||
w.set_focus_column(focused)
|
w.set_focus_column(focused)
|
||||||
common.WWrap.__init__(self, w)
|
common.WWrap.__init__(self, w)
|
||||||
|
|
||||||
|
def get_kv(self):
|
||||||
|
return (self.kf.get_text(), self.vf.get_text())
|
||||||
|
|
||||||
def keypress(self, s, k):
|
def keypress(self, s, k):
|
||||||
if self.editing:
|
if self.editing:
|
||||||
if self.focused == 0:
|
k = self.editing.keypress(s, k)
|
||||||
return self.kf.keypress(s, k)
|
|
||||||
else:
|
|
||||||
return self.vf.keypress(s, k)
|
|
||||||
return k
|
return k
|
||||||
|
|
||||||
def selectable(self):
|
def selectable(self):
|
||||||
@ -69,10 +75,15 @@ class KVWalker(urwid.ListWalker):
|
|||||||
self.focus_col = 0
|
self.focus_col = 0
|
||||||
self.editing = False
|
self.editing = False
|
||||||
|
|
||||||
def edit(self):
|
def start_edit(self):
|
||||||
self.editing = KVItem(self.focus_col, True, self.maxk, *self.lst[self.focus])
|
self.editing = KVItem(self.focus_col, True, self.maxk, *self.lst[self.focus])
|
||||||
self._modified()
|
self._modified()
|
||||||
|
|
||||||
|
def stop_edit(self):
|
||||||
|
self.lst[self.focus] = self.editing.get_kv()
|
||||||
|
self.editing = False
|
||||||
|
self._modified()
|
||||||
|
|
||||||
def left(self):
|
def left(self):
|
||||||
self.focus_col = 0
|
self.focus_col = 0
|
||||||
self._modified()
|
self._modified()
|
||||||
@ -127,21 +138,25 @@ class KVEditor(common.WWrap):
|
|||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
if self.walker.editing:
|
if self.walker.editing:
|
||||||
self.w.keypress(size, key)
|
if key in ["esc"]:
|
||||||
return None
|
self.walker.stop_edit()
|
||||||
else:
|
return None
|
||||||
key = common.shortcuts(key)
|
elif key in ["left", "right", "up", "down"]:
|
||||||
if key == "q":
|
self.walker.stop_edit()
|
||||||
self.master.pop_view()
|
|
||||||
elif key == "h":
|
|
||||||
self.walker.left()
|
|
||||||
elif key == "l":
|
|
||||||
self.walker.right()
|
|
||||||
elif key == "tab":
|
|
||||||
self.walker.tab_next()
|
|
||||||
elif key == "enter":
|
|
||||||
self.walker.edit()
|
|
||||||
elif key == "esc":
|
|
||||||
self.master.view_connlist()
|
|
||||||
else:
|
else:
|
||||||
return self.w.keypress(size, key)
|
self.w.keypress(size, key)
|
||||||
|
return None
|
||||||
|
|
||||||
|
key = common.shortcuts(key)
|
||||||
|
if key == ["q", "esc"]:
|
||||||
|
self.master.pop_view()
|
||||||
|
elif key in ["h", "left"]:
|
||||||
|
self.walker.left()
|
||||||
|
elif key in ["l", "right"]:
|
||||||
|
self.walker.right()
|
||||||
|
elif key == "tab":
|
||||||
|
self.walker.tab_next()
|
||||||
|
elif key == "enter":
|
||||||
|
self.walker.start_edit()
|
||||||
|
else:
|
||||||
|
return self.w.keypress(size, key)
|
||||||
|
Loading…
Reference in New Issue
Block a user