From cdd5a53767e51a6d992bf8d08df2733e7af916b8 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 7 Feb 2012 16:39:37 +1300 Subject: Refactor console. Split the console implementation out into logical components. --- libmproxy/console/help.py | 146 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 libmproxy/console/help.py (limited to 'libmproxy/console/help.py') diff --git a/libmproxy/console/help.py b/libmproxy/console/help.py new file mode 100644 index 00000000..574dd7ca --- /dev/null +++ b/libmproxy/console/help.py @@ -0,0 +1,146 @@ +import urwid +import common +from .. import filt + +class HelpView(urwid.ListBox): + def __init__(self, master): + self.master = master + urwid.ListBox.__init__( + self, + self.helptext() + ) + + def keypress(self, size, key): + key = common.shortcuts(key) + if key == "q": + self.master.pop_view() + return None + return urwid.ListBox.keypress(self, size, key) + + def helptext(self): + text = [] + text.append(("head", "Global keys:\n")) + keys = [ + ("A", "accept all intercepted connections"), + ("a", "accept this intercepted connection"), + ("c", "client replay"), + ("i", "set interception pattern"), + ("j, k", "up, down"), + ("l", "set limit filter pattern"), + ("L", "load saved flows"), + + ("m", "change body display mode"), + (None, + common.highlight_key("raw", "r") + + [("text", ": raw data")] + ), + (None, + common.highlight_key("pretty", "p") + + [("text", ": pretty-print XML, HTML and JSON")] + ), + (None, + common.highlight_key("hex", "h") + + [("text", ": hex dump")] + ), + + ("o", "toggle options:"), + (None, + common.highlight_key("anticache", "a") + + [("text", ": prevent cached responses")] + ), + (None, + common.highlight_key("anticomp", "c") + + [("text", ": prevent compressed responses")] + ), + (None, + common.highlight_key("killextra", "k") + + [("text", ": kill requests not part of server replay")] + ), + (None, + common.highlight_key("norefresh", "n") + + [("text", ": disable server replay response refresh")] + ), + + ("q", "quit / return to connection list"), + ("Q", "quit without confirm prompt"), + ("r", "replay request"), + ("R", "revert changes to request"), + ("s", "set/unset script"), + ("S", "server replay"), + ("t", "set sticky cookie expression"), + ("u", "set sticky auth expression"), + ("w", "save all flows matching current limit"), + ("W", "save this flow"), + ("|", "run script on this flow"), + ("space", "page down"), + ("pg up/down", "page up/down"), + ] + text.extend(common.format_keyvals(keys, key="key", val="text", indent=4)) + + text.append(("head", "\n\nConnection list keys:\n")) + keys = [ + ("C", "clear connection list or eventlog"), + ("d", "delete connection from view"), + ("v", "toggle eventlog"), + ("X", "kill and delete connection, even if it's mid-intercept"), + ("tab", "tab between eventlog and connection list"), + ("enter", "view connection"), + ] + text.extend(common.format_keyvals(keys, key="key", val="text", indent=4)) + + text.append(("head", "\n\nConnection view keys:\n")) + keys = [ + ("b", "save request/response body"), + ("e", "edit request/response"), + ("p", "previous flow"), + ("v", "view body in external viewer"), + ("z", "encode/decode a request/response"), + ("tab", "toggle request/response view"), + ("space", "next flow"), + ] + text.extend(common.format_keyvals(keys, key="key", val="text", indent=4)) + + text.append(("head", "\n\nFilter expressions:\n")) + f = [] + for i in filt.filt_unary: + f.append( + ("~%s"%i.code, i.help) + ) + for i in filt.filt_rex: + f.append( + ("~%s regex"%i.code, i.help) + ) + for i in filt.filt_int: + f.append( + ("~%s int"%i.code, i.help) + ) + f.sort() + f.extend( + [ + ("!", "unary not"), + ("&", "and"), + ("|", "or"), + ("(...)", "grouping"), + ] + ) + text.extend(common.format_keyvals(f, key="key", val="text", indent=4)) + + text.extend( + [ + "\n", + ("text", " Regexes are Python-style.\n"), + ("text", " Regexes can be specified as quoted strings.\n"), + ("text", " Header matching (~h, ~hq, ~hs) is against a string of the form \"name: value\".\n"), + ("text", " Expressions with no operators are regex matches against URL.\n"), + ("text", " Default binary operator is &.\n"), + ("head", "\n Examples:\n"), + ] + ) + examples = [ + ("google\.com", "Url containing \"google.com"), + ("~q ~b test", "Requests where body contains \"test\""), + ("!(~q & ~t \"text/html\")", "Anything but requests with a text/html content type."), + ] + text.extend(common.format_keyvals(examples, key="key", val="text", indent=4)) + return [urwid.Text(text)] + -- cgit v1.2.3 From e3f28e1c06093147660e2857adce24b441d6530f Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 8 Feb 2012 21:47:39 +1300 Subject: Move to context-dependent help model. The all-in-one page was just getting too unwieldy. --- libmproxy/console/help.py | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) (limited to 'libmproxy/console/help.py') diff --git a/libmproxy/console/help.py b/libmproxy/console/help.py index 574dd7ca..b2eafbf0 100644 --- a/libmproxy/console/help.py +++ b/libmproxy/console/help.py @@ -3,8 +3,9 @@ import common from .. import filt class HelpView(urwid.ListBox): - def __init__(self, master): - self.master = master + def __init__(self, master, help_context, state): + self.master, self.state = master, state + self.help_context = help_context or [] urwid.ListBox.__init__( self, self.helptext() @@ -13,13 +14,19 @@ class HelpView(urwid.ListBox): def keypress(self, size, key): key = common.shortcuts(key) if key == "q": - self.master.pop_view() + self.master.statusbar = self.state[0] + self.master.body = self.state[1] + self.master.header = self.state[2] + self.master.make_view() return None return urwid.ListBox.keypress(self, size, key) def helptext(self): text = [] - text.append(("head", "Global keys:\n")) + text.append(("head", "Keys for this view:\n")) + text.extend(self.help_context) + + text.append(("head", "\n\nGlobal keys:\n")) keys = [ ("A", "accept all intercepted connections"), ("a", "accept this intercepted connection"), @@ -77,29 +84,6 @@ class HelpView(urwid.ListBox): ] text.extend(common.format_keyvals(keys, key="key", val="text", indent=4)) - text.append(("head", "\n\nConnection list keys:\n")) - keys = [ - ("C", "clear connection list or eventlog"), - ("d", "delete connection from view"), - ("v", "toggle eventlog"), - ("X", "kill and delete connection, even if it's mid-intercept"), - ("tab", "tab between eventlog and connection list"), - ("enter", "view connection"), - ] - text.extend(common.format_keyvals(keys, key="key", val="text", indent=4)) - - text.append(("head", "\n\nConnection view keys:\n")) - keys = [ - ("b", "save request/response body"), - ("e", "edit request/response"), - ("p", "previous flow"), - ("v", "view body in external viewer"), - ("z", "encode/decode a request/response"), - ("tab", "toggle request/response view"), - ("space", "next flow"), - ] - text.extend(common.format_keyvals(keys, key="key", val="text", indent=4)) - text.append(("head", "\n\nFilter expressions:\n")) f = [] for i in filt.filt_unary: -- cgit v1.2.3 From 866a93a8bc28fed47dde04f49c13592a7163bff4 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 8 Feb 2012 22:28:15 +1300 Subject: Start consolidating keybindings. I want each view to have a more coherent set of bindings. This means minimizing the global bindings, and making some bindings accessible only from screens related to their functionality. --- libmproxy/console/help.py | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'libmproxy/console/help.py') diff --git a/libmproxy/console/help.py b/libmproxy/console/help.py index b2eafbf0..0c710c7b 100644 --- a/libmproxy/console/help.py +++ b/libmproxy/console/help.py @@ -28,28 +28,12 @@ class HelpView(urwid.ListBox): text.append(("head", "\n\nGlobal keys:\n")) keys = [ - ("A", "accept all intercepted connections"), - ("a", "accept this intercepted connection"), ("c", "client replay"), ("i", "set interception pattern"), ("j, k", "up, down"), ("l", "set limit filter pattern"), ("L", "load saved flows"), - ("m", "change body display mode"), - (None, - common.highlight_key("raw", "r") + - [("text", ": raw data")] - ), - (None, - common.highlight_key("pretty", "p") + - [("text", ": pretty-print XML, HTML and JSON")] - ), - (None, - common.highlight_key("hex", "h") + - [("text", ": hex dump")] - ), - ("o", "toggle options:"), (None, common.highlight_key("anticache", "a") + @@ -78,7 +62,6 @@ class HelpView(urwid.ListBox): ("u", "set sticky auth expression"), ("w", "save all flows matching current limit"), ("W", "save this flow"), - ("|", "run script on this flow"), ("space", "page down"), ("pg up/down", "page up/down"), ] -- cgit v1.2.3 From 5df0b9e9610b803241f8c4870ddfe3afb450a048 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 8 Feb 2012 22:55:48 +1300 Subject: Further keybinding consolidation. Also, move KVEditor's "i" binding to "A" to avoid clashes with global bindings. --- libmproxy/console/help.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'libmproxy/console/help.py') diff --git a/libmproxy/console/help.py b/libmproxy/console/help.py index 0c710c7b..22b42475 100644 --- a/libmproxy/console/help.py +++ b/libmproxy/console/help.py @@ -26,13 +26,20 @@ class HelpView(urwid.ListBox): text.append(("head", "Keys for this view:\n")) text.extend(self.help_context) + text.append(("head", "\n\nMovement:\n")) + keys = [ + ("j, k", "up, down"), + ("h, l", "left, right (in some contexts)"), + ("space", "page down"), + ("pg up/down", "page up/down"), + ("arrows", "up, down, left, right"), + ] + text.extend(common.format_keyvals(keys, key="key", val="text", indent=4)) + text.append(("head", "\n\nGlobal keys:\n")) keys = [ ("c", "client replay"), ("i", "set interception pattern"), - ("j, k", "up, down"), - ("l", "set limit filter pattern"), - ("L", "load saved flows"), ("o", "toggle options:"), (None, @@ -54,16 +61,10 @@ class HelpView(urwid.ListBox): ("q", "quit / return to connection list"), ("Q", "quit without confirm prompt"), - ("r", "replay request"), - ("R", "revert changes to request"), ("s", "set/unset script"), ("S", "server replay"), ("t", "set sticky cookie expression"), ("u", "set sticky auth expression"), - ("w", "save all flows matching current limit"), - ("W", "save this flow"), - ("space", "page down"), - ("pg up/down", "page up/down"), ] text.extend(common.format_keyvals(keys, key="key", val="text", indent=4)) -- cgit v1.2.3