aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/console/kveditor.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-02-07 16:39:37 +1300
committerAldo Cortesi <aldo@nullcube.com>2012-02-07 16:39:37 +1300
commitcdd5a53767e51a6d992bf8d08df2733e7af916b8 (patch)
treebe7d42be2960ef42675779d1494a1f5469199be5 /libmproxy/console/kveditor.py
parentf7b3a6d571059aef84e26ac82b9cc67a081230f6 (diff)
downloadmitmproxy-cdd5a53767e51a6d992bf8d08df2733e7af916b8.tar.gz
mitmproxy-cdd5a53767e51a6d992bf8d08df2733e7af916b8.tar.bz2
mitmproxy-cdd5a53767e51a6d992bf8d08df2733e7af916b8.zip
Refactor console.
Split the console implementation out into logical components.
Diffstat (limited to 'libmproxy/console/kveditor.py')
-rw-r--r--libmproxy/console/kveditor.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/libmproxy/console/kveditor.py b/libmproxy/console/kveditor.py
new file mode 100644
index 00000000..7f2d965c
--- /dev/null
+++ b/libmproxy/console/kveditor.py
@@ -0,0 +1,70 @@
+import urwid
+import common
+
+class SText(common.WWrap):
+ def __init__(self, txt):
+ w = urwid.Text(txt, wrap="any")
+ w = urwid.AttrWrap(w, "editfield")
+ common.WWrap.__init__(self, w)
+
+ def keypress(self, size, key):
+ raise ValueError, key
+ time.sleep(0.5)
+ return key
+
+ def selectable(self):
+ return True
+
+
+class KVEditor(common.WWrap):
+ def __init__(self, master, title, value, callback):
+ self.master, self.title, self.value, self.callback = master, title, value, callback
+ p = urwid.Text(title)
+ p = urwid.Padding(p, align="left", width=("relative", 100))
+ p = urwid.AttrWrap(p, "heading")
+ maxk = max(len(v[0]) for v in value)
+ parts = []
+ for k, v in value:
+ parts.append(
+ urwid.Columns(
+ [
+ (
+ "fixed",
+ maxk + 2,
+ SText(k)
+ ),
+ SText(v)
+ ],
+ dividechars = 2
+ )
+ )
+ parts.append(urwid.Text(" "))
+ self.lb = urwid.ListBox(parts)
+ self.w = urwid.Frame(self.lb, header = p)
+ self.master.statusbar.update("")
+
+ def keypress(self, size, key):
+ if key == "q":
+ self.master.pop_view()
+ return None
+ if key in ("tab", "enter"):
+ cw = self.lb.get_focus()[0]
+ col = cw.get_focus_column()
+ if col == 0:
+ cw.set_focus_column(1)
+ else:
+ self.lb._keypress_down(size)
+ cw = self.lb.get_focus()[0]
+ cw.set_focus_column(0)
+ return None
+ elif key == "ctrl e":
+ # Editor
+ pass
+ elif key == "ctrl r":
+ # Revert
+ pass
+ elif key == "esc":
+ self.master.view_connlist()
+ return
+ return self.w.keypress(size, key)
+