mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
KVEditor -> GridEditor
This commit is contained in:
parent
552146d015
commit
18d0e840b5
@ -17,7 +17,7 @@ import mailcap, mimetypes, tempfile, os, subprocess, glob, time, shlex
|
|||||||
import os.path, sys
|
import os.path, sys
|
||||||
import urwid
|
import urwid
|
||||||
from .. import controller, utils, flow, version
|
from .. import controller, utils, flow, version
|
||||||
import flowlist, flowview, help, common, kveditor, palettes
|
import flowlist, flowview, help, common, grideditor, palettes
|
||||||
|
|
||||||
EVENTLOG_SIZE = 500
|
EVENTLOG_SIZE = 500
|
||||||
|
|
||||||
@ -543,10 +543,10 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
self.header = None
|
self.header = None
|
||||||
self.make_view()
|
self.make_view()
|
||||||
|
|
||||||
def view_kveditor(self, title, value, callback, *args, **kwargs):
|
def view_grideditor(self, title, value, callback, *args, **kwargs):
|
||||||
self.body = kveditor.KVEditor(self, title, value, callback, *args, **kwargs)
|
self.body = grideditor.GridEditor(self, title, value, callback, *args, **kwargs)
|
||||||
self.header = None
|
self.header = None
|
||||||
self.help_context = kveditor.help_context
|
self.help_context = grideditor.help_context
|
||||||
self.statusbar = StatusBar(self, self.footer_text_help)
|
self.statusbar = StatusBar(self, self.footer_text_help)
|
||||||
self.make_view()
|
self.make_view()
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ class ConnectionView(common.WWrap):
|
|||||||
conn.set_form_urlencoded(flow.ODict(lst))
|
conn.set_form_urlencoded(flow.ODict(lst))
|
||||||
|
|
||||||
def edit_form(self, conn):
|
def edit_form(self, conn):
|
||||||
self.master.view_kveditor("Editing form", conn.get_form_urlencoded().lst, self.set_form, conn)
|
self.master.view_grideditor("Editing form", conn.get_form_urlencoded().lst, self.set_form, conn)
|
||||||
|
|
||||||
def edit_form_confirm(self, key, conn):
|
def edit_form_confirm(self, key, conn):
|
||||||
if key == "y":
|
if key == "y":
|
||||||
@ -427,9 +427,9 @@ class ConnectionView(common.WWrap):
|
|||||||
else:
|
else:
|
||||||
self.edit_form(conn)
|
self.edit_form(conn)
|
||||||
elif part == "h":
|
elif part == "h":
|
||||||
self.master.view_kveditor("Editing headers", conn.headers.lst, self.set_headers, conn)
|
self.master.view_grideditor("Editing headers", conn.headers.lst, self.set_headers, conn)
|
||||||
elif part == "q":
|
elif part == "q":
|
||||||
self.master.view_kveditor("Editing query", conn.get_query().lst, self.set_query, conn)
|
self.master.view_grideditor("Editing query", conn.get_query().lst, self.set_query, conn)
|
||||||
elif part == "u" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
elif part == "u" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
||||||
self.master.prompt_edit("URL", conn.get_url(), self.set_url)
|
self.master.prompt_edit("URL", conn.get_url(), self.set_url)
|
||||||
elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
||||||
|
@ -66,7 +66,7 @@ class SEdit(common.WWrap):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class KVItem(common.WWrap):
|
class GridItem(common.WWrap):
|
||||||
def __init__(self, focused, editing, maxk, k, v):
|
def __init__(self, focused, editing, maxk, k, v):
|
||||||
self.focused, self.editing, self.maxk = focused, editing, maxk
|
self.focused, self.editing, self.maxk = focused, editing, maxk
|
||||||
if focused == 0 and editing:
|
if focused == 0 and editing:
|
||||||
@ -103,7 +103,7 @@ class KVItem(common.WWrap):
|
|||||||
|
|
||||||
|
|
||||||
KEY_MAX = 30
|
KEY_MAX = 30
|
||||||
class KVWalker(urwid.ListWalker):
|
class GridWalker(urwid.ListWalker):
|
||||||
def __init__(self, lst, editor):
|
def __init__(self, lst, editor):
|
||||||
self.lst, self.editor = lst, editor
|
self.lst, self.editor = lst, editor
|
||||||
self.maxk = min(max(len(v[0]) for v in lst), KEY_MAX) if lst else 20
|
self.maxk = min(max(len(v[0]) for v in lst), KEY_MAX) if lst else 20
|
||||||
@ -146,7 +146,7 @@ class KVWalker(urwid.ListWalker):
|
|||||||
|
|
||||||
def start_edit(self):
|
def start_edit(self):
|
||||||
if self.lst:
|
if self.lst:
|
||||||
self.editing = KVItem(self.focus_col, True, self.maxk, *self.lst[self.focus])
|
self.editing = GridItem(self.focus_col, True, self.maxk, *self.lst[self.focus])
|
||||||
self._modified()
|
self._modified()
|
||||||
|
|
||||||
def stop_edit(self):
|
def stop_edit(self):
|
||||||
@ -176,7 +176,7 @@ class KVWalker(urwid.ListWalker):
|
|||||||
if self.editing:
|
if self.editing:
|
||||||
return self.editing, self.focus
|
return self.editing, self.focus
|
||||||
elif self.lst:
|
elif self.lst:
|
||||||
return KVItem(self.focus_col, False, self.maxk, *self.lst[self.focus]), self.focus
|
return GridItem(self.focus_col, False, self.maxk, *self.lst[self.focus]), self.focus
|
||||||
else:
|
else:
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
@ -187,20 +187,20 @@ class KVWalker(urwid.ListWalker):
|
|||||||
def get_next(self, pos):
|
def get_next(self, pos):
|
||||||
if pos+1 >= len(self.lst):
|
if pos+1 >= len(self.lst):
|
||||||
return None, None
|
return None, None
|
||||||
return KVItem(None, False, self.maxk, *self.lst[pos+1]), pos+1
|
return GridItem(None, False, self.maxk, *self.lst[pos+1]), pos+1
|
||||||
|
|
||||||
def get_prev(self, pos):
|
def get_prev(self, pos):
|
||||||
if pos-1 < 0:
|
if pos-1 < 0:
|
||||||
return None, None
|
return None, None
|
||||||
return KVItem(None, False, self.maxk, *self.lst[pos-1]), pos-1
|
return GridItem(None, False, self.maxk, *self.lst[pos-1]), pos-1
|
||||||
|
|
||||||
|
|
||||||
class KVListBox(urwid.ListBox):
|
class GridListBox(urwid.ListBox):
|
||||||
def __init__(self, lw):
|
def __init__(self, lw):
|
||||||
urwid.ListBox.__init__(self, lw)
|
urwid.ListBox.__init__(self, lw)
|
||||||
|
|
||||||
|
|
||||||
class KVEditor(common.WWrap):
|
class GridEditor(common.WWrap):
|
||||||
def __init__(self, master, title, value, callback, *cb_args, **cb_kwargs):
|
def __init__(self, master, title, value, callback, *cb_args, **cb_kwargs):
|
||||||
value = copy.deepcopy(value)
|
value = copy.deepcopy(value)
|
||||||
self.master, self.title, self.value, self.callback = master, title, value, callback
|
self.master, self.title, self.value, self.callback = master, title, value, callback
|
||||||
@ -208,8 +208,8 @@ class KVEditor(common.WWrap):
|
|||||||
p = urwid.Text(title)
|
p = urwid.Text(title)
|
||||||
p = urwid.Padding(p, align="left", width=("relative", 100))
|
p = urwid.Padding(p, align="left", width=("relative", 100))
|
||||||
p = urwid.AttrWrap(p, "heading")
|
p = urwid.AttrWrap(p, "heading")
|
||||||
self.walker = KVWalker(self.value, self)
|
self.walker = GridWalker(self.value, self)
|
||||||
self.lb = KVListBox(self.walker)
|
self.lb = GridListBox(self.walker)
|
||||||
self.w = urwid.Frame(self.lb, header = p)
|
self.w = urwid.Frame(self.lb, header = p)
|
||||||
self.master.statusbar.update("")
|
self.master.statusbar.update("")
|
||||||
self.show_empty_msg()
|
self.show_empty_msg()
|
@ -44,7 +44,7 @@ dark = [
|
|||||||
# Hex view
|
# Hex view
|
||||||
('offset', 'dark cyan', 'default'),
|
('offset', 'dark cyan', 'default'),
|
||||||
|
|
||||||
# KV Editor
|
# Grid Editor
|
||||||
('focusfield', 'black', 'light gray'),
|
('focusfield', 'black', 'light gray'),
|
||||||
('editfield', 'black', 'light cyan'),
|
('editfield', 'black', 'light cyan'),
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user