Merge pull request #2700 from mhils/issue-2697

Fix #2697
This commit is contained in:
Aldo Cortesi 2017-12-18 14:33:32 +13:00 committed by GitHub
commit b1f923e148
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,16 +15,30 @@ from mitmproxy.tools.console import grideditor
from mitmproxy.tools.console import eventlog
class Header(urwid.Frame):
class StackWidget(urwid.Frame):
def __init__(self, widget, title, focus):
super().__init__(
widget,
if title:
header = urwid.AttrWrap(
urwid.Text(title),
"heading" if focus else "heading_inactive"
)
else:
header = None
super().__init__(
widget,
header=header
)
def keypress(self, size, key):
# Make sure that we don't propagate cursor events outside of the widget.
# Otherwise, in a horizontal layout, urwid's Pile would change the focused widget
# if we cannot scroll any further.
ret = super().keypress(size, key)
command = self._command_map[ret] # awkward as they don't implement a full dict api
if command and command.startswith("cursor"):
return None
return ret
class WindowStack:
def __init__(self, master, base):
@ -142,12 +156,16 @@ class Window(urwid.Frame):
self.pane = 0
def wrapped(idx):
window = self.stacks[idx].top_window()
widget = self.stacks[idx].top_widget()
if self.master.options.console_layout_headers and window.title:
return Header(widget, window.title, self.pane == idx)
if self.master.options.console_layout_headers:
title = self.stacks[idx].top_window().title
else:
return widget
title = None
return StackWidget(
widget,
title,
self.pane == idx
)
w = None
if c == "single":