mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
console options: help for overlays, improved layout for overlay grid editor
This commit is contained in:
parent
21794c7bbe
commit
cb18c91f13
@ -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
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user