mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +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:
|
||||||
|
if key in ["esc"]:
|
||||||
|
self.walker.stop_edit()
|
||||||
|
return None
|
||||||
|
elif key in ["left", "right", "up", "down"]:
|
||||||
|
self.walker.stop_edit()
|
||||||
|
else:
|
||||||
self.w.keypress(size, key)
|
self.w.keypress(size, key)
|
||||||
return None
|
return None
|
||||||
else:
|
|
||||||
key = common.shortcuts(key)
|
key = common.shortcuts(key)
|
||||||
if key == "q":
|
if key == ["q", "esc"]:
|
||||||
self.master.pop_view()
|
self.master.pop_view()
|
||||||
elif key == "h":
|
elif key in ["h", "left"]:
|
||||||
self.walker.left()
|
self.walker.left()
|
||||||
elif key == "l":
|
elif key in ["l", "right"]:
|
||||||
self.walker.right()
|
self.walker.right()
|
||||||
elif key == "tab":
|
elif key == "tab":
|
||||||
self.walker.tab_next()
|
self.walker.tab_next()
|
||||||
elif key == "enter":
|
elif key == "enter":
|
||||||
self.walker.edit()
|
self.walker.start_edit()
|
||||||
elif key == "esc":
|
|
||||||
self.master.view_connlist()
|
|
||||||
else:
|
else:
|
||||||
return self.w.keypress(size, key)
|
return self.w.keypress(size, key)
|
||||||
|
Loading…
Reference in New Issue
Block a user