aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2017-06-11 21:20:12 +1200
committerAldo Cortesi <aldo@nullcube.com>2017-06-11 21:20:12 +1200
commita482868cd6028be7aabf4429b8e8b2a43d487d12 (patch)
tree7c435f4cc904d653a1b38b154617493d12e28dfa
parent926b58ab4f7dde45dfad7735cfe498403e6f05d7 (diff)
downloadmitmproxy-a482868cd6028be7aabf4429b8e8b2a43d487d12.tar.gz
mitmproxy-a482868cd6028be7aabf4429b8e8b2a43d487d12.tar.bz2
mitmproxy-a482868cd6028be7aabf4429b8e8b2a43d487d12.zip
console: extract "tab" to m_next pseudo-key
This makes tab work consistently across contexts, makes it globally bindable, and gets rid of an un-needed command.
-rw-r--r--mitmproxy/tools/console/commands.py2
-rw-r--r--mitmproxy/tools/console/defaultkeys.py3
-rw-r--r--mitmproxy/tools/console/grideditor/base.py47
-rw-r--r--mitmproxy/tools/console/master.py14
-rw-r--r--mitmproxy/tools/console/options.py2
-rw-r--r--mitmproxy/tools/console/signals.py3
-rw-r--r--mitmproxy/tools/console/statusbar.py14
-rw-r--r--mitmproxy/tools/console/tabs.py4
8 files changed, 16 insertions, 73 deletions
diff --git a/mitmproxy/tools/console/commands.py b/mitmproxy/tools/console/commands.py
index 7f680c72..f60285b1 100644
--- a/mitmproxy/tools/console/commands.py
+++ b/mitmproxy/tools/console/commands.py
@@ -148,7 +148,7 @@ class Commands(urwid.Pile, layoutwidget.LayoutWidget):
self.master = master
def keypress(self, size, key):
- if key == "tab":
+ if key == "m_next":
self.focus_position = (
self.focus_position + 1
) % len(self.widget_list)
diff --git a/mitmproxy/tools/console/defaultkeys.py b/mitmproxy/tools/console/defaultkeys.py
index 2a442fbf..5f48c0d8 100644
--- a/mitmproxy/tools/console/defaultkeys.py
+++ b/mitmproxy/tools/console/defaultkeys.py
@@ -17,6 +17,7 @@ def map(km):
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("tab", "console.nav.next", ["global"], "Next")
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")
@@ -105,7 +106,6 @@ def map(km):
)
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 "
@@ -121,7 +121,6 @@ def map(km):
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",
diff --git a/mitmproxy/tools/console/grideditor/base.py b/mitmproxy/tools/console/grideditor/base.py
index 87172eb4..bac574c4 100644
--- a/mitmproxy/tools/console/grideditor/base.py
+++ b/mitmproxy/tools/console/grideditor/base.py
@@ -11,14 +11,6 @@ from mitmproxy.tools.console import signals
from mitmproxy.tools.console import layoutwidget
import mitmproxy.tools.console.master # noqa
-FOOTER = [
- ('heading_key', "enter"), ":edit ",
- ('heading_key', "q"), ":back ",
-]
-FOOTER_EDITING = [
- ('heading_key', "esc"), ":stop editing ",
-]
-
def read_file(filename: str, escaped: bool) -> typing.AnyStr:
filename = os.path.expanduser(filename)
@@ -197,12 +189,10 @@ class GridWalker(urwid.ListWalker):
self.edit_row = GridRow(
self.focus_col, True, self.editor, self.lst[self.focus]
)
- signals.footer_help.send(self, helptext=FOOTER_EDITING)
self._modified()
def stop_edit(self):
if self.edit_row:
- signals.footer_help.send(self, helptext=FOOTER)
try:
val = self.edit_row.edit_col.get_data()
except ValueError:
@@ -315,7 +305,6 @@ class BaseGridEditor(urwid.WidgetWrap):
w = urwid.Frame(self.lb, header=h)
super().__init__(w)
- signals.footer_help.send(self, helptext="")
self.show_empty_msg()
def layout_popping(self):
@@ -344,7 +333,7 @@ class BaseGridEditor(urwid.WidgetWrap):
def keypress(self, size, key):
if self.walker.edit_row:
- if key in ["esc"]:
+ if key == "esc":
self.walker.stop_edit()
elif key == "tab":
pf, pfc = self.walker.focus, self.walker.focus_col
@@ -358,6 +347,8 @@ class BaseGridEditor(urwid.WidgetWrap):
column = self.columns[self.walker.focus_col]
if key == "m_start":
self.walker.set_focus(0)
+ elif key == "m_next":
+ self.walker.tab_next()
elif key == "m_end":
self.walker.set_focus(len(self.walker.lst) - 1)
elif key == "left":
@@ -389,38 +380,6 @@ class BaseGridEditor(urwid.WidgetWrap):
def handle_key(self, key):
return False
- def make_help(self):
- text = [
- urwid.Text([("text", "Editor control:\n")])
- ]
- keys = [
- ("A", "insert row before cursor"),
- ("a", "add row after cursor"),
- ("d", "delete row"),
- ("e", "spawn external editor on current field"),
- ("q", "save changes and exit editor"),
- ("r", "read value from file"),
- ("R", "read unescaped value from file"),
- ("esc", "save changes and exit editor"),
- ("tab", "next field"),
- ("enter", "edit field"),
- ]
- text.extend(
- common.format_keyvals(keys, key="key", val="text", indent=4)
- )
- text.append(
- urwid.Text(
- [
- "\n",
- ("text", "Values are escaped Python-style strings.\n"),
- ]
- )
- )
- return text
-
- def cmd_next(self):
- self.walker.tab_next()
-
def cmd_add(self):
self.walker.add()
diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py
index cf145c70..30b1277c 100644
--- a/mitmproxy/tools/console/master.py
+++ b/mitmproxy/tools/console/master.py
@@ -131,6 +131,13 @@ class ConsoleAddon:
"""
self.master.inject_key("m_end")
+ @command.command("console.nav.next")
+ def nav_next(self) -> None:
+ """
+ Go to the next navigatable item.
+ """
+ self.master.inject_key("m_next")
+
@command.command("console.nav.up")
def nav_up(self) -> None:
"""
@@ -343,13 +350,6 @@ class ConsoleAddon:
"""
self._grideditor().cmd_insert()
- @command.command("console.grideditor.next")
- def grideditor_next(self) -> None:
- """
- Go to next cell.
- """
- self._grideditor().cmd_next()
-
@command.command("console.grideditor.delete")
def grideditor_delete(self) -> None:
"""
diff --git a/mitmproxy/tools/console/options.py b/mitmproxy/tools/console/options.py
index 89656a18..c53716e7 100644
--- a/mitmproxy/tools/console/options.py
+++ b/mitmproxy/tools/console/options.py
@@ -261,7 +261,7 @@ class Options(urwid.Pile, layoutwidget.LayoutWidget):
return foc.opt.name
def keypress(self, size, key):
- if key == "tab":
+ if key == "m_next":
self.focus_position = (
self.focus_position + 1
) % len(self.widget_list)
diff --git a/mitmproxy/tools/console/signals.py b/mitmproxy/tools/console/signals.py
index 5cbbd875..2c09c708 100644
--- a/mitmproxy/tools/console/signals.py
+++ b/mitmproxy/tools/console/signals.py
@@ -33,9 +33,6 @@ call_in = blinker.Signal()
# Focus the body, footer or header of the main window
focus = blinker.Signal()
-# Set the mini help text in the footer of the main window
-footer_help = blinker.Signal()
-
# Fired when settings change
update_settings = blinker.Signal()
diff --git a/mitmproxy/tools/console/statusbar.py b/mitmproxy/tools/console/statusbar.py
index a4308848..44b89c52 100644
--- a/mitmproxy/tools/console/statusbar.py
+++ b/mitmproxy/tools/console/statusbar.py
@@ -3,7 +3,6 @@ import os.path
import urwid
from mitmproxy.tools.console import common
-from mitmproxy.tools.console import pathedit
from mitmproxy.tools.console import signals
from mitmproxy.tools.console import commandeditor
import mitmproxy.tools.console.master # noqa
@@ -39,16 +38,12 @@ class ActionBar(urwid.WidgetWrap):
self.clear()
signals.status_message.connect(self.sig_message)
signals.status_prompt.connect(self.sig_prompt)
- signals.status_prompt_path.connect(self.sig_path_prompt)
signals.status_prompt_onekey.connect(self.sig_prompt_onekey)
signals.status_prompt_command.connect(self.sig_prompt_command)
- self.last_path = ""
-
self.prompting = None
self.onekey = False
- self.pathprompt = False
def sig_message(self, sender, message, expire=1):
if self.prompting:
@@ -74,15 +69,6 @@ class ActionBar(urwid.WidgetWrap):
self._w = commandeditor.CommandEdit(partial)
self.prompting = commandeditor.CommandExecutor(self.master)
- def sig_path_prompt(self, sender, prompt, callback, args=()):
- signals.focus.send(self, section="footer")
- self._w = pathedit.PathEdit(
- self.prep_prompt(prompt),
- os.path.dirname(self.last_path)
- )
- self.pathprompt = True
- self.prompting = PromptPath(callback, args)
-
def sig_prompt_onekey(self, sender, prompt, keys, callback, args=()):
"""
Keys are a set of (word, key) tuples. The appropriate key in the
diff --git a/mitmproxy/tools/console/tabs.py b/mitmproxy/tools/console/tabs.py
index 93d6909e..77873086 100644
--- a/mitmproxy/tools/console/tabs.py
+++ b/mitmproxy/tools/console/tabs.py
@@ -35,7 +35,9 @@ class Tabs(urwid.WidgetWrap):
def keypress(self, size, key):
n = len(self.tabs)
- if key == "right":
+ if key == "m_next":
+ self.change_tab((self.tab_offset + 1) % n)
+ elif key == "right":
self.change_tab((self.tab_offset + 1) % n)
elif key == "left":
self.change_tab((self.tab_offset - 1) % n)