mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
console: refactor the way we keep global view state
This commit is contained in:
parent
aa9a38522f
commit
120c8db8a4
@ -188,8 +188,6 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
self.eventlog = options.eventlog
|
self.eventlog = options.eventlog
|
||||||
self.eventlist = urwid.SimpleListWalker([])
|
self.eventlist = urwid.SimpleListWalker([])
|
||||||
|
|
||||||
self.statusbar = None
|
|
||||||
|
|
||||||
if options.client_replay:
|
if options.client_replay:
|
||||||
self.client_playback_path(options.client_replay)
|
self.client_playback_path(options.client_replay)
|
||||||
|
|
||||||
@ -287,12 +285,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
try:
|
try:
|
||||||
return flow.read_flows_from_paths([path])
|
return flow.read_flows_from_paths([path])
|
||||||
except flow.FlowReadError as e:
|
except flow.FlowReadError as e:
|
||||||
if not self.statusbar:
|
signals.status_message.send(message=e.strerror)
|
||||||
print >> sys.stderr, e.strerror
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
signals.status_message.send(message=e.strerror)
|
|
||||||
return None
|
|
||||||
|
|
||||||
def client_playback_path(self, path):
|
def client_playback_path(self, path):
|
||||||
flows = self._readflows(path)
|
flows = self._readflows(path)
|
||||||
@ -326,7 +319,9 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
try:
|
try:
|
||||||
subprocess.call(cmd)
|
subprocess.call(cmd)
|
||||||
except:
|
except:
|
||||||
signals.status_message.send(message="Can't start editor: %s" % " ".join(c))
|
signals.status_message.send(
|
||||||
|
message = "Can't start editor: %s" % " ".join(c)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
data = open(name, "rb").read()
|
data = open(name, "rb").read()
|
||||||
self.ui.start()
|
self.ui.start()
|
||||||
@ -386,17 +381,11 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
self.ui.set_terminal_properties(256)
|
self.ui.set_terminal_properties(256)
|
||||||
self.ui.register_palette(self.palette.palette())
|
self.ui.register_palette(self.palette.palette())
|
||||||
self.flow_list_walker = flowlist.FlowListWalker(self, self.state)
|
self.flow_list_walker = flowlist.FlowListWalker(self, self.state)
|
||||||
self.view = None
|
|
||||||
self.statusbar = None
|
|
||||||
self.header = None
|
|
||||||
self.body = None
|
|
||||||
self.help_context = None
|
self.help_context = None
|
||||||
self.onekey = False
|
|
||||||
self.loop = urwid.MainLoop(
|
self.loop = urwid.MainLoop(
|
||||||
self.view,
|
urwid.SolidFill("x"),
|
||||||
screen = self.ui,
|
screen = self.ui,
|
||||||
)
|
)
|
||||||
self.view_flowlist()
|
|
||||||
|
|
||||||
self.server.start_slave(
|
self.server.start_slave(
|
||||||
controller.Slave,
|
controller.Slave,
|
||||||
@ -425,6 +414,11 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
raise urwid.ExitMainLoop
|
raise urwid.ExitMainLoop
|
||||||
signal.signal(signal.SIGINT, exit)
|
signal.signal(signal.SIGINT, exit)
|
||||||
|
|
||||||
|
self.loop.set_alarm_in(
|
||||||
|
0.0001,
|
||||||
|
lambda *args: self.view_flowlist()
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.loop.run()
|
self.loop.run()
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -438,43 +432,38 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
|
|
||||||
def make_view(self):
|
|
||||||
self.view = window.Window(
|
|
||||||
self,
|
|
||||||
self.body,
|
|
||||||
header = self.header,
|
|
||||||
footer = self.statusbar
|
|
||||||
)
|
|
||||||
return self.view
|
|
||||||
|
|
||||||
def view_help(self):
|
def view_help(self):
|
||||||
h = help.HelpView(
|
self.loop.widget = window.Window(
|
||||||
self,
|
self,
|
||||||
self.help_context,
|
help.HelpView(
|
||||||
(self.statusbar, self.body, self.header)
|
self,
|
||||||
|
self.help_context,
|
||||||
|
self.loop.widget,
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
statusbar.StatusBar(self, help.footer)
|
||||||
)
|
)
|
||||||
self.statusbar = statusbar.StatusBar(self, help.footer)
|
|
||||||
self.body = h
|
|
||||||
self.header = None
|
|
||||||
self.loop.widget = self.make_view()
|
|
||||||
|
|
||||||
def view_flowdetails(self, flow):
|
def view_flowdetails(self, flow):
|
||||||
h = flowdetailview.FlowDetailsView(
|
self.loop.widget = window.Window(
|
||||||
self,
|
self,
|
||||||
flow,
|
flowdetailview.FlowDetailsView(
|
||||||
(self.statusbar, self.body, self.header)
|
self,
|
||||||
|
flow,
|
||||||
|
self.loop.widget
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
statusbar.StatusBar(self, flowdetailview.footer)
|
||||||
)
|
)
|
||||||
self.statusbar = statusbar.StatusBar(self, flowdetailview.footer)
|
|
||||||
self.body = h
|
|
||||||
self.header = None
|
|
||||||
self.loop.widget = self.make_view()
|
|
||||||
|
|
||||||
def view_grideditor(self, ge):
|
def view_grideditor(self, ge):
|
||||||
self.body = ge
|
|
||||||
self.header = None
|
|
||||||
self.help_context = ge.make_help()
|
self.help_context = ge.make_help()
|
||||||
self.statusbar = statusbar.StatusBar(self, grideditor.footer)
|
self.loop.widget = window.Window(
|
||||||
self.loop.widget = self.make_view()
|
self,
|
||||||
|
ge,
|
||||||
|
None,
|
||||||
|
statusbar.StatusBar(self, grideditor.FOOTER)
|
||||||
|
)
|
||||||
|
|
||||||
def view_flowlist(self):
|
def view_flowlist(self):
|
||||||
if self.ui.started:
|
if self.ui.started:
|
||||||
@ -483,24 +472,30 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
self.state.set_focus(self.state.flow_count())
|
self.state.set_focus(self.state.flow_count())
|
||||||
|
|
||||||
if self.eventlog:
|
if self.eventlog:
|
||||||
self.body = flowlist.BodyPile(self)
|
body = flowlist.BodyPile(self)
|
||||||
else:
|
else:
|
||||||
self.body = flowlist.FlowListBox(self)
|
body = flowlist.FlowListBox(self)
|
||||||
self.statusbar = statusbar.StatusBar(self, flowlist.footer)
|
|
||||||
self.header = None
|
|
||||||
self.state.view_mode = common.VIEW_LIST
|
self.state.view_mode = common.VIEW_LIST
|
||||||
|
|
||||||
self.loop.widget = self.make_view()
|
|
||||||
self.help_context = flowlist.help_context
|
self.help_context = flowlist.help_context
|
||||||
|
self.loop.widget = window.Window(
|
||||||
|
self,
|
||||||
|
body,
|
||||||
|
None,
|
||||||
|
statusbar.StatusBar(self, flowlist.footer)
|
||||||
|
)
|
||||||
|
self.loop.draw_screen()
|
||||||
|
|
||||||
def view_flow(self, flow):
|
def view_flow(self, flow):
|
||||||
self.body = flowview.FlowView(self, self.state, flow)
|
|
||||||
self.header = flowview.FlowViewHeader(self, flow)
|
|
||||||
self.statusbar = statusbar.StatusBar(self, flowview.footer)
|
|
||||||
self.state.set_focus_flow(flow)
|
self.state.set_focus_flow(flow)
|
||||||
self.state.view_mode = common.VIEW_FLOW
|
self.state.view_mode = common.VIEW_FLOW
|
||||||
self.loop.widget = self.make_view()
|
|
||||||
self.help_context = flowview.help_context
|
self.help_context = flowview.help_context
|
||||||
|
self.loop.widget = window.Window(
|
||||||
|
self,
|
||||||
|
flowview.FlowView(self, self.state, flow),
|
||||||
|
flowview.FlowViewHeader(self, flow),
|
||||||
|
statusbar.StatusBar(self, flowview.footer)
|
||||||
|
)
|
||||||
|
|
||||||
def _write_flows(self, path, flows):
|
def _write_flows(self, path, flows):
|
||||||
if not path:
|
if not path:
|
||||||
|
@ -18,10 +18,7 @@ class FlowDetailsView(urwid.ListBox):
|
|||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
key = common.shortcuts(key)
|
key = common.shortcuts(key)
|
||||||
if key == "q":
|
if key == "q":
|
||||||
self.master.statusbar = self.state[0]
|
self.master.loop.widget = self.state
|
||||||
self.master.body = self.state[1]
|
|
||||||
self.master.header = self.state[2]
|
|
||||||
self.master.loop.widget = self.master.make_view()
|
|
||||||
return None
|
return None
|
||||||
elif key == "?":
|
elif key == "?":
|
||||||
key = None
|
key = None
|
||||||
|
@ -10,11 +10,11 @@ from .. import utils, filt, script
|
|||||||
from netlib import http_uastrings
|
from netlib import http_uastrings
|
||||||
|
|
||||||
|
|
||||||
footer = [
|
FOOTER = [
|
||||||
('heading_key', "enter"), ":edit ",
|
('heading_key', "enter"), ":edit ",
|
||||||
('heading_key', "q"), ":back ",
|
('heading_key', "q"), ":back ",
|
||||||
]
|
]
|
||||||
footer_editing = [
|
FOOTER_EDITING = [
|
||||||
('heading_key', "esc"), ":stop editing ",
|
('heading_key', "esc"), ":stop editing ",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -164,12 +164,12 @@ class GridWalker(urwid.ListWalker):
|
|||||||
self.editing = GridRow(
|
self.editing = GridRow(
|
||||||
self.focus_col, True, self.editor, self.lst[self.focus]
|
self.focus_col, True, self.editor, self.lst[self.focus]
|
||||||
)
|
)
|
||||||
self.editor.master.statusbar.update(footer_editing)
|
self.editor.master.loop.widget.footer.update(FOOTER_EDITING)
|
||||||
self._modified()
|
self._modified()
|
||||||
|
|
||||||
def stop_edit(self):
|
def stop_edit(self):
|
||||||
if self.editing:
|
if self.editing:
|
||||||
self.editor.master.statusbar.update(footer)
|
self.editor.master.loop.widget.footer.update(FOOTER)
|
||||||
self.set_current_value(self.editing.get_edit_value(), False)
|
self.set_current_value(self.editing.get_edit_value(), False)
|
||||||
self.editing = False
|
self.editing = False
|
||||||
self._modified()
|
self._modified()
|
||||||
@ -268,7 +268,7 @@ class GridEditor(urwid.WidgetWrap):
|
|||||||
self.lb,
|
self.lb,
|
||||||
header = urwid.Pile([title, h])
|
header = urwid.Pile([title, h])
|
||||||
)
|
)
|
||||||
self.master.statusbar.update("")
|
self.master.loop.widget.footer.update("")
|
||||||
self.show_empty_msg()
|
self.show_empty_msg()
|
||||||
|
|
||||||
def show_empty_msg(self):
|
def show_empty_msg(self):
|
||||||
|
@ -180,10 +180,7 @@ class HelpView(urwid.ListBox):
|
|||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
key = common.shortcuts(key)
|
key = common.shortcuts(key)
|
||||||
if key == "q":
|
if key == "q":
|
||||||
self.master.statusbar = self.state[0]
|
self.master.loop.widget = self.state
|
||||||
self.master.body = self.state[1]
|
|
||||||
self.master.header = self.state[2]
|
|
||||||
self.master.loop.widget = self.master.make_view()
|
|
||||||
return None
|
return None
|
||||||
elif key == "?":
|
elif key == "?":
|
||||||
key = None
|
key = None
|
||||||
|
@ -114,6 +114,7 @@ class StatusBar(urwid.WidgetWrap):
|
|||||||
self.ib = urwid.WidgetWrap(urwid.Text(""))
|
self.ib = urwid.WidgetWrap(urwid.Text(""))
|
||||||
self._w = urwid.Pile([self.ib, self.ab])
|
self._w = urwid.Pile([self.ib, self.ab])
|
||||||
signals.update_settings.connect(self.sig_update_settings)
|
signals.update_settings.connect(self.sig_update_settings)
|
||||||
|
self.redraw()
|
||||||
|
|
||||||
def sig_update_settings(self, sender):
|
def sig_update_settings(self, sender):
|
||||||
self.redraw()
|
self.redraw()
|
||||||
@ -188,7 +189,11 @@ class StatusBar(urwid.WidgetWrap):
|
|||||||
if self.master.state.follow_focus:
|
if self.master.state.follow_focus:
|
||||||
opts.append("following")
|
opts.append("following")
|
||||||
if self.master.stream_large_bodies:
|
if self.master.stream_large_bodies:
|
||||||
opts.append("stream:%s" % utils.pretty_size(self.master.stream_large_bodies.max_size))
|
opts.append(
|
||||||
|
"stream:%s" % utils.pretty_size(
|
||||||
|
self.master.stream_large_bodies.max_size
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if opts:
|
if opts:
|
||||||
r.append("[%s]"%(":".join(opts)))
|
r.append("[%s]"%(":".join(opts)))
|
||||||
|
Loading…
Reference in New Issue
Block a user