diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py index a6885733d..c0d8e05c8 100644 --- a/mitmproxy/tools/console/master.py +++ b/mitmproxy/tools/console/master.py @@ -309,13 +309,15 @@ class ConsoleMaster(master.Master): def shutdown(self): raise urwid.ExitMainLoop - def overlay(self, widget): + def overlay(self, widget, **kwargs): signals.push_view_state.send( self, window = overlay.SimpleOverlay( + self, widget, self.loop.widget, widget.width, + **kwargs ) ) diff --git a/mitmproxy/tools/console/options.py b/mitmproxy/tools/console/options.py index 706605fc6..f38550f98 100644 --- a/mitmproxy/tools/console/options.py +++ b/mitmproxy/tools/console/options.py @@ -1,6 +1,7 @@ import urwid import blinker import textwrap +import pprint from typing import Optional, Sequence from mitmproxy import exceptions @@ -8,6 +9,8 @@ from mitmproxy.tools.console import common from mitmproxy.tools.console import signals from mitmproxy.tools.console import overlay +HELP_HEIGHT = 5 + def can_edit_inplace(opt): if opt.choices: @@ -27,8 +30,6 @@ def _mkhelp(): keys = [ ("enter", "edit option"), ("D", "reset all to defaults"), - ("g", "go to start of list"), - ("G", "go to end of list"), ("w", "save options"), ] text.extend(common.format_keyvals(keys, key="key", val="text", indent=4)) @@ -62,8 +63,10 @@ class OptionItem(urwid.WidgetWrap): val = self.opt.current() if self.opt.typespec == bool: displayval = "true" if val else "false" - elif val is None: + elif not val: displayval = "" + elif self.opt.typespec == Sequence[str]: + displayval = pprint.pformat(val, indent=1) else: displayval = str(val) @@ -218,8 +221,10 @@ class OptionsList(urwid.ListBox): overlay.OptionsOverlay( self.master, foc.opt.name, - foc.opt.current() - ) + foc.opt.current(), + HELP_HEIGHT + 5 + ), + valign="top" ) else: raise NotImplementedError() @@ -254,7 +259,7 @@ class Options(urwid.Pile): super().__init__( [ OptionsList(master), - (5, oh), + (HELP_HEIGHT, oh), ] ) self.master = master diff --git a/mitmproxy/tools/console/overlay.py b/mitmproxy/tools/console/overlay.py index e1dc50bf5..e874da691 100644 --- a/mitmproxy/tools/console/overlay.py +++ b/mitmproxy/tools/console/overlay.py @@ -8,13 +8,15 @@ from mitmproxy.tools.console import grideditor class SimpleOverlay(urwid.Overlay): - def __init__(self, widget, parent, width): + def __init__(self, master, widget, parent, width, valign="middle"): + self.widget = widget + self.master = master super().__init__( widget, parent, align="center", width=width, - valign="middle", + valign=valign, height="pack" ) @@ -22,6 +24,8 @@ class SimpleOverlay(urwid.Overlay): key = super().keypress(size, key) if key == "esc": signals.pop_view_state.send(self) + if key == "?": + self.master.view_help(self.widget.make_help()) else: return key @@ -105,20 +109,33 @@ class Chooser(urwid.WidgetWrap): signals.pop_view_state.send(self) return super().keypress(size, key) + def make_help(self): + text = [] + keys = [ + ("enter", "choose option"), + ("esc", "exit chooser"), + ] + text.extend(common.format_keyvals(keys, key="key", val="text", indent=4)) + return text + class OptionsOverlay(urwid.WidgetWrap): - def __init__(self, master, name, vals): + def __init__(self, master, name, vals, vspace): + """ + vspace: how much vertical space to keep clear + """ cols, rows = master.ui.get_cols_rows() + self.ge = grideditor.OptionsEditor(master, name, vals) super().__init__( urwid.AttrWrap( urwid.LineBox( - urwid.BoxAdapter( - grideditor.OptionsEditor(master, name, vals), - math.ceil(rows * 0.5) - ), - title="text" + urwid.BoxAdapter(self.ge, rows - vspace), + title=name ), "background" ) ) self.width = math.ceil(cols * 0.8) + + def make_help(self): + return self.ge.make_help() diff --git a/mitmproxy/tools/console/signals.py b/mitmproxy/tools/console/signals.py index ad2c29629..93f095776 100644 --- a/mitmproxy/tools/console/signals.py +++ b/mitmproxy/tools/console/signals.py @@ -30,7 +30,7 @@ call_in = blinker.Signal() # Focus the body, footer or header of the main window focus = blinker.Signal() -# Focus the body, footer or header of the main window +# Set the mini help text in the footer of the main window footer_help = blinker.Signal() # Fired when settings change