diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2015-03-22 17:18:53 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2015-03-22 17:18:53 +1300 |
commit | 08bb07653306ed0f84932391732391227ee07ba2 (patch) | |
tree | f9b01df3489284f37f3df0c033f324f7e1d58c11 /libmproxy/console/__init__.py | |
parent | 120c8db8a413018bde60d156f480ade001b492ef (diff) | |
download | mitmproxy-08bb07653306ed0f84932391732391227ee07ba2.tar.gz mitmproxy-08bb07653306ed0f84932391732391227ee07ba2.tar.bz2 mitmproxy-08bb07653306ed0f84932391732391227ee07ba2.zip |
console: signal-based view stack, unifying mechanisms for help, flow views, etc.
Diffstat (limited to 'libmproxy/console/__init__.py')
-rw-r--r-- | libmproxy/console/__init__.py | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index f6f8e721..90c8bd89 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -28,7 +28,6 @@ class ConsoleState(flow.State): self.follow_focus = None self.default_body_view = contentview.get("Auto") - self.view_mode = common.VIEW_LIST self.view_flow_mode = common.VIEW_FLOW_REQUEST self.flowsettings = weakref.WeakKeyDictionary() @@ -210,9 +209,13 @@ class ConsoleMaster(flow.FlowMaster): print >> sys.stderr, "Stream file error:", err sys.exit(1) + self.view_stack = [] + if options.app: self.start_app(self.options.app_host, self.options.app_port) signals.call_in.connect(self.sig_call_in) + signals.pop_view_state.connect(self.sig_pop_view_state) + signals.push_view_state.connect(self.sig_push_view_state) def __setattr__(self, name, value): self.__dict__[name] = value @@ -223,6 +226,13 @@ class ConsoleMaster(flow.FlowMaster): return callback(*args) self.loop.set_alarm_in(seconds, cb) + def sig_pop_view_state(self, sender): + if self.view_stack: + self.loop.widget = self.view_stack.pop() + + def sig_push_view_state(self, sender): + self.view_stack.append(self.loop.widget) + def start_stream_to_path(self, path, mode="wb"): path = os.path.expanduser(path) try: @@ -433,30 +443,25 @@ class ConsoleMaster(flow.FlowMaster): self.shutdown() def view_help(self): + signals.push_view_state.send(self) self.loop.widget = window.Window( self, - help.HelpView( - self, - self.help_context, - self.loop.widget, - ), + help.HelpView(self.help_context), None, statusbar.StatusBar(self, help.footer) ) def view_flowdetails(self, flow): + signals.push_view_state.send(self) self.loop.widget = window.Window( self, - flowdetailview.FlowDetailsView( - self, - flow, - self.loop.widget - ), + flowdetailview.FlowDetailsView(low), None, statusbar.StatusBar(self, flowdetailview.footer) ) def view_grideditor(self, ge): + signals.push_view_state.send(self) self.help_context = ge.make_help() self.loop.widget = window.Window( self, @@ -475,7 +480,6 @@ class ConsoleMaster(flow.FlowMaster): body = flowlist.BodyPile(self) else: body = flowlist.FlowListBox(self) - self.state.view_mode = common.VIEW_LIST self.help_context = flowlist.help_context self.loop.widget = window.Window( @@ -487,8 +491,8 @@ class ConsoleMaster(flow.FlowMaster): self.loop.draw_screen() def view_flow(self, flow): + signals.push_view_state.send(self) self.state.set_focus_flow(flow) - self.state.view_mode = common.VIEW_FLOW self.help_context = flowview.help_context self.loop.widget = window.Window( self, @@ -548,12 +552,6 @@ class ConsoleMaster(flow.FlowMaster): self.state.default_body_view = v self.refresh_focus() - def pop_view(self): - if self.state.view_mode == common.VIEW_FLOW: - self.view_flow(self.state.view[self.state.focus]) - else: - self.view_flowlist() - def edit_scripts(self, scripts): commands = [x[0] for x in scripts] # remove outer array if commands == [s.command for s in self.scripts]: |