aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2015-04-03 14:38:04 +1300
committerAldo Cortesi <aldo@nullcube.com>2015-04-03 14:38:04 +1300
commit57bdb893425058d03b1aaf28e1c774c81a8d9403 (patch)
tree17de62670b18626f9f941dfbf4270d5363be3f8a
parent65971f02ade7cc2126b4142a32c363e02112f95c (diff)
downloadmitmproxy-57bdb893425058d03b1aaf28e1c774c81a8d9403.tar.gz
mitmproxy-57bdb893425058d03b1aaf28e1c774c81a8d9403.tar.bz2
mitmproxy-57bdb893425058d03b1aaf28e1c774c81a8d9403.zip
console: keyboard shortcuts for options
-rw-r--r--libmproxy/console/common.py10
-rw-r--r--libmproxy/console/options.py43
-rw-r--r--libmproxy/console/palettes.py5
3 files changed, 43 insertions, 15 deletions
diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py
index bc8a2aad..23d3a4a4 100644
--- a/libmproxy/console/common.py
+++ b/libmproxy/console/common.py
@@ -37,14 +37,14 @@ def is_keypress(k):
return True
-def highlight_key(s, k):
+def highlight_key(str, key, textattr="text", keyattr="key"):
l = []
- parts = s.split(k, 1)
+ parts = str.split(key, 1)
if parts[0]:
- l.append(("text", parts[0]))
- l.append(("key", k))
+ l.append((textattr, parts[0]))
+ l.append((keyattr, key))
if parts[1]:
- l.append(("text", parts[1]))
+ l.append((textattr, parts[1]))
return l
diff --git a/libmproxy/console/options.py b/libmproxy/console/options.py
index c6c4afb7..bb6b6c09 100644
--- a/libmproxy/console/options.py
+++ b/libmproxy/console/options.py
@@ -6,15 +6,25 @@ help_context = None
class OptionWidget(urwid.WidgetWrap):
- def __init__(self, option, text, active, focus):
+ def __init__(self, option, text, shortcut, active, focus):
self.option = option
- opt = urwid.Text(text, align="center")
+ textattr = "text"
+ keyattr = "key"
if focus and active:
- opt = urwid.AttrWrap(opt, "option_active_selected")
+ textattr = "option_active_selected"
elif focus:
- opt = urwid.AttrWrap(opt, "option_selected")
+ textattr = "option_selected"
+ keyattr = "option_selected_key"
elif active:
- opt = urwid.AttrWrap(opt, "option_active")
+ textattr = "option_active"
+ text = common.highlight_key(
+ text,
+ shortcut,
+ textattr=textattr,
+ keyattr=keyattr
+ )
+ opt = urwid.Text(text, align="center")
+ opt = urwid.AttrWrap(opt, textattr)
opt = urwid.Padding(opt, align="center", width=("relative", 20))
urwid.WidgetWrap.__init__(self, opt)
@@ -58,24 +68,33 @@ class OptionListBox(urwid.ListBox):
self,
OptionWalker(options)
)
+ self.options = options
+ self.keymap = {}
+ for i in options:
+ self.keymap[i.shortcut] = i
def keypress(self, size, key):
key = common.shortcuts(key)
if key == "enter":
- self.get_focus()[0].option.ativate()
+ self.get_focus()[0].option.activate()
+ return None
+ if key in self.keymap:
+ self.keymap[key].activate()
+ self.set_focus(self.options.index(self.keymap[key]))
return None
return super(self.__class__, self).keypress(size, key)
_neg = lambda: False
class Option:
- def __init__(self, text, getstate=None, ativate=None):
+ def __init__(self, text, shortcut, getstate=None, activate=None):
self.text = text
+ self.shortcut = shortcut
self.getstate = getstate or _neg
- self.ativate = ativate or _neg
+ self.activate = activate or _neg
def render(self, focus):
- return OptionWidget(self, self.text, self.getstate(), focus)
+ return OptionWidget(self, self.text, self.shortcut, self.getstate(), focus)
class Options(urwid.WidgetWrap):
@@ -85,11 +104,13 @@ class Options(urwid.WidgetWrap):
[
Option(
"Anti-Cache",
+ "C",
lambda: master.anticache,
self.toggle_anticache
),
Option(
"Anti-Compression",
+ "o",
lambda: master.anticomp,
self.toggle_anticomp
),
@@ -97,6 +118,7 @@ class Options(urwid.WidgetWrap):
#Option("Ignore Patterns"),
Option(
"Kill Extra",
+ "E",
lambda: master.killextra,
self.toggle_killextra
),
@@ -104,6 +126,7 @@ class Options(urwid.WidgetWrap):
#Option("Replacement Patterns"),
Option(
"Show Host",
+ "H",
lambda: master.showhost,
self.toggle_showhost
),
@@ -112,11 +135,13 @@ class Options(urwid.WidgetWrap):
#Option("TCP Proxying"),
Option(
"No Refresh",
+ "R",
lambda: not master.refresh_server_playback,
self.toggle_refresh_server_playback
),
Option(
"No Upstream Certs",
+ "U",
lambda: master.server.config.no_upstream_cert,
self.toggle_upstream_cert
),
diff --git a/libmproxy/console/palettes.py b/libmproxy/console/palettes.py
index 020863f8..98a1e042 100644
--- a/libmproxy/console/palettes.py
+++ b/libmproxy/console/palettes.py
@@ -19,6 +19,7 @@ class Palette:
# Options
'option_selected', 'option_active', 'option_active_selected',
+ 'option_selected_key',
# List and Connections
'method', 'focus',
@@ -120,6 +121,7 @@ class LowLight(Palette):
# Options
option_selected = ('light gray', 'dark blue'),
+ option_selected_key = ('dark blue,bold', 'dark blue'),
option_active = ('light red', 'default'),
option_active_selected = ('light red', 'dark blue'),
@@ -194,6 +196,7 @@ class SolarizedLight(LowLight):
# Options
option_selected = (sol_base2, sol_base02),
+ option_selected_key = (sol_blue, sol_base02),
option_active = (sol_orange, 'default'),
option_active_selected = (sol_orange, sol_base02),
@@ -271,7 +274,7 @@ class SolarizedDark(LowDark):
palettes = {
- #"lowlight": LowLight(),
+ "lowlight": LowLight(),
#"lowdark": LowDark(),
#"light": Light(),
#"dark": Dark(),