From 32ba6021b3c07efaa45a9223479151cd7e74ccbd Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 1 Apr 2015 09:25:50 +1300 Subject: console: improve handling of help contexts, fix key bindings in flow views --- libmproxy/console/__init__.py | 34 ++++++++++++++++++++++------------ libmproxy/console/flowview.py | 14 +++++--------- libmproxy/console/searchable.py | 2 +- libmproxy/console/tabs.py | 3 +-- libmproxy/console/window.py | 20 +++++++------------- 5 files changed, 36 insertions(+), 37 deletions(-) (limited to 'libmproxy/console') diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index 660024cc..a963924e 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -15,8 +15,8 @@ import urwid import weakref from .. import controller, flow, script -from . import flowlist, flowview, help, common, window, signals -from . import grideditor, palettes, contentview, flowdetailview, statusbar +from . import flowlist, flowview, help, window, signals +from . import grideditor, palettes, contentview, statusbar EVENTLOG_SIZE = 500 @@ -227,6 +227,16 @@ class ConsoleMaster(flow.FlowMaster): def sig_pop_view_state(self, sender): if self.view_stack: self.loop.widget = self.view_stack.pop() + else: + signals.status_prompt_onekey.send( + self, + prompt = "Quit", + keys = ( + ("yes", "y"), + ("no", "n"), + ), + callback = self.quit, + ) def sig_push_view_state(self, sender): self.view_stack.append(self.loop.widget) @@ -393,7 +403,6 @@ class ConsoleMaster(flow.FlowMaster): self.ui.set_terminal_properties(256) self.ui.register_palette(self.palette.palette()) self.flow_list_walker = flowlist.FlowListWalker(self, self.state) - self.help_context = None self.loop = urwid.MainLoop( urwid.SolidFill("x"), screen = self.ui, @@ -444,23 +453,24 @@ class ConsoleMaster(flow.FlowMaster): sys.stderr.flush() self.shutdown() - def view_help(self): + def view_help(self, helpctx): signals.push_view_state.send(self) self.loop.widget = window.Window( self, - help.HelpView(self.help_context), + help.HelpView(helpctx), None, - statusbar.StatusBar(self, help.footer) + statusbar.StatusBar(self, help.footer), + None ) def view_grideditor(self, ge): signals.push_view_state.send(self) - self.help_context = ge.make_help() self.loop.widget = window.Window( self, ge, None, - statusbar.StatusBar(self, grideditor.FOOTER) + statusbar.StatusBar(self, grideditor.FOOTER), + ge.make_help() ) def view_flowlist(self): @@ -474,24 +484,24 @@ class ConsoleMaster(flow.FlowMaster): else: body = flowlist.FlowListBox(self) - self.help_context = flowlist.help_context self.loop.widget = window.Window( self, body, None, - statusbar.StatusBar(self, flowlist.footer) + statusbar.StatusBar(self, flowlist.footer), + flowlist.help_context ) self.loop.draw_screen() def view_flow(self, flow, tab_offset=0): signals.push_view_state.send(self) self.state.set_focus_flow(flow) - self.help_context = flowview.help_context self.loop.widget = window.Window( self, flowview.FlowView(self, self.state, flow, tab_offset), flowview.FlowViewHeader(self, flow), - statusbar.StatusBar(self, flowview.footer) + statusbar.StatusBar(self, flowview.footer), + flowview.help_context ) def _write_flows(self, path, flows): diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 538f42f0..6a3ced6e 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -434,6 +434,8 @@ class FlowView(tabs.Tabs): signals.flow_change.send(self, flow = self.flow) def keypress(self, size, key): + key = super(self.__class__, self).keypress(size, key) + if key == " ": self.view_next_flow(self.flow) return @@ -446,10 +448,7 @@ class FlowView(tabs.Tabs): else: conn = None - if key == "q": - signals.pop_view_state.send(self) - return None - elif key in ("up", "down", "page up", "page down"): + if key in ("up", "down", "page up", "page down"): # Why doesn't this just work?? self._w.keypress(size, key) elif key == "a": @@ -499,7 +498,7 @@ class FlowView(tabs.Tabs): args = (self.flow,) ) - if not conn and key in "befgmxvz": + if not conn and key in set(list("befgmxvz")): signals.status_message.send( message = "Tab to the request or response", expire = 1 @@ -601,10 +600,7 @@ class FlowView(tabs.Tabs): args = (conn,) ) signals.flow_change.send(self, flow = self.flow) - else: - return super(self.__class__, self).keypress(size, key) - else: - return super(self.__class__, self).keypress(size, key) + return key def encode_callback(self, key, conn): encoding_map = { diff --git a/libmproxy/console/searchable.py b/libmproxy/console/searchable.py index a723dca8..8f63c3f5 100644 --- a/libmproxy/console/searchable.py +++ b/libmproxy/console/searchable.py @@ -36,7 +36,7 @@ class Searchable(urwid.ListBox): if key == "N": self.find_next(True) else: - super(self.__class__, self).keypress(size, key) + return super(self.__class__, self).keypress(size, key) def set_search(self, text): self.state.last_search = text diff --git a/libmproxy/console/tabs.py b/libmproxy/console/tabs.py index bb188c28..fff13890 100644 --- a/libmproxy/console/tabs.py +++ b/libmproxy/console/tabs.py @@ -17,8 +17,7 @@ class Tabs(urwid.WidgetWrap): if key == "tab": self.tab_offset = (self.tab_offset + 1)%(len(self.tabs)) self.show() - else: - return self._w.keypress(size, key) + return self._w.keypress(size, key) def show(self): headers = [] diff --git a/libmproxy/console/window.py b/libmproxy/console/window.py index d686f61d..14a3acd2 100644 --- a/libmproxy/console/window.py +++ b/libmproxy/console/window.py @@ -1,19 +1,21 @@ import urwid -from . import common, grideditor, signals, contentview +from . import grideditor, signals, contentview + class Window(urwid.Frame): - def __init__(self, master, body, header, footer): + def __init__(self, master, body, header, footer, helpctx): urwid.Frame.__init__(self, body, header=header, footer=footer) self.master = master + self.helpctx = helpctx signals.focus.connect(self.sig_focus) def sig_focus(self, sender, section): self.focus_position = section def keypress(self, size, k): - k = urwid.Frame.keypress(self, self.master.loop.screen_size, k) + k = super(self.__class__, self).keypress(size, k) if k == "?": - self.master.view_help() + self.master.view_help(self.helpctx) elif k == "c": if not self.master.client_playback: signals.status_prompt_path.send( @@ -65,15 +67,7 @@ class Window(urwid.Frame): elif k == "Q": raise urwid.ExitMainLoop elif k == "q": - signals.status_prompt_onekey.send( - self, - prompt = "Quit", - keys = ( - ("yes", "y"), - ("no", "n"), - ), - callback = self.master.quit, - ) + signals.pop_view_state.send(self) elif k == "M": signals.status_prompt_onekey.send( prompt = "Global default display mode", -- cgit v1.2.3