Merge pull request #2384 from cortesi/layouts

console: layout pane headers
This commit is contained in:
Aldo Cortesi 2017-06-11 13:14:30 +12:00 committed by GitHub
commit 75c047da3f
10 changed files with 46 additions and 12 deletions

View File

@ -385,6 +385,10 @@ class Options(optmanager.OptManager):
"Console layout.",
choices=sorted(console_layouts),
)
self.add_option(
"console_layout_headers", bool, True,
"Show layout comonent headers",
)
self.add_option(
"console_focus_follow", bool, False,
"Focus follows new flows."

View File

@ -109,6 +109,7 @@ def mitmproxy(opts):
common_options(parser, opts)
opts.make_parser(parser, "console_layout")
opts.make_parser(parser, "console_layout_headers")
group = parser.add_argument_group(
"Filters",
"See help in mitmproxy for filter expression syntax."

View File

@ -152,6 +152,7 @@ class CommandHelp(urwid.Frame):
class Commands(urwid.Pile):
title = "Commands"
keyctx = "commands"
def __init__(self, master):

View File

@ -10,6 +10,7 @@ class LogBufferWalker(urwid.SimpleListWalker):
class EventLog(urwid.ListBox):
keyctx = "eventlog"
title = "Events"
def __init__(self, master):
self.walker = LogBufferWalker([])

View File

@ -110,6 +110,7 @@ class FlowListWalker(urwid.ListWalker):
class FlowListBox(urwid.ListBox):
title = "Flows"
keyctx = "flowlist"
def __init__(

View File

@ -276,6 +276,7 @@ class FlowDetails(tabs.Tabs):
class FlowView(urwid.Frame):
keyctx = "flowview"
title = "Flow Details"
def __init__(self, master):
super().__init__(

View File

@ -16,7 +16,7 @@ from mitmproxy.net.http import Headers
class QueryEditor(base.FocusEditor):
title = "Editing query"
title = "Edit Query"
columns = [
col_text.Column("Key"),
col_text.Column("Value")
@ -71,7 +71,7 @@ class HeaderEditor(base.FocusEditor):
class RequestHeaderEditor(HeaderEditor):
title = "Editing request headers"
title = "Edit Request Headers"
def get_data(self, flow):
return flow.request.headers.fields
@ -81,7 +81,7 @@ class RequestHeaderEditor(HeaderEditor):
class ResponseHeaderEditor(HeaderEditor):
title = "Editing response headers"
title = "Edit Response Headers"
def get_data(self, flow):
return flow.response.headers.fields
@ -91,7 +91,7 @@ class ResponseHeaderEditor(HeaderEditor):
class RequestFormEditor(base.FocusEditor):
title = "Editing URL-encoded form"
title = "Edit URL-encoded Form"
columns = [
col_text.Column("Key"),
col_text.Column("Value")
@ -157,7 +157,7 @@ class SetHeadersEditor(base.GridEditor):
class PathEditor(base.FocusEditor):
# TODO: Next row on enter?
title = "Editing URL path components"
title = "Edit Path Components"
columns = [
col_text.Column("Component"),
]
@ -208,7 +208,7 @@ class HostPatternEditor(base.GridEditor):
class CookieEditor(base.FocusEditor):
title = "Editing request Cookie header"
title = "Edit Cookies"
columns = [
col_text.Column("Name"),
col_text.Column("Value"),
@ -242,7 +242,7 @@ class CookieAttributeEditor(base.GridEditor):
class SetCookieEditor(base.FocusEditor):
title = "Editing response SetCookie header"
title = "Edit SetCookie Header"
columns = [
col_text.Column("Name"),
col_text.Column("Value"),

View File

@ -14,6 +14,7 @@ footer = [
class HelpView(urwid.ListBox):
title = "Help"
keyctx = "help"
def __init__(self, help_context):

View File

@ -264,6 +264,7 @@ class OptionHelp(urwid.Frame):
class Options(urwid.Pile):
title = "Options"
keyctx = "options"
def __init__(self, master):

View File

@ -11,6 +11,17 @@ from mitmproxy.tools.console import grideditor
from mitmproxy.tools.console import eventlog
class Header(urwid.Frame):
def __init__(self, widget, title, focus):
super().__init__(
widget,
header = urwid.AttrWrap(
urwid.Text(title),
"heading" if focus else "heading_inactive"
)
)
class WindowStack:
def __init__(self, master, base):
self.master = master
@ -90,6 +101,7 @@ class Window(urwid.Frame):
signals.push_view_state.connect(self.push)
self.master.options.subscribe(self.configure, ["console_layout"])
self.master.options.subscribe(self.configure, ["console_layout_headers"])
self.pane = 0
self.stacks = [
WindowStack(master, "flowlist"),
@ -107,21 +119,31 @@ class Window(urwid.Frame):
Redraw the layout.
"""
c = self.master.options.console_layout
if c == "single":
self.pane = 0
def wrap(w, idx):
if self.master.options.console_layout_headers and hasattr(w, "title"):
return Header(w, w.title, self.pane == idx)
else:
return w
w = None
if c == "single":
w = self.stacks[0].top()
w = wrap(self.stacks[0].top(), 0)
elif c == "vertical":
w = urwid.Pile(
[i.top() for i in self.stacks]
[
wrap(s.top(), i) for i, s in enumerate(self.stacks)
]
)
else:
w = urwid.Columns(
[i.top() for i in self.stacks], dividechars=1
[wrap(s.top(), i) for i, s in enumerate(self.stacks)],
dividechars=1
)
self.body = urwid.AttrWrap(w, "background")
if c == "single":
self.pane = 0
def flow_changed(self, sender, flow):
if self.master.view.focus.flow:
@ -200,6 +222,7 @@ class Window(urwid.Frame):
self.pane = 0
else:
self.pane = (self.pane + 1) % len(self.stacks)
self.refresh()
def mouse_event(self, *args, **kwargs):
# args: (size, event, button, col, row)