aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/console/tabs.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2015-03-29 17:40:43 +1300
committerAldo Cortesi <aldo@nullcube.com>2015-03-29 17:40:43 +1300
commitcacd09fafc19b323c46c4c565d0044593b677e17 (patch)
treeae85615d75f0765a8fa80157c88b261146dc6653 /libmproxy/console/tabs.py
parentcfeee347d95cf56dfaf53c77ac5726bb72347234 (diff)
downloadmitmproxy-cacd09fafc19b323c46c4c565d0044593b677e17.tar.gz
mitmproxy-cacd09fafc19b323c46c4c565d0044593b677e17.tar.bz2
mitmproxy-cacd09fafc19b323c46c4c565d0044593b677e17.zip
console: add a tabs widget, and use it for flowview.
Diffstat (limited to 'libmproxy/console/tabs.py')
-rw-r--r--libmproxy/console/tabs.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/libmproxy/console/tabs.py b/libmproxy/console/tabs.py
new file mode 100644
index 00000000..3245f430
--- /dev/null
+++ b/libmproxy/console/tabs.py
@@ -0,0 +1,35 @@
+import urwid
+
+class Tabs(urwid.WidgetWrap):
+ def __init__(self, tabs, tab_offset=0):
+ urwid.WidgetWrap.__init__(self, "")
+ self.tab_offset = tab_offset
+ self.tabs = tabs
+ self.show()
+
+ def _tab(self, content, attr):
+ p = urwid.Text(content)
+ p = urwid.Padding(p, align="left", width=("relative", 100))
+ p = urwid.AttrWrap(p, attr)
+ return p
+
+ def keypress(self, size, key):
+ if key == "tab":
+ self.tab_offset = (self.tab_offset + 1)%(len(self.tabs))
+ self.show()
+ else:
+ return key
+
+ def show(self):
+ headers = []
+ for i in range(len(self.tabs)):
+ txt = self.tabs[i][0]()
+ if i == self.tab_offset:
+ headers.append(self._tab(txt, "heading"))
+ else:
+ headers.append(self._tab(txt, "heading_inactive"))
+ headers = urwid.Columns(headers)
+ self._w = urwid.Frame(
+ body = self.tabs[self.tab_offset][1](),
+ header = headers
+ )