diff options
Diffstat (limited to 'libmproxy/console/__init__.py')
-rw-r--r-- | libmproxy/console/__init__.py | 75 |
1 files changed, 33 insertions, 42 deletions
diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index 2c673531..04e240d3 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -1,18 +1,3 @@ -# Copyright (C) 2010 Aldo Cortesi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - import mailcap, mimetypes, tempfile, os, subprocess, glob, time, shlex, stat import os.path, sys, weakref import urwid @@ -204,15 +189,13 @@ class StatusBar(common.WWrap): self.message("") fc = self.master.state.flow_count() - if self.master.currentflow: - idx = self.master.state.view.index(self.master.currentflow) + 1 - t = [ - ('heading', ("[%s/%s]"%(idx, fc)).ljust(9)) - ] + if self.master.state.focus is None: + offset = 0 else: - t = [ - ('heading', ("[%s]"%fc).ljust(9)) - ] + offset = min(self.master.state.focus + 1, fc) + t = [ + ('heading', ("[%s/%s]"%(offset, fc)).ljust(9)) + ] if self.master.server.bound: boundaddr = "[%s:%s]"%(self.master.server.address or "*", self.master.server.port) @@ -263,7 +246,10 @@ class ConsoleState(flow.State): self.focus = None 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.last_script = "" self.last_saveload = "" self.flowsettings = weakref.WeakKeyDictionary() @@ -308,6 +294,9 @@ class ConsoleState(flow.State): idx = 0 self.focus = idx + def set_focus_flow(self, f): + self.set_focus(self.view.index(f)) + def get_from_pos(self, pos): if len(self.view) <= pos or pos < 0: return None, None @@ -320,6 +309,10 @@ class ConsoleState(flow.State): return self.get_from_pos(pos-1) def delete_flow(self, f): + if f in self.view and self.view.index(f) <= self.focus: + self.focus -= 1 + if self.focus < 0: + self.focus = None ret = flow.State.delete_flow(self, f) self.set_focus(self.focus) return ret @@ -328,6 +321,9 @@ class ConsoleState(flow.State): class Options(object): attributes = [ + "app", + "app_domain", + "app_ip", "anticache", "anticomp", "client_replay", @@ -426,6 +422,9 @@ class ConsoleMaster(flow.FlowMaster): print >> sys.stderr, "Script load error:", err sys.exit(1) + if options.app: + self.start_app(options.app_domain, options.app_ip) + def start_stream(self, path): path = os.path.expanduser(path) try: @@ -564,8 +563,6 @@ class ConsoleMaster(flow.FlowMaster): self.palette = palettes.palettes[name] def run(self): - self.currentflow = None - self.ui = urwid.raw_display.Screen() self.ui.set_terminal_properties(256) self.ui.register_palette(self.palette) @@ -599,13 +596,6 @@ class ConsoleMaster(flow.FlowMaster): sys.stderr.flush() self.shutdown() - def focus_current(self): - if self.currentflow: - try: - self.flow_list_walker.set_focus(self.state.view.index(self.currentflow)) - except (IndexError, ValueError): - pass - def make_view(self): self.view = urwid.Frame( self.body, @@ -640,8 +630,6 @@ class ConsoleMaster(flow.FlowMaster): self.ui.clear() if self.state.follow_focus: self.state.set_focus(self.state.flow_count()) - else: - self.focus_current() if self.eventlog: self.body = flowlist.BodyPile(self) @@ -649,7 +637,7 @@ class ConsoleMaster(flow.FlowMaster): self.body = flowlist.FlowListBox(self) self.statusbar = StatusBar(self, flowlist.footer) self.header = None - self.currentflow = None + self.state.view_mode = common.VIEW_LIST self.make_view() self.help_context = flowlist.help_context @@ -658,7 +646,8 @@ class ConsoleMaster(flow.FlowMaster): self.body = flowview.FlowView(self, self.state, flow) self.header = flowview.FlowViewHeader(self, flow) self.statusbar = StatusBar(self, flowview.footer) - self.currentflow = flow + self.state.set_focus_flow(flow) + self.state.view_mode = common.VIEW_FLOW self.make_view() self.help_context = flowview.help_context @@ -705,7 +694,6 @@ class ConsoleMaster(flow.FlowMaster): f.close() if self.flow_list_walker: self.sync_list_view() - self.focus_current() return reterr def path_prompt(self, prompt, text, callback, *args): @@ -771,8 +759,7 @@ class ConsoleMaster(flow.FlowMaster): def change_default_display_mode(self, t): v = contentview.get_by_shortcut(t) self.state.default_body_view = v - if self.currentflow: - self.refresh_flow(self.currentflow) + self.refresh_focus() def set_reverse_proxy(self, txt): if not txt: @@ -790,8 +777,8 @@ class ConsoleMaster(flow.FlowMaster): return size def pop_view(self): - if self.currentflow: - self.view_flow(self.currentflow) + if self.state.view_mode == common.VIEW_FLOW: + self.view_flow(self.state.view[self.state.focus]) else: self.view_flowlist() @@ -966,7 +953,7 @@ class ConsoleMaster(flow.FlowMaster): if a == "h": self.showhost = not self.showhost self.sync_list_view() - self.refresh_flow(self.currentflow) + self.refresh_focus() elif a == "k": self.killextra = not self.killextra elif a == "n": @@ -997,6 +984,10 @@ class ConsoleMaster(flow.FlowMaster): self.state.delete_flow(f) self.sync_list_view() + def refresh_focus(self): + if self.state.view: + self.refresh_flow(self.state.view[self.state.focus]) + def refresh_flow(self, c): if hasattr(self.header, "refresh_flow"): self.header.refresh_flow(c) |