aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/console/kveditor.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-02-08 18:25:00 +1300
committerAldo Cortesi <aldo@nullcube.com>2012-02-08 18:25:00 +1300
commit76f2595df76f81bdbca360fe032167b6b1269a4d (patch)
tree99fbef5d9b9281dabcc6b289d3aeab132f6b80d1 /libmproxy/console/kveditor.py
parent4026aa2e5f6929633b4800d55cf26698f9dd3c40 (diff)
downloadmitmproxy-76f2595df76f81bdbca360fe032167b6b1269a4d.tar.gz
mitmproxy-76f2595df76f81bdbca360fe032167b6b1269a4d.tar.bz2
mitmproxy-76f2595df76f81bdbca360fe032167b6b1269a4d.zip
KVEditor: "e" shortcut spawns an external editor on a field.
Diffstat (limited to 'libmproxy/console/kveditor.py')
-rw-r--r--libmproxy/console/kveditor.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/libmproxy/console/kveditor.py b/libmproxy/console/kveditor.py
index 40387a56..ceed2e00 100644
--- a/libmproxy/console/kveditor.py
+++ b/libmproxy/console/kveditor.py
@@ -1,6 +1,7 @@
import copy
import urwid
import common
+from .. import utils
class SText(common.WWrap):
def __init__(self, txt, focused):
@@ -76,6 +77,15 @@ class KVWalker(urwid.ListWalker):
self.focus_col = 0
self.editing = False
+ def get_current_value(self):
+ if self.lst:
+ return self.lst[self.focus][self.focus_col]
+
+ def set_current_value(self, val):
+ row = list(self.lst[self.focus])
+ row[self.focus_col] = val
+ self.lst[self.focus] = tuple(row)
+
def delete_focus(self):
if self.lst:
del self.lst[self.focus]
@@ -174,7 +184,7 @@ class KVEditor(common.WWrap):
else:
self.w.keypress(size, key)
return None
-
+
key = common.shortcuts(key)
if key in ["q", "esc"]:
self.callback(self.walker.lst, *self.cb_args, **self.cb_kwargs)
@@ -191,6 +201,13 @@ class KVEditor(common.WWrap):
self.walker.insert()
elif key == "d":
self.walker.delete_focus()
+ elif key == "e":
+ o = self.walker.get_current_value()
+ if o is not None:
+ n = self.master.spawn_editor(o)
+ n = utils.clean_hanging_newline(n)
+ self.walker.set_current_value(n)
+ self.walker._modified()
elif key in ["enter", "e"]:
self.walker.start_edit()
else: