mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
console: Key binding help
Add a help field to key bindings, use that in contextual help display.
This commit is contained in:
parent
7caa7e7538
commit
fdfd3ed937
138
mitmproxy/tools/console/defaultkeys.py
Normal file
138
mitmproxy/tools/console/defaultkeys.py
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
|
||||||
|
def map(km):
|
||||||
|
km.add(":", "console.command ''", ["global"], "Command prompt")
|
||||||
|
km.add("?", "console.view.help", ["global"], "View help")
|
||||||
|
km.add("C", "console.view.commands", ["global"], "View commands")
|
||||||
|
km.add("O", "console.view.options", ["global"], "View options")
|
||||||
|
km.add("E", "console.view.eventlog", ["global"], "View event log")
|
||||||
|
km.add("Q", "console.exit", ["global"], "Exit immediately")
|
||||||
|
km.add("q", "console.view.pop", ["global"], "Exit the current view")
|
||||||
|
km.add("-", "console.layout.cycle", ["global"], "Cycle to next layout")
|
||||||
|
km.add("shift tab", "console.panes.next", ["global"], "Focus next layout pane")
|
||||||
|
km.add("P", "console.view.flow @focus", ["global"], "View flow details")
|
||||||
|
|
||||||
|
km.add("g", "console.nav.start", ["global"], "Go to start")
|
||||||
|
km.add("G", "console.nav.end", ["global"], "Go to end")
|
||||||
|
km.add("k", "console.nav.up", ["global"], "Up")
|
||||||
|
km.add("j", "console.nav.down", ["global"], "Down")
|
||||||
|
km.add("l", "console.nav.right", ["global"], "Right")
|
||||||
|
km.add("h", "console.nav.left", ["global"], "Left")
|
||||||
|
km.add(" ", "console.nav.pagedown", ["global"], "Page down")
|
||||||
|
km.add("ctrl f", "console.nav.pagedown", ["global"], "Page down")
|
||||||
|
km.add("ctrl b", "console.nav.pageup", ["global"], "Page up")
|
||||||
|
|
||||||
|
km.add("i", "console.command set intercept=", ["global"], "Set intercept")
|
||||||
|
km.add("W", "console.command set save_stream_file=", ["global"], "Stream to file")
|
||||||
|
km.add("A", "flow.resume @all", ["flowlist", "flowview"], "Resume all intercepted flows")
|
||||||
|
km.add("a", "flow.resume @focus", ["flowlist", "flowview"], "Resume this intercepted flow")
|
||||||
|
km.add(
|
||||||
|
"b", "console.command cut.save s.content|@focus ''",
|
||||||
|
["flowlist", "flowview"],
|
||||||
|
"Save response body to file"
|
||||||
|
)
|
||||||
|
km.add("d", "view.remove @focus", ["flowlist", "flowview"], "Delete flow from view")
|
||||||
|
km.add("D", "view.duplicate @focus", ["flowlist", "flowview"], "Duplicate flow")
|
||||||
|
km.add(
|
||||||
|
"e",
|
||||||
|
"console.choose.cmd Format export.formats "
|
||||||
|
"console.command export.file {choice} @focus ''",
|
||||||
|
["flowlist", "flowview"],
|
||||||
|
"Export this flow to file"
|
||||||
|
)
|
||||||
|
km.add("f", "console.command set view_filter=", ["flowlist"], "Set view filter")
|
||||||
|
km.add("F", "set console_focus_follow=toggle", ["flowlist"], "Set focus follow")
|
||||||
|
km.add(
|
||||||
|
"ctrl l",
|
||||||
|
"console.command cut.clip ",
|
||||||
|
["flowlist", "flowview"],
|
||||||
|
"Send cuts to clipboard"
|
||||||
|
)
|
||||||
|
km.add("L", "console.command view.load ", ["flowlist"], "Load flows from file")
|
||||||
|
km.add("m", "flow.mark.toggle @focus", ["flowlist"], "Toggle mark on this flow")
|
||||||
|
km.add("M", "view.marked.toggle", ["flowlist"], "Toggle viewing marked flows")
|
||||||
|
km.add(
|
||||||
|
"n",
|
||||||
|
"console.command view.create get https://google.com",
|
||||||
|
["flowlist"],
|
||||||
|
"Create a new flow"
|
||||||
|
)
|
||||||
|
km.add(
|
||||||
|
"o",
|
||||||
|
"console.choose.cmd Order view.order.options "
|
||||||
|
"set console_order={choice}",
|
||||||
|
["flowlist"],
|
||||||
|
"Set flow list order"
|
||||||
|
)
|
||||||
|
km.add("r", "replay.client @focus", ["flowlist", "flowview"], "Replay this flow")
|
||||||
|
km.add("S", "console.command replay.server ", ["flowlist"], "Start server replay")
|
||||||
|
km.add("v", "set console_order_reversed=toggle", ["flowlist"], "Reverse flow list order")
|
||||||
|
km.add("U", "flow.mark @all false", ["flowlist"], "Un-set all marks")
|
||||||
|
km.add("w", "console.command save.file @shown ", ["flowlist"], "Save listed flows to file")
|
||||||
|
km.add("V", "flow.revert @focus", ["flowlist", "flowview"], "Revert changes to this flow")
|
||||||
|
km.add("X", "flow.kill @focus", ["flowlist"], "Kill this flow")
|
||||||
|
km.add("z", "view.remove @all", ["flowlist"], "Clear flow list")
|
||||||
|
km.add("Z", "view.remove @hidden", ["flowlist"], "Purge all flows not showing")
|
||||||
|
km.add(
|
||||||
|
"|",
|
||||||
|
"console.command script.run @focus ",
|
||||||
|
["flowlist", "flowview"],
|
||||||
|
"Run a script on this flow"
|
||||||
|
)
|
||||||
|
km.add("enter", "console.view.flow @focus", ["flowlist"], "View this flow")
|
||||||
|
|
||||||
|
km.add(
|
||||||
|
"e",
|
||||||
|
"console.choose.cmd Part console.edit.focus.options "
|
||||||
|
"console.edit.focus {choice}",
|
||||||
|
["flowview"],
|
||||||
|
"Edit a flow component"
|
||||||
|
)
|
||||||
|
km.add(
|
||||||
|
"f",
|
||||||
|
"view.setval.toggle @focus fullcontents",
|
||||||
|
["flowview"],
|
||||||
|
"Toggle viewing full contents on this flow",
|
||||||
|
)
|
||||||
|
km.add("w", "console.command save.file @focus ", ["flowview"], "Save flow to file")
|
||||||
|
km.add(" ", "view.focus.next", ["flowview"], "Go to next flow")
|
||||||
|
|
||||||
|
km.add(
|
||||||
|
"v",
|
||||||
|
"console.choose \"View Part\" request,response "
|
||||||
|
"console.bodyview @focus {choice}",
|
||||||
|
["flowview"],
|
||||||
|
"View flow body in an external viewer"
|
||||||
|
)
|
||||||
|
km.add("p", "view.focus.prev", ["flowview"], "Go to previous flow")
|
||||||
|
km.add("m", "console.flowview.mode.set", ["flowview"], "Set flow view mode")
|
||||||
|
km.add("tab", "console.nav.right", ["flowview"], "Go to next tab")
|
||||||
|
km.add(
|
||||||
|
"z",
|
||||||
|
"console.choose \"Part\" request,response "
|
||||||
|
"flow.encode.toggle @focus {choice}",
|
||||||
|
["flowview"],
|
||||||
|
"Encode/decode flow body"
|
||||||
|
)
|
||||||
|
|
||||||
|
km.add("L", "console.command options.load ", ["options"], "Load from file")
|
||||||
|
km.add("S", "console.command options.save ", ["options"], "Save to file")
|
||||||
|
km.add("D", "options.reset", ["options"], "Reset all options")
|
||||||
|
km.add("d", "console.options.reset.current", ["options"], "Reset this option")
|
||||||
|
|
||||||
|
km.add("a", "console.grideditor.add", ["grideditor"], "Add a row after cursor")
|
||||||
|
km.add("A", "console.grideditor.insert", ["grideditor"], "Insert a row before cursor")
|
||||||
|
km.add("tab", "console.grideditor.next", ["grideditor"], "Go to next field")
|
||||||
|
km.add("d", "console.grideditor.delete", ["grideditor"], "Delete this row")
|
||||||
|
km.add(
|
||||||
|
"r",
|
||||||
|
"console.command console.grideditor.readfile",
|
||||||
|
["grideditor"],
|
||||||
|
"Read unescaped data from file"
|
||||||
|
)
|
||||||
|
km.add(
|
||||||
|
"R",
|
||||||
|
"console.command console.grideditor.readfile_escaped",
|
||||||
|
["grideditor"],
|
||||||
|
"Read a Python-style escaped string from file"
|
||||||
|
)
|
||||||
|
km.add("e", "console.grideditor.editor", ["grideditor"], "Edit in external editor")
|
@ -29,7 +29,7 @@ class HelpView(tabs.Tabs, layoutwidget.LayoutWidget):
|
|||||||
k = b.key
|
k = b.key
|
||||||
if b.key == " ":
|
if b.key == " ":
|
||||||
k = "space"
|
k = "space"
|
||||||
kvs.append((k, b.command))
|
kvs.append((k, b.help or b.command))
|
||||||
return common.format_keyvals(kvs)
|
return common.format_keyvals(kvs)
|
||||||
|
|
||||||
def keybindings(self):
|
def keybindings(self):
|
||||||
|
@ -15,7 +15,10 @@ SupportedContexts = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Binding = collections.namedtuple("Binding", ["key", "command", "contexts"])
|
Binding = collections.namedtuple(
|
||||||
|
"Binding",
|
||||||
|
["key", "command", "contexts", "help"]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Keymap:
|
class Keymap:
|
||||||
@ -24,7 +27,7 @@ class Keymap:
|
|||||||
self.keys = {}
|
self.keys = {}
|
||||||
self.bindings = []
|
self.bindings = []
|
||||||
|
|
||||||
def add(self, key: str, command: str, contexts: typing.Sequence[str]) -> None:
|
def add(self, key: str, command: str, contexts: typing.Sequence[str], help="") -> None:
|
||||||
"""
|
"""
|
||||||
Add a key to the key map. If context is empty, it's considered to be
|
Add a key to the key map. If context is empty, it's considered to be
|
||||||
a global binding.
|
a global binding.
|
||||||
@ -35,7 +38,7 @@ class Keymap:
|
|||||||
if c not in SupportedContexts:
|
if c not in SupportedContexts:
|
||||||
raise ValueError("Unsupported context: %s" % c)
|
raise ValueError("Unsupported context: %s" % c)
|
||||||
|
|
||||||
b = Binding(key=key, command=command, contexts=contexts)
|
b = Binding(key=key, command=command, contexts=contexts, help=help)
|
||||||
self.bindings.append(b)
|
self.bindings.append(b)
|
||||||
self.bind(b)
|
self.bind(b)
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ from mitmproxy import flow
|
|||||||
from mitmproxy.addons import intercept
|
from mitmproxy.addons import intercept
|
||||||
from mitmproxy.addons import readfile
|
from mitmproxy.addons import readfile
|
||||||
from mitmproxy.addons import view
|
from mitmproxy.addons import view
|
||||||
|
from mitmproxy.tools.console import defaultkeys
|
||||||
from mitmproxy.tools.console import keymap
|
from mitmproxy.tools.console import keymap
|
||||||
from mitmproxy.tools.console import overlay
|
from mitmproxy.tools.console import overlay
|
||||||
from mitmproxy.tools.console import palettes
|
from mitmproxy.tools.console import palettes
|
||||||
@ -428,119 +429,6 @@ class ConsoleAddon:
|
|||||||
signals.flow_change.send(self, flow=f)
|
signals.flow_change.send(self, flow=f)
|
||||||
|
|
||||||
|
|
||||||
def default_keymap(km):
|
|
||||||
km.add(":", "console.command ''", ["global"])
|
|
||||||
km.add("?", "console.view.help", ["global"])
|
|
||||||
km.add("C", "console.view.commands", ["global"])
|
|
||||||
km.add("O", "console.view.options", ["global"])
|
|
||||||
km.add("E", "console.view.eventlog", ["global"])
|
|
||||||
km.add("Q", "console.exit", ["global"])
|
|
||||||
km.add("q", "console.view.pop", ["global"])
|
|
||||||
km.add("-", "console.layout.cycle", ["global"])
|
|
||||||
km.add("shift tab", "console.panes.next", ["global"])
|
|
||||||
km.add("P", "console.view.flow @focus", ["global"])
|
|
||||||
|
|
||||||
km.add("g", "console.nav.start", ["global"])
|
|
||||||
km.add("G", "console.nav.end", ["global"])
|
|
||||||
km.add("k", "console.nav.up", ["global"])
|
|
||||||
km.add("j", "console.nav.down", ["global"])
|
|
||||||
km.add("l", "console.nav.right", ["global"])
|
|
||||||
km.add("h", "console.nav.left", ["global"])
|
|
||||||
km.add(" ", "console.nav.pagedown", ["global"])
|
|
||||||
km.add("ctrl f", "console.nav.pagedown", ["global"])
|
|
||||||
km.add("ctrl b", "console.nav.pageup", ["global"])
|
|
||||||
|
|
||||||
km.add("i", "console.command set intercept=", ["global"])
|
|
||||||
km.add("W", "console.command set save_stream_file=", ["global"])
|
|
||||||
km.add("A", "flow.resume @all", ["flowlist", "flowview"])
|
|
||||||
km.add("a", "flow.resume @focus", ["flowlist", "flowview"])
|
|
||||||
km.add(
|
|
||||||
"b", "console.command cut.save s.content|@focus ''",
|
|
||||||
["flowlist", "flowview"]
|
|
||||||
)
|
|
||||||
km.add("d", "view.remove @focus", ["flowlist", "flowview"])
|
|
||||||
km.add("D", "view.duplicate @focus", ["flowlist", "flowview"])
|
|
||||||
km.add(
|
|
||||||
"e",
|
|
||||||
"console.choose.cmd Format export.formats "
|
|
||||||
"console.command export.file {choice} @focus ''",
|
|
||||||
["flowlist", "flowview"]
|
|
||||||
)
|
|
||||||
km.add("f", "console.command set view_filter=", ["flowlist"])
|
|
||||||
km.add("F", "set console_focus_follow=toggle", ["flowlist"])
|
|
||||||
km.add("ctrl l", "console.command cut.clip ", ["flowlist", "flowview"])
|
|
||||||
km.add("L", "console.command view.load ", ["flowlist"])
|
|
||||||
km.add("m", "flow.mark.toggle @focus", ["flowlist"])
|
|
||||||
km.add("M", "view.marked.toggle", ["flowlist"])
|
|
||||||
km.add(
|
|
||||||
"n",
|
|
||||||
"console.command view.create get https://google.com",
|
|
||||||
["flowlist"]
|
|
||||||
)
|
|
||||||
km.add(
|
|
||||||
"o",
|
|
||||||
"console.choose.cmd Order view.order.options "
|
|
||||||
"set console_order={choice}",
|
|
||||||
["flowlist"]
|
|
||||||
)
|
|
||||||
km.add("r", "replay.client @focus", ["flowlist", "flowview"])
|
|
||||||
km.add("S", "console.command replay.server ", ["flowlist"])
|
|
||||||
km.add("v", "set console_order_reversed=toggle", ["flowlist"])
|
|
||||||
km.add("U", "flow.mark @all false", ["flowlist"])
|
|
||||||
km.add("w", "console.command save.file @shown ", ["flowlist"])
|
|
||||||
km.add("V", "flow.revert @focus", ["flowlist", "flowview"])
|
|
||||||
km.add("X", "flow.kill @focus", ["flowlist"])
|
|
||||||
km.add("z", "view.remove @all", ["flowlist"])
|
|
||||||
km.add("Z", "view.remove @hidden", ["flowlist"])
|
|
||||||
km.add("|", "console.command script.run @focus ", ["flowlist", "flowview"])
|
|
||||||
km.add("enter", "console.view.flow @focus", ["flowlist"])
|
|
||||||
|
|
||||||
km.add(
|
|
||||||
"e",
|
|
||||||
"console.choose.cmd Part console.edit.focus.options "
|
|
||||||
"console.edit.focus {choice}",
|
|
||||||
["flowview"]
|
|
||||||
)
|
|
||||||
km.add("f", "view.setval.toggle @focus fullcontents", ["flowview"])
|
|
||||||
km.add("w", "console.command save.file @focus ", ["flowview"])
|
|
||||||
km.add(" ", "view.focus.next", ["flowview"])
|
|
||||||
km.add(
|
|
||||||
"o",
|
|
||||||
"console.choose.cmd Order view.order.options "
|
|
||||||
"set console_order={choice}",
|
|
||||||
["flowlist"]
|
|
||||||
)
|
|
||||||
|
|
||||||
km.add(
|
|
||||||
"v",
|
|
||||||
"console.choose \"View Part\" request,response "
|
|
||||||
"console.bodyview @focus {choice}",
|
|
||||||
["flowview"]
|
|
||||||
)
|
|
||||||
km.add("p", "view.focus.prev", ["flowview"])
|
|
||||||
km.add("m", "console.flowview.mode.set", ["flowview"])
|
|
||||||
km.add("tab", "console.nav.right", ["flowview"])
|
|
||||||
km.add(
|
|
||||||
"z",
|
|
||||||
"console.choose \"Part\" request,response "
|
|
||||||
"flow.encode.toggle @focus {choice}",
|
|
||||||
["flowview"]
|
|
||||||
)
|
|
||||||
|
|
||||||
km.add("L", "console.command options.load ", ["options"])
|
|
||||||
km.add("S", "console.command options.save ", ["options"])
|
|
||||||
km.add("D", "options.reset", ["options"])
|
|
||||||
km.add("d", "console.options.reset.current", ["options"])
|
|
||||||
|
|
||||||
km.add("a", "console.grideditor.add", ["grideditor"])
|
|
||||||
km.add("A", "console.grideditor.insert", ["grideditor"])
|
|
||||||
km.add("tab", "console.grideditor.next", ["grideditor"])
|
|
||||||
km.add("d", "console.grideditor.delete", ["grideditor"])
|
|
||||||
km.add("r", "console.command console.grideditor.readfile", ["grideditor"])
|
|
||||||
km.add("R", "console.command console.grideditor.readfile_escaped", ["grideditor"])
|
|
||||||
km.add("e", "console.grideditor.editor", ["grideditor"])
|
|
||||||
|
|
||||||
|
|
||||||
class ConsoleMaster(master.Master):
|
class ConsoleMaster(master.Master):
|
||||||
|
|
||||||
def __init__(self, options, server):
|
def __init__(self, options, server):
|
||||||
@ -556,7 +444,7 @@ class ConsoleMaster(master.Master):
|
|||||||
# This line is just for type hinting
|
# This line is just for type hinting
|
||||||
self.options = self.options # type: Options
|
self.options = self.options # type: Options
|
||||||
self.keymap = keymap.Keymap(self)
|
self.keymap = keymap.Keymap(self)
|
||||||
default_keymap(self.keymap)
|
defaultkeys.map(self.keymap)
|
||||||
self.options.errored.connect(self.options_error)
|
self.options.errored.connect(self.options_error)
|
||||||
|
|
||||||
self.view_stack = []
|
self.view_stack = []
|
||||||
|
Loading…
Reference in New Issue
Block a user